Posts mit dem Label bash werden angezeigt. Alle Posts anzeigen
Posts mit dem Label bash werden angezeigt. Alle Posts anzeigen

Montag, 14. Dezember 2015

GNU rejected TUI, for the moment

Hello everyone

As TUI can show its true power only when it is already installed on your system, so one could simply share the scripts that  rely on TUI, just like one shares any bash or other shell script, I wanted to become part of GNU.

That is no easy task, specialy if you come from a 4 year old project that hasnt had this goal from start.
So, for the past 10 months, its been in the GNU Evaluation queue and just until a day ago it look very promising.

However, it got rejected for the moment, as more user feedback is wanted for them to evaluate the need/profit of making TUI part of the GNU family.

With one of the arguments beeing that we would need some user feedback for further evaluation.

That is, because TUI has a new approach to the terminal...
An approach mainwhile quite the same, but also quite different.

In the beginning, I wanted the 'ultimate' dir/menu browser for (a single specific) directory based script project/s.
In the end I extracted those functions as I wanted to have the scripts provided in named directories to look/match the containing 'ultimate' menu, so I made them individual commands.

Due to this change, one can also create great (single file) wizzards or wrappers around other cli/clu applications or make tools that act (but dont look like) 'ip' or 'iw' commands, just for your custom directory-tree structure.

It comes with many commands/functions for often used tasks, such as tui-yesno, tui-select, tui-read, as well as nice optical commands such as tui-header and tui-title.

As it is a command and line-based-output framework, it might look weird if you just try a single command.
To get started - once installed, you might want to check:
tuirc samples
tuirc provides
To get the manual, please check either:
info tui
tuirc info
tuirc html  # Only if you used "make install all"
I'm asking here for this required feedback:
  • Which OS/Distro?
  • Does Installer work?
  • Does running 'tuirc' raise any, and if - what kind of - error messages? (Besides initial creating of user configuration)
  • Any other errors/bugs/unexpected behaviour you came along?
Additionally according to your skill, time and preferences:
  • What are our thoughts about the 'tuirc samples'  and info page?
  • Did you find any security bugs? - have any advice how to fix them?
Get it from: https://savannah.nongnu.org/projects/tui/
Issue is, all i can say for sure is that it runs well on my system.
I'd very much like to have confirmed reports on which OS or Distro it installs and runs well or not.
That is also required to get it working for that OS/Distro, eventhough most of them work alike, there are differences i might not be aware to catch and handle (properly) without reports and hints how its done on your OS.

Thank you in advance for sharing your thoughts about TUI.

Samstag, 21. November 2015

Two advanced simple bash menus

Many times one comes along a situation one wants to present a menu.
There are many ways to achieve this, none is wrong, none is right - each has its own value for its own situation.
However, to maintain or extend an existing menu can be hard to manage, at times.

I'd like to present you two of my favorite menu styles/types.
Hope you like them. :)

Variables:

Lets say you have a bunch of lists to handle, that you would like to present as menu...
It takes the variable prefix BUY_ and lists only the 'suffix' as menu content.
Simply add a new variable, and it will be listed in the menu.
Simply rename an existing variable, and as long the prefix BUY_ exists, it will be applied to the menu.
## Uncomment the variable assignments, to extend the menu
## Alll the menu 'management' can be done 'up here'
    BUY_FRUITS="apple banana kiwi"
    #BUY_PROTEIN="steak lenses"
    #BUY_DRINK="water milk limo"

## Expand/List all variables starting with BUI_
    MENU="${!BUY_*}"

## Loops the menus
while :;do
    echo "What variable to expand?"
   
    ## Cut of BUY_ from all (//) items of the list MENU
    select item in ${MENU//BUY_} Quit;do break;done
   
    ## Let the user Quit the loop
    [ Quit = $item ] && break
   
    ## RE-append the leading BUY_ variable prefix
    sel_item=BUY_$item
   
    ## Finaly expand / list the content of sel_item (BUY_$item).
    ## These 2 echo's should replace your function
    echo "${!sel_item}"
    echo
done

Array:

Lets say you have a bunch of tasks which you want to describe, and you know you might require to change the description.
This way, you only need to change the description in the array, and it keeps working.

    # Make sure no entries remain from possible previous runs
    unset MENU
   
    # Fill the values
    MENU[0]="First menu entry"
    MENU[1]="Menu entry one"
    MENU[2]="All good things are three"
   
    # Let the user select
    select choice in Quit "${MENU[@]}";do
        # Act accordingly
        # Its recomended to call functions from here, so the menu remains 'over-see-able'
        case "$choice" in
        Quit)        break        ;;
        "${MENU[0]}")    echo "first"    ;;
        "${MENU[1]}")    echo "second"    ;;
        "${MENU[2]}")    echo "third"    ;;
        esac
    done
Have fun tweaking!

Montag, 21. September 2015

YASSI 1.0.1 - Final release

I'm happy to announce the final release of YASSI.

YASSI does not need to be installed, unless you want to 'info yassi'.
The project name and version 'yassi'/1.0.1, and both lines with 'Report bugs...' are read from the configuration file,
and therefor will adjust to your project settings.
Not even 2 months ago I had started with this project, and it already provides all the functions i've wanted for it.While I initially started it for another project of mine where i needed to focus on the duty, i wanted to have it as its own project, to use with ther projects.

I do hope you helps you as much as it does for me.

What is YASSI again?

Yet Another Simple Script Installer

What is it for?

It requires a single file to provide all information for an installation custom to your needs,
while staying easy change-able by the end user.

Get it


Montag, 3. August 2015

Yet Another Simple Script Installation

Got a cool script, and now need an installation script?

YASSI helps you :)
Inspired by the powerfull, but complex, GNU Autotool's, i've written this single script to handle this.

Main benefit?
It requires just a single configuration file.

Main drawback?
Its just to place the files, it does NOT do ANY compiling.

Read all about it, in the README.md

Samstag, 13. Juni 2015

Linux, minimal WIFI on Laptop

Every now and then i do a new installation or try out a new (or new version of an already known) distro.

The most irritating part with many linux installations is the following:

They provide wifi tools on the install image, but they are not part of the core system to be installed.

The core system expects a desktop computer, or just any device having a wired only connection to the internet (or LAN for that reason) .

So, first of a remainder of the packages required:
  • dhcpcd, and ifconfig (or ip) (should already be installed)
  • wpa_supplicant
  • iw

As for all my scripts, it uses TUI, so you might want to install GIT or just download it from the http://github.com/sri-arjuna/tui page.

Now, the concept is, to have one script per spot, and have logfiles for each of the spots.

The logfiles are created according to the script its name, and create the key (creds) file automaticly if its missing.

Add the missing pieces, AP, password and your wifi device.

Then, save the code as something like: wifi-home.
#!/bin/bash
#
#    Variables
#
    WIFI=wlp3s0        # Your WIFI device
    SSID="AP-name"    # The AP its name
    PASS="AP-pass"        # Password for that AP
    URL="google.com"    # Which URL to ping
    ME=${0##*/}
    KEY="$HOME/.config/$ME.key"    # Where to save the keyfile
    #
#    Internals
#
    start=${start:-false}
    [ 0 -eq ${UID:-0} ] && \
        LOG=/var/log/$ME.log || \
        LOG=$HOME/.local/logs/$ME.log
#
#    Functions
#
    wifi_createkey () { # SSID PASS FILE
    # Creates a wpa key file if none exists yet
    #
        [ -d "$(dirname $3)" ] || mkdir -p "$(dirname $3)"
        wpa_passphrase "$1" "$2" > "$3"
    }
    wifi_start() {
    # Start wpa supplicant in background
    #
        wpa_supplicant -B -i$WIFI -c"$KEY" 1>>"$LOG" 2>>"$LOG" &
        dhcpcd -B 1>>"$LOG" 2>>"$LOG"
    }
    p() { ping -c 1 "$URL" 1>/dev/zero 2>/dev/zero;}
#
#    Display and action
#
    # Is there a key file?
    [ ! -f "$KEY" ] && wifi_createkey "$SSID" "$PASS" "$KEY"

    # If it cant ping, then there is no internet
    if ! p 1>/dev/zero 2>/dev/zero
    then    start=true
        # If they are already running, they are blocking the new connection
        for used in dhcpcd ${0##*/}
        do    # Make sure those processes are killed if they are still running
        if ps|grep $used | grep -v $$ >/dev/zero && tui-yesno "$used is already running, stop it?"
        then    pkill $used
            kill $(ps|awk -v user=$used '/used/ {print $1}')
        fi
        done
    fi

    # Now only start if we need to
    if $start
    then    tui-status -r 2 "Starting WIFI..."
        wifi_start &
        tui-status $? "Started wifi"
    fi
Now lets prepare that thing to be executed upon boot, prepare:
[Unit]
Description=Wifi-Home

[Service]
Type=oneshot
ExecStart=/path/to/script/wifi-home.sh

[Install]
WantedBy=multi-user.target
And place it in /etc/systemd/system as wifi-home.service.
And now finaly as root:
systemctl enable wifi-home
systemctl start wifi-home
Et voila, you should now have wifi at each new boot.

After a restart, you can check how long the loading took:

$ systemd-analyze critical-chain

The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

graphical.target @12.509s
└─multi-user.target @12.508s
  └─wifi-home.service @11.729s +778ms
    └─basic.target @11.382s
   ...





Hope this helps

Samstag, 30. Mai 2015

One for between

The is a simple example how to read directly from a list file and check if that variable exists as directory.
If that is true, if writes to the tasklist, if not, it writes to another list.

Since one can pass multiple arguments to touch, one can even use parameter expansion to create multiple files at once.

#!/bin/bash
DATA="$HOME/data"
LIST="$DATA/mylist.txt"
JOB_NO="$DATA/job_no.txt"
JOB_YES="$DATA/job_yes.txt"

[ -d "$DATA" ] || mkdir -p "$DATA"
touch $JOB_{NO,YES} $LIST

while read dirfolder
do    [ -d "$dirfolder" ] && \
    echo "$dirfolder" >> "$JOB_YES" || \
    echo "$dirfolder" >> "$JOB_NO"
done<"$LIST"

Have fun

Dienstag, 26. Mai 2015

Background jobs, exit status

Figured another way to get an exit status of a job ran in background.

Obviously, these examples are simplified.
Each first of the two, is the 'one-liner' and the 2nd code box shows the structure with idention.

1) In this first one, we're sending the output of the background job into a variable, which we echo at the end.
This works, but doesnt really take advantage of a 'background' job.
ret=$(( sleep 2 ; [ -d not-existing ] ; echo $?) &)
echo $ret
ret=$(
    (
        sleep 2
        [ -d not-existing ]
        echo $?
    )&
)
echo $ret


2) This one applies alot more to what one usualy expects as a background job. (AFAIU) mkfifo lets the read-command wait until something is written to its passed file.

tmp=~/.cache/$$~ ; mkfifo "$tmp"
( sleep 10 ; [ -d not-existing ] ; echo $? > "$tmp") &
read RET < "$tmp" ; [ "$RET" = "0" ] && echo "GOOD!" || echo "BAD"
rm -f "$tmp"
tmp=~/.cache/$$~
mkfifo "$tmp"
(
    sleep 10
    [ -d not-existing ]
    echo $? > "$tmp"
) &
read RET < "$tmp"
[ "$RET" = "0" ] && echo "GOOD!" || echo "BAD"
rm -f "$tmp"
3) And to close the top 3, my most used code of these three.
This one loops while the background job is active and prints dots while its running. One could replace the printed string to update the text accordingly.

tmp="~/.cache/$~"
( sleep 5 ; [ -d not-existing ] ; echo $? > "$tmp") &
pid=$!
while ps $pid 1>/dev/zero;do sleep 0.5 ; printf ".";done
cat "$tmp"
tmp="~/.cache/$~"
(
    sleep 5
    [ -d not-existing ]
    echo $? > "$tmp"
) &
pid=$!
while ps $pid 1>/dev/zero
do
    sleep 0.5
    printf "."
done
cat "$tmp"

Last but not least, i'll have a tool to help with such a task.
Its called: tui-psm, which names Text User Interface - Paralell Script Manager.
You can pass as many scripts as an array can hold, and limit the paralell executed scripts to any number you want (5 is default).
tui-psm script1.sh script2.bash script3.csh

But it can more, for example, if you need at least 3 scripts to be executed successfully before you attempt to run script 5, this could be your approach:
tui-psm -cq script1.sh script2.bash script3.csh ./script4.zsh
[ $? -ge 3 ] && ./script5.ash

Hope this helped.
Have fun scripting!

Montag, 25. Mai 2015

Taming the beast, TUI back to stable

Now after the big excitement of the successfull changes to use an invidiual rc file for all its used variables, basic usage seems to be back to normal again.

It is causing a rush to figure one successfully installs the bash completition, accidently to a wrong and non-working path.

But this massive change also helped me to figure out which internal variables to share and which not, so i've added the function 'provides' to figure that out.

tui provides
Will print a hughe and long list with all the variables used internaly and which you may use as well.

If you
source  tui
you'll have all of those variables available, but sourcing just the rc file, and the wanted file providing the variables you want can increase usage speed.
source ~/.tui_rc || . tui
source $TUI_FILE_{APPS,SETTINGS}

Also several small hotfixes, of which i was sure i have had applied already 6 months ago....

Hope you like it, enjoy! :)

Freitag, 22. Mai 2015

TUI 0.8.0-2, The RC File release

Get it here:
https://github.com/sri-arjuna/tui/releases/tag/v0.8.0-2

Read about it here:
http://www.unix.com/shell-programming-and-scripting/253496-tui-text-user-interface-framework-scripts.html

Also the installation script has changed:


Hope you like the changes.
Enjoy! :)

Dienstag, 19. Mai 2015

Simply check a single ip or a range of ips within your LAN

IP_PRE=192.168.1
[ -z "$1" ] && echo "Usage: ${0##*/} 15 30-37 42 .."

for num in "${@}";do
# Parse all the arguments
    if [ "-" = "$(echo $num|tr -d [[:digit:]])" ]
    then    # Its a range, as it contains a '-'
        range_start=${num/-*}
        range_end=${num/*-}
        range=${seq $range_start 1 $range_end}
    else    # It has no range, its a single number
        range=$num
    fi
    # Parse all the numbers filled in range
    for r in $range;do
        ping -c1 $IP_PRE.$r 2>/dev/zero 1>/dev/zero && \
            echo "$IP_PRE.$r is up" || \
            echo "$IP_PRE.$r is down"
    done
done

Samstag, 16. Mai 2015

Todays achievement

I'm trying to provide some information on the variables used by TUI, reading them from 'memory' as env doesnt list them anymore (since heartbleed, still accessable by "echo ...").

Anyway, so me kind of proud this worked on first attempt :)
List all the variables starting with TUI_ and RET_:
echo ${!TUI_*} ${!RET_*}
While this is already nice, as it prints all variable names starting with either TUI_ or RET_, i'd like to show the values of these variables as well, so the user gets an idea what to expect.
Thought, eval might be usefull at this point, to show the current set paths, files, colors and default return values.

for foundVar in ${!TUI_*} ${!RET_*}
do    tui-printf -E \
           "$foundVar" \
           "$(tmp=\$$foundVar ; printf '%s' $(eval echo $tmp))"
done

Which then finaly printed (shortened):
:: TUI_DIR_CACHE                     /home/sea/.cache ::
:: TUI_DIR_CONF                              /etc/tui ::
:: TUI_DIR_DOCS                    /usr/share/doc/tui ::
:: TUI_DIR_INSTALL_ROOT                               ::
:: TUI_DIR_SYSTEM                      /usr/share/tui ::
:: TUI_DIR_THEMES               /usr/share/tui/themes ::
:: TUI_DIR_USER                 /home/sea/.config/tui ::
:: TUI_DIR_USER_LOGS       /home/sea/.config/tui/logs ::
:: TUI_DIR_USER_MANPAGES    /home/sea/.local/man/man1 ::
:: TUI_DIR_USER_SCRIPTS          /home/sea/.local/bin ::

Mittwoch, 6. Mai 2015

Get the extension of a filename

Every now and then, one needs to decide upon a file its extension what to do.

This is what i've added as tui-str-extension:
out=""
FN=$( echo "$1" | sed s," ","",g)    # Remove any spaces and make it a single string
for chance in $(echo "$FN"|sed s,"\."," ",g)    # Use dots as string seperators
do    out="$chance"
done
if [ "$out" = "$FN" ]
then    echo ""
else     echo "${out%\ /}"     # Remove any tailing or single space
fi
Hope you like it :)

Dienstag, 7. April 2015

Building FFMPEG

Been on in all easter days, it pulls in so many different applications, codecs, drivers and whatnot.
Just imagine, the temporary build path contains more than 500mb of data, compared to the final binary of ffmpeg, which is not even 500kb in size when done.

Yesterday evening i was finaly able to build the (my) first ffmpeg.
Today when i wanted to redo it, starting with 0, figured many of the build steps got accidently optimized for rerunning, which means, some of the parameters for the first 'contact' got removed and have to be readded.

Eventhouth its a smaller script, about 700 lines of code, not beeing familiar with the building process of that many applications is not a small challenge.

But i just encoded my first x265 video last night, and i have to say, the quality is great, eveb more when comparing to the filesize.

That was a good motivator, to keep me going for the still missing (failing) things, such as, but not limited to:
  • vorbis
  • webp
  • v4l
  • ass
  • srt
  • rtmp
  • speex
  • wav
  • dc1394
Once it does what i want, this script will be part of VHS, as its a handler for ffmpeg it makes sense to let it build the tools it depends on.

I'll keep you posted :)

Samstag, 15. November 2014

tui-printf: aligment is good

While having multiple terminal windows open, i've just figured the good math of reasons to split up...

Plain:











With indicators:


TUI - Themes, colors per user, and root is special

Heya, isnt that cool?!?

I've finaly applied a theme-mechanic so one can easily change among colors and borders used with TUI.
Root uses even another one, changeable only by root obviously.

But since my default linux is Fedora, the default theme is 'blue'.
And since the user root can do more damange, and Fedora is based upon Red Hat, the default root color theme is 'red'.

Here is a preview with the upcoming 'dev-scripts':
Above was called as regular user,
below was called as root user.

Montag, 10. November 2014

Readded 2-Pass encoding for VHS

1.0.7
- Reducded -Q dvd from v768 to v640
- Readded 2pass encoding: -2
- Fixed small typos

Isnt that just nice, after several weeks of asking for feedback, one actualy replied AFTER i decided it to be stable.
Oh well, at least i know now that the 2 pass encoding was working, for others at least, so i have readded this with this new update of my "Video Handler Script".

Hope you like it

Sonntag, 2. November 2014

ds prj list

Just done a little nice feature to keep track of the modules used with a project:
ds prj list