root/software/hbkcd/install.sh @ 9af489b1
| a9f959b7 | David Sorber | #!/bin/bash
|
||
| 2d09f20b | David Sorber | BOLD='\033[1m'
|
||
ENDC='\033[0m'
|
||||
RED='\033[0;31m'
|
||||
BOLD_RED='\033[1;31m'
|
||||
| a9f959b7 | David Sorber | echo -e "hbkcd Install Script\n"
|
||
if [[ $EUID -ne 0 ]]; then
|
||||
| 2d09f20b | David Sorber | echo -e "${BOLD_RED}ERROR:${ENDC} This script must be run as root"
|
||
| a9f959b7 | David Sorber | exit 1
|
||
fi
|
||||
| 2d09f20b | David Sorber | # Package and python module dependencies
|
||
declare -a pkg_deps=("python3-setuptools" "python3-pip" "libmagic-dev" "pbzip2")
|
||||
declare -A pip_deps=( [python-magic]=magic )
|
||||
# Check each package dependency
|
||||
echo "Checking package dependencies"
|
||||
to_install=""
|
||||
for package in "${pkg_deps[@]}"
|
||||
do
|
||||
printf " $package..."
|
||||
dpkg -l | grep "$package" > /dev/null
|
||||
if [ "$?" -ne 0 ]; then
|
||||
printf "${BOLD_RED}NOT INSTALLED${ENDC}\n"
|
||||
if [[ -z "$to_install" ]]; then
|
||||
to_install="$package"
|
||||
else
|
||||
to_install="$to_install $package"
|
||||
fi
|
||||
else
|
||||
printf "${BOLD}INSTALLED${ENDC}\n"
|
||||
fi
|
||||
done
|
||||
printf "\n"
|
||||
# Attempt to install any missing packages
|
||||
if [[ -z "${to_install// }" ]]; then
|
||||
printf "All required packages are installed.\n"
|
||||
else
|
||||
printf "Attempting to install missing packages: $to_install\n\n"
|
||||
sudo apt -y install "$to_install"
|
||||
if [[ "$?" -eq 0 ]]; then
|
||||
printf "\n\nPackage dependencies installed successfully.\n"
|
||||
else
|
||||
printf "\n\n${BOLD_RED}ERROR:${ENDC} unable to install package dependencies\n\n"
|
||||
exit -1
|
||||
fi
|
||||
fi
|
||||
printf "\n\n"
|
||||
# Check each Python module dependency
|
||||
echo "Checking Python module dependencies"
|
||||
to_install=""
|
||||
for module in "${!pip_deps[@]}"
|
||||
do
|
||||
printf " $module..."
|
||||
python3 -c "import ${pip_deps[$module]}" 2> /dev/null
|
||||
if [ "$?" -ne 0 ]; then
|
||||
printf "${BOLD_RED}NOT INSTALLED${ENDC}\n"
|
||||
if [[ -z "$to_install" ]]; then
|
||||
to_install="$module"
|
||||
else
|
||||
to_install="$to_install $module"
|
||||
fi
|
||||
else
|
||||
printf "${BOLD}INSTALLED${ENDC}\n"
|
||||
fi
|
||||
done
|
||||
printf "\n"
|
||||
# Attempt to install any missing Python modules
|
||||
if [[ -z "${to_install// }" ]]; then
|
||||
printf "All required Python modules are installed.\n"
|
||||
else
|
||||
printf "Attempting to install missing Python modules: $to_install\n\n"
|
||||
sudo pip3 install "$to_install"
|
||||
if [[ "$?" -eq 0 ]]; then
|
||||
printf "\n\nPython module dependencies installed successfully.\n"
|
||||
else
|
||||
printf "\n\n${BOLD_RED}ERROR:${ENDC} unable to install Python module dependencies\n\n"
|
||||
exit -1
|
||||
fi
|
||||
fi
|
||||
printf "\n\n"
|
||||
| a9f959b7 | David Sorber | |||
# Install systemd config
|
||||
| 2d09f20b | David Sorber | printf "Installing hbkcd systemd service..."
|
||
| a9f959b7 | David Sorber | cp conf/systemd/hbkcd.service /etc/systemd/system/
|
||
systemctl daemon-reload
|
||||
| 2d09f20b | David Sorber | printf "DONE\n"
|
||
printf "\n\n"
|
||||
| a9f959b7 | David Sorber | |||
# Install hbkcd Python module
|
||||
| d915a659 | David Sorber | # TODO: need to figure out a clean way to detect if this fails and halt
|
||
| a9f959b7 | David Sorber | ./setup.py install
|
||
| 2d09f20b | David Sorber | printf "\n\n"
|
||
| a9f959b7 | David Sorber | |||
| 6c9e1d69 | David Sorber | # Install scripts and logrotate config
|
||
| 2d09f20b | David Sorber | printf "Installing hbkcd scripts..."
|
||
| a9f959b7 | David Sorber | install -m 755 scripts/hbkcd_add.sh /usr/local/bin/hbkcd_add
|
||
install -m 755 scripts/hbkcd_queue.sh /usr/local/bin/hbkcd_queue
|
||||
install -m 755 scripts/hbkcd_remove.sh /usr/local/bin/hbkcd_remove
|
||||
| d915a659 | David Sorber | install -m 755 scripts/hbkcd_status.sh /usr/local/bin/hbkcd_status
|
||
| 2d09f20b | David Sorber | printf "DONE\n"
|
||
| 6c9e1d69 | David Sorber | printf "Installing logrotate config..."
|
||
install -m 644 -o root -g root conf/logrotate/hbkcd /etc/logrotate.d/hbkcd
|
||||
printf "DONE\n"
|
||||
| 2d09f20b | David Sorber | printf "\n\n"
|
||
| a9f959b7 | David Sorber | |||
# Start or restart hbckd
|
||||
systemctl status hbkcd
|
||||
result="$?"
|
||||
if [ "$result" -ne 0 ]; then
|
||||
echo "Starting hbkcd"
|
||||
systemctl start hbkcd
|
||||
else
|
||||
echo "Restarting hbkcd"
|
||||
systemctl restart hbkcd
|
||||
fi
|
||||
| 2d09f20b | David Sorber | printf "\n${BOLD}[complete]${ENDC}\n\n"
|