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"
|
2022-11-10 14:27:23 -07:00
|
|
|
sel=$(dialog --backtitle "$apptitle" --title "Systemd services Menu :" --default-item "$defaultitem" --cancel-button "Back" --menu "" 0 0 0 \
|
2018-09-15 18:12:24 -06:00
|
|
|
"${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
|
2022-11-10 14:27:23 -07:00
|
|
|
sel=$(dialog --backtitle "$apptitle" --title "Enable services :" --cancel-button "Cancel" --checklist "" 0 0 0 \
|
2018-09-15 18:12:24 -06:00
|
|
|
"${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
|
2022-11-10 14:27:23 -07:00
|
|
|
sel=$(dialog --backtitle "$apptitle" --title "Disable services :" --cancel-button "Cancel" --checklist "" 0 0 0 \
|
2018-09-15 18:12:24 -06:00
|
|
|
"${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
|
2022-11-10 14:27:23 -07:00
|
|
|
sel=$(dialog --backtitle "$apptitle" --title "Restart services :" --cancel-button "Cancel" --checklist "" 0 0 0 \
|
2018-09-15 18:12:24 -06:00
|
|
|
"${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
|
2022-11-10 14:27:23 -07:00
|
|
|
sel=$(dialog --backtitle "$apptitle" --title "Start services :" --cancel-button "Cancel" --checklist "" 0 0 0 \
|
2018-09-15 18:12:24 -06:00
|
|
|
"${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
|
2022-11-10 14:27:23 -07:00
|
|
|
sel=$(dialog --backtitle "$apptitle" --title "Stop services :" --cancel-button "Cancel" --checklist "" 0 0 0 \
|
2018-09-15 18:12:24 -06:00
|
|
|
"${svclist[@]}" \
|
|
|
|
3>&1 1>&2 2>&3)
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
for itm in $sel; do
|
|
|
|
svcstop ${itm//'"'/''}
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|