2018-09-15 18:12:24 -06:00
|
|
|
#!/bin/bash
|
|
|
|
. ./lib
|
|
|
|
|
|
|
|
options=()
|
2018-09-15 19:23:33 -06:00
|
|
|
options+=("Enable" "systemctl enable")
|
|
|
|
options+=("Disable" "systemctl disable")
|
|
|
|
#options+=("" "")
|
|
|
|
#options+=("Restart" "(Experimental)")
|
|
|
|
#options+=("Start" "(Experimental)")
|
|
|
|
#options+=("Stop" "(Experimental)")
|
2018-09-15 18:12:24 -06:00
|
|
|
|
|
|
|
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
|
2018-09-15 19:16:25 -06:00
|
|
|
if [[ $itm = *"."* ]]; then
|
2018-09-15 18:12:24 -06:00
|
|
|
svclist+=("$itm" "" off)
|
2018-09-15 19:16:25 -06:00
|
|
|
fi
|
2018-09-15 18:12:24 -06:00
|
|
|
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
|
2018-09-15 19:16:25 -06:00
|
|
|
if [[ $itm = *"."* ]]; then
|
2018-09-15 18:12:24 -06:00
|
|
|
svclist+=("$itm" "" off)
|
2018-09-15 19:16:25 -06:00
|
|
|
fi
|
2018-09-15 18:12:24 -06:00
|
|
|
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
|
2018-09-15 19:16:25 -06:00
|
|
|
if [[ $itm = *"."* ]]; then
|
2018-09-15 18:12:24 -06:00
|
|
|
svclist+=("$itm" "" off)
|
2018-09-15 19:16:25 -06:00
|
|
|
fi
|
2018-09-15 18:12:24 -06:00
|
|
|
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
|