Files
LFSPkgBuilds/LFSPkgBuildScripts/HelperScripts/InstallServices
2020-02-11 13:22:54 +00:00

92 lines
1.8 KiB
Bash

#!/bin/bash
#©keithhedger Thu 8 Mar 12:20:25 GMT 2018 kdhedger68713@gmail.com
#export NCURSES_NO_UTF8_ACS=1
RED='\e[1;31m'
GREEN='\e[1;32m'
NORMAL='\e[0;0m'
DREPLY=/tmp/dialogreply$$
export DIALOGOPTS="--backtitle \"Enable/Disbale services at boot\""
BLFSBOOTSCRIPTS="blfs-bootscripts-20190609"
if [ ! -d "$BLFSBOOTSCRIPTS" ];then
wget -c --no-check-certificate "http://anduin.linuxfromscratch.org/BLFS/blfs-bootscripts/$BLFSBOOTSCRIPTS.tar.xz"
tar -xvf $BLFSBOOTSCRIPTS.tar.xz
fi
BOOTSCRIPTS="$BLFSBOOTSCRIPTS"
setvariable ()
{
THEVAR=$1
eval $THEVAR=\"$(<$DREPLY)\"
if [ "X${!THEVAR}" = X ];then
exit 0
fi
:>$DREPLY
}
installScript ()
{
echo -e "${GREEN}Installing $1 ...${NORMAL}"
if ! make -C "$BOOTSCRIPTS" "install-service-$1" 2>/dev/null;then
make -C "$BOOTSCRIPTS" "install-$1"
fi
}
uninstallScript ()
{
echo -e "${RED}Un-Installing $1 ...${NORMAL}"
make -C "$BOOTSCRIPTS" "uninstall-$1"
}
if [ "$1" != "" ];then
for arg in $@
do
installScript $arg
done
exit 0
fi
if [ ! -e /usr/bin/dialog ];then
echo "No dialog program found, please install services manually ..."
exit 1
fi
pushd $BOOTSCRIPTS
SERVICEARRAY=( $(sed -n 's/^install-\([a-z]*-*[a-z]*\):.*$/\1/p' Makefile |sed 's/^service-//g'|sort) )
popd
DIAOPTS=""
for (( j=0;j<${#SERVICEARRAY[@]};j++ ))
do
if [ -e /etc/init.d/${SERVICEARRAY[j]} ];then
STATE="on"
else
STATE="off"
fi
DIAOPTS="${DIAOPTS}${SERVICEARRAY[j]} "\"\"" $STATE "
done
eval dialog --checklist \"Select Startup Services\" $(($(tput lines) -6 )) 80 $(tput lines) $DIAOPTS 2>$DREPLY
setvariable DATA
#install selected
for arg in ${DATA}
do
if [ ! -e /etc/init.d/$arg ];then
installScript $arg
fi
done
#uninstall deselected
for arg in ${SERVICEARRAY[@]}
do
if [ -e /etc/init.d/$arg ] && [ "X$(echo $DATA|sed -n "/$arg/p")" = "X" ];then
uninstallScript $arg
fi
done