mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 18:44:29 +05:00
Better dependency check
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user