Better dependency check

This commit is contained in:
th33xitus
2020-07-23 10:20:14 +02:00
parent 108b5c7b0c
commit 734aed1f7b
3 changed files with 42 additions and 51 deletions

View File

@@ -27,9 +27,6 @@ get_date(){
current_date=`date +"%Y-%m-%d_%H%M%S"`
}
### sourcing all additional scripts
for script in ${HOME}/kiauh/scripts/*; do . $script; done
### set important directories
#klipper
KLIPPER_DIR=${HOME}/klipper
@@ -432,5 +429,9 @@ backup_menu(){
backup_menu
}
### sourcing all additional scripts
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
for script in ${SRCDIR}/kiauh/scripts/*; do . $script; done
check_euid
main_menu

View File

@@ -3,9 +3,9 @@ check_euid(){
if [ "$EUID" -eq 0 ]
then
echo -e "${red}"
echo -e "/=================================================\ "
echo -e "| !!! THIS SCRIPT MUST NOT RAN AS ROOT !!! |"
echo -e "\=================================================/ "
top_border
echo -e "| !!! THIS SCRIPT MUST NOT RAN AS ROOT !!! |"
bottom_border
echo -e "${default}"
exit 1
fi
@@ -85,24 +85,29 @@ restart_nginx(){
fi
}
dep_check(){
for package in "${dep[@]}"
dependency_check(){
status_msg "Checking for dependencies ..."
#check if package is installed, if not write name into array
for pkg in "${dep[@]}"
do
! command -v $package >&/dev/null 2>&1 && install+=($package)
done
if ! [ ${#install[@]} -eq 0 ]; then
warn_msg "The following packages are missing but necessary:"
echo ${install[@]}
while true; do
read -p "Do you want to install them now? (Y/n): " yn
case "$yn" in
Y|y|Yes|yes|"")
status_msg "Installing dependencies ..."
sudo apt-get install ${install[@]} -y && ok_msg "Dependencies installed!"
break;;
N|n|No|no) break;;
esac
if [[ ! $(dpkg-query -f'${Status}' --show $pkg 2>/dev/null) = *\ installed ]]; then
inst+=($pkg)
fi
done
#if array is not empty, install packages from array elements
if [ "${#inst[@]}" != "0" ]; then
status_msg "Installing the following dependencies:"
for element in ${inst[@]}
do
echo -e "${cyan}$element ${default}"
done
echo
sudo apt-get install ${inst[@]} -y
ok_msg "Dependencies installed!"
#clearing the array
unset inst
else
ok_msg "Dependencies already met! Continue..."
fi
}

View File

@@ -1,7 +1,5 @@
octoprint_install_routine(){
#experimental new dependency check
octoprint_dependencies
#execute operations
octoprint_dependencies
install_octoprint
add_groups
configure_autostart
@@ -11,29 +9,17 @@ octoprint_install_routine(){
}
octoprint_dependencies(){
octo_dep=(
dep=(
git
wget
python-pip
python-dev
python-setuptools
python-virtualenv
git
libyaml-dev
build-essential
wget
)
status_msg "Checking for dependencies ..."
for octo_dep_pgk in "${octo_dep[@]}"
do
if [[ ! $(dpkg-query -f'${Status}' --show $octo_dep_pgk 2>/dev/null) = *\ installed ]]; then
install+=($octo_dep_pgk)
fi
done
if ! [ ${#install[@]} -eq 0 ]; then
status_msg "Installing dependencies ..."
sudo apt-get install ${install[@]} -y && ok_msg "Dependencies installed!"
else
ok_msg "All dependencies already met!"
fi
python-setuptools
python-virtualenv
)
dependency_check
}
install_octoprint(){
@@ -56,14 +42,13 @@ install_octoprint(){
}
add_groups(){
USER=$(whoami)
if [[ ! $(groups | grep tty) ]]; then
status_msg "Adding user '$USER' to group 'tty' ..."
sudo usermod -a -G tty $USER && ok_msg "Done!"
if [ ! "$(groups | grep tty)" ]; then
status_msg "Adding user '${USER}' to group 'tty' ..."
sudo usermod -a -G tty ${USER} && ok_msg "Done!"
fi
if [[ ! $(groups | grep tty) ]]; then
status_msg "Adding user '$USER' to group 'dialout' ..."
sudo usermod -a -G dialout $USER && ok_msg "Done!"
if [ ! "$(groups | grep dialout)" ]; then
status_msg "Adding user '${USER}' to group 'dialout' ..."
sudo usermod -a -G dialout ${USER} && ok_msg "Done!"
fi
}