diff --git a/config/systemd/menu b/config/systemd/menu index 76f8913..bff577f 100644 --- a/config/systemd/menu +++ b/config/systemd/menu @@ -2,9 +2,11 @@ . ./lib options=() +options+=("Services" "") +options+=("" "") options+=("timedatectl" "") -defaultitem="timedatectl" +defaultitem="Services" sel=$(whiptail --backtitle "$apptitle" --title "Systemd Menu :" --menu "" --default-item "$defaultitem" --cancel-button "Back" 0 0 0 \ "${options[@]}" \ 3>&1 1>&2 2>&3) @@ -14,6 +16,7 @@ fi sed -i "/^defaultitem=/c\defaultitem=\"$sel\"" $0 case $sel in + 'Services') menu config/systemd/services/menu;; 'timedatectl') menu config/systemd/timedatectl/menu;; esac diff --git a/config/systemd/services/menu b/config/systemd/services/menu new file mode 100644 index 0000000..d87ec5f --- /dev/null +++ b/config/systemd/services/menu @@ -0,0 +1,112 @@ +#!/bin/bash +. ./lib + +options=() +options+=("Enable" "") +options+=("Disable" "") +options+=("" "") +options+=("Restart" "") +options+=("Start" "") +options+=("Stop" "") + +defaultitem="Enable" +sel=$(whiptail --backtitle "$apptitle" --title "Systemd services Menu :" --menu "" --default-item "$defaultitem" --cancel-button "Back" 0 0 0 \ + "${options[@]}" \ + 3>&1 1>&2 2>&3) +if [ ! "$?" = "0" ]; then + exit 1 +fi +sed -i "/^defaultitem=/c\defaultitem=\"$sel\"" $0 + +case $sel in + 'Enable') + services=$(systemctl list-unit-files | grep disabled) + svclist=() + for itm in $services; do + if [ ! "$itm" == "disabled" ]; then + svclist+=("$itm" "" off) + fi + done + sel=$(whiptail --backtitle "$apptitle" --title "Enable services :" --checklist "" --cancel-button "Cancel" 0 0 0 \ + "${svclist[@]}" \ + 3>&1 1>&2 2>&3) + if [ "$?" = "0" ]; then + for itm in $sel; do + svcenable ${itm//'"'/''} + done + fi + ;; + 'Disable') + services=$(systemctl list-unit-files | grep enabled) + svclist=() + for itm in $services; do + if [ ! "$itm" == "enabled" ]; then + svclist+=("$itm" "" off) + fi + done + sel=$(whiptail --backtitle "$apptitle" --title "Disable services :" --checklist "" --cancel-button "Cancel" 0 0 0 \ + "${svclist[@]}" \ + 3>&1 1>&2 2>&3) + if [ "$?" = "0" ]; then + for itm in $sel; do + svcdisable ${itm//'"'/''} + done + fi + ;; + 'Restart') + services=$(systemctl | grep running) + svclist=() + for itm in $services; do + for lbl in $itm; do + svclist+=("$itm" "" off) + break + done + done + sel=$(whiptail --backtitle "$apptitle" --title "Restart services :" --checklist "" --cancel-button "Cancel" 0 0 0 \ + "${svclist[@]}" \ + 3>&1 1>&2 2>&3) + if [ "$?" = "0" ]; then + for itm in $sel; do + svcrestart ${itm//'"'/''} + done + fi + ;; + 'Start') + services=$(systemctl | grep exited) + svclist=() + for itm in $services; do + for lbl in $itm; do + svclist+=("$itm" "" off) + break + done + done + sel=$(whiptail --backtitle "$apptitle" --title "Start services :" --checklist "" --cancel-button "Cancel" 0 0 0 \ + "${svclist[@]}" \ + 3>&1 1>&2 2>&3) + if [ "$?" = "0" ]; then + for itm in $sel; do + svcstart ${itm//'"'/''} + done + fi + ;; + 'Stop') + services=$(systemctl | grep running) + svclist=() + for itm in $services; do + for lbl in $itm; do + svclist+=("$itm" "" off) + break + done + done + sel=$(whiptail --backtitle "$apptitle" --title "Stop services :" --checklist "" --cancel-button "Cancel" 0 0 0 \ + "${svclist[@]}" \ + 3>&1 1>&2 2>&3) + if [ "$?" = "0" ]; then + for itm in $sel; do + svcstop ${itm//'"'/''} + done + fi + ;; +esac + +exit 0 diff --git a/lib b/lib index f2da669..c9a2dc3 100644 --- a/lib +++ b/lib @@ -71,7 +71,7 @@ instpkg(){ sudo -u aurbuilder yaourt -S --needed $2 pressanykey else - echo "To install AUR packages, you need to install yaourt or packer in updates menu !" + echo "To install AUR packages, you need to install an aurhelper in updates menu !" fi fi fi @@ -194,7 +194,46 @@ svcstart(){ displayname="$2 ($1)" fi if (confirm "Start $displayname service ?\n\nsystemctl start $1") then + clear + echo "systemctl start $1" systemctl start $1 + pressanykey + else + exit 1 + fi +} + +# $1 : servicename +# $2 : [displayname] +svcrestart(){ + if [ "$2" = "" ]; then + displayname="$1" + else + displayname="$2 ($1)" + fi + if (confirm "Restart $displayname service ?\n\nsystemctl restart $1") then + clear + echo "systemctl restart $1" + systemctl restart $1 + pressanykey + else + exit 1 + fi +} + +# $1 : servicename +# $2 : [displayname] +svcstop(){ + if [ "$2" = "" ]; then + displayname="$1" + else + displayname="$2 ($1)" + fi + if (confirm "Stop $displayname service ?\n\nsystemctl stop $1") then + clear + echo "systemctl stop $1" + systemctl stop $1 + pressanykey else exit 1 fi @@ -209,7 +248,10 @@ svcenable(){ displayname="$2 ($1)" fi if (confirm "Start $displayname service at boot ?\n\nsystemctl enable $1") then + clear + echo "systemctl enable $1" systemctl enable $1 + pressanykey #else # exit 1 fi @@ -224,7 +266,10 @@ svcdisable(){ displayname="$2 ($1)" fi if (confirm "Disable $displayname service at boot ?\n\nsystemctl disable $1") then + clear + echo "systemctl disable $1" systemctl disable $1 + pressanykey #else # exit 1 fi