#!/bin/bash . ./lib options=() options+=("Enable" "systemctl enable") options+=("Disable" "systemctl disable") #options+=("" "") #options+=("Restart" "(Experimental)") #options+=("Start" "(Experimental)") #options+=("Stop" "(Experimental)") defaultitem="Enable" sel=$(dialog --backtitle "$apptitle" --title "Systemd services Menu :" --default-item "$defaultitem" --cancel-button "Back" --menu "" 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=$(dialog --backtitle "$apptitle" --title "Enable services :" --cancel-button "Cancel" --checklist "" 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=$(dialog --backtitle "$apptitle" --title "Disable services :" --cancel-button "Cancel" --checklist "" 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 if [[ $itm = *"."* ]]; then svclist+=("$itm" "" off) fi done sel=$(dialog --backtitle "$apptitle" --title "Restart services :" --cancel-button "Cancel" --checklist "" 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 if [[ $itm = *"."* ]]; then svclist+=("$itm" "" off) fi done sel=$(dialog --backtitle "$apptitle" --title "Start services :" --cancel-button "Cancel" --checklist "" 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 if [[ $itm = *"."* ]]; then svclist+=("$itm" "" off) fi done sel=$(dialog --backtitle "$apptitle" --title "Stop services :" --cancel-button "Cancel" --checklist "" 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