Revision 2d09f20b
Added by David Sorber over 7 years ago
| software/hbkcd/install.sh | ||
|---|---|---|
|
#!/bin/bash
|
||
|
|
||
|
BOLD='\033[1m'
|
||
|
ENDC='\033[0m'
|
||
|
RED='\033[0;31m'
|
||
|
BOLD_RED='\033[1;31m'
|
||
|
|
||
|
echo -e "hbkcd Install Script\n"
|
||
|
|
||
|
if [[ $EUID -ne 0 ]]; then
|
||
|
echo "ERROR: This script must be run as root"
|
||
|
echo -e "${BOLD_RED}ERROR:${ENDC} This script must be run as root"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# TODO: check and install prereqs if needed
|
||
|
# 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"
|
||
|
|
||
|
# Install systemd config
|
||
|
printf "Installing hbkcd systemd service..."
|
||
|
cp conf/systemd/hbkcd.service /etc/systemd/system/
|
||
|
systemctl daemon-reload
|
||
|
printf "DONE\n"
|
||
|
printf "\n\n"
|
||
|
|
||
|
# Install hbkcd Python module
|
||
|
./setup.py install
|
||
|
printf "\n\n"
|
||
|
|
||
|
# Install scripts
|
||
|
printf "Installing hbkcd scripts..."
|
||
|
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
|
||
|
printf "DONE\n"
|
||
|
printf "\n\n"
|
||
|
|
||
|
# Start or restart hbckd
|
||
|
systemctl status hbkcd
|
||
| ... | ... | |
|
systemctl restart hbkcd
|
||
|
fi
|
||
|
|
||
|
echo -e "\n[complete]\n"
|
||
|
printf "\n${BOLD}[complete]${ENDC}\n\n"
|
||
Fix minor bug in calculating the queued duration. Add dependency
checking to the install script (with a lot of bash syntax help from
stackoverflow!).