wm:fvwm:scripts:gen-networks-menu.sh
# Gen Networks Menu # Generate FVWM menu for all network configured # Usage : gen-networks-menu.sh MenuName # Variable that stores how to discover configured wifi networks #DISCOVERNETWORKCMD='find /etc/netctl -maxdepth 1 -type f -printf %f\n' DISCOVERWIFICMD='find /etc/netctl -maxdepth 1 -name "*" -type f -print0 | xargs -0 grep -iH connection=wireless | cut -d ":" -f 1 | xargs basename -a' # Variable that stores how to discover configured ethernet networks DISCOVERETHCMD='find /etc/netctl -maxdepth 1 -name "*" -type f -print0 | xargs -0 grep -iH connection=ethernet | cut -d ":" -f 1 | xargs basename -a' # Variable that stores how to discover configured PPTP networks DISCOVERPPPCMD='find /etc/ppp/peers -maxdepth 1 -type f -printf %f\\n' # Function that check the status of a network function CHECKNETWORK() { # Check if network $1 is in status "dead" sudo netctl status $1 | grep -q \(dead\) # if it is if [ $? -eq 0 ] then return 1 else return 0 fi } # Varaible that store how to start a network NETWORKSTARTCMD='sudo netctl start' # Varaible that store how to stop a network NETWORKSTOPCMD='sudo netctl stop' # Varaible that store how to restart a network NETWORKRESTARTCMD='sudo netctl restart' # Variable with menu separator SEPARATOR="AddToMenu $1 \"\" Nop" echo "AddToMenu $1 '- Wifi -' Title" echo $SEPARATOR for NETWORK in $(eval $DISCOVERWIFICMD) do #check status of this network CHECKNETWORK $NETWORK #if down if [ $? -ne 0 ] then # Write in the menu to start it echo "AddToMenu $1 \"Start $NETWORK\" Exec exec urxvt -e $NETWORKSTARTCMD $NETWORK" echo $SEPARATOR else # Write in the Menu to restart it echo AddToMenu $1 \"Restart $NETWORK\" Exec exec urxvt -e $NETWORKRESTARTCMD $NETWORK # Or stop it echo AddToMenu $1 \"Stop $NETWORK\" Exec exec urxvt -e $NETWORKSTOPCMD $NETWORK echo $SEPARATOR fi done echo "AddToMenu $1 '- Ethernet -' Title" echo $SEPARATOR for NETWORK in $(eval $DISCOVERETHCMD) do #check status of this network CHECKNETWORK $NETWORK #if down if [ $? -ne 0 ] then # Write in the menu to start it echo "AddToMenu $1 \"Start $NETWORK\" Exec exec urxvt -e $NETWORKSTARTCMD $NETWORK" echo $SEPARATOR else # Write in the Menu to restart it echo AddToMenu $1 \"Restart $NETWORK\" Exec exec urxvt -e $NETWORKRESTARTCMD $NETWORK # Or stop it echo AddToMenu $1 \"Stop $NETWORK\" Exec exec urxvt -e $NETWORKSTOPCMD $NETWORK echo $SEPARATOR fi done echo "AddToMenu $1 '- PPTP -' Title" echo $SEPARATOR for NETWORK in $(eval $DISCOVERPPPCMD) do # Write in the menu to start it echo "AddToMenu $1 \"Start $NETWORK\" Exec exec urxvt -e sudo pon $NETWORK" # Or stop it echo AddToMenu $1 \"Stop $NETWORK\" Exec exec urxvt -e sudo poff $NETWORK echo $SEPARATOR done
wm/fvwm/scripts/gen-networks-menu.sh.txt · Last modified: 2021/12/29 21:09 by warnaud