refactor: multiple

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-04-18 10:53:11 +02:00
parent 2406df702b
commit e6df33c518
15 changed files with 270 additions and 299 deletions

View File

@@ -565,9 +565,28 @@ function fetch_webui_ports(){
}
#================================================#
#================= USERGROUPS ===================#
#=================== SYSTEM =====================#
#================================================#
function check_system_updates(){
SYS_UPDATE=$(apt list --upgradeable 2>/dev/null | sed "1d")
if [ ! -z "$SYS_UPDATE" ]; then
# add system updates to the update all array for the update all function in the updater
SYS_UPDATE_AVAIL="true" && update_arr+=(update_system)
DISPLAY_SYS_UPDATE="${yellow}System upgrade available!${white}"
else
SYS_UPDATE_AVAIL="false"
DISPLAY_SYS_UPDATE="${green}System up to date! ${white}"
fi
}
function update_system(){
status_msg "Updating System ..."
sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y
CONFIRM_MSG="Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}"
print_msg && clear_msg
}
function check_usergroups(){
local group_dialout group_tty
if grep -q "dialout" </etc/group && ! grep -q "dialout" <(groups "${USER}"); then
@@ -613,4 +632,97 @@ function check_usergroups(){
esac
done
fi
}
function create_custom_hostname(){
echo
top_border
echo -e "| You can change the hostname of this machine to use |"
echo -e "| that name to open the Interface in your browser. |"
echo -e "| |"
echo -e "| E.g.: If you set the hostname to 'my-printer' you |"
echo -e "| can open Mainsail / Fluidd / Octoprint by |"
echo -e "| browsing to: http://my-printer.local |"
bottom_border
while true; do
read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn
case "${yn}" in
Y|y|Yes|yes)
user_input_hostname
break;;
N|n|No|no|"") break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
function user_input_hostname(){
unset NEW_HOSTNAME
unset HOSTNAME_VALID
unset HOSTENAME_CONFIRM
echo
top_border
echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${white} |"
echo -e "| ${red}No special characters allowed!${white} |"
echo -e "| ${red}No leading or trailing '-' allowed!${white} |"
bottom_border
while true; do
read -p "${cyan}###### Please set the new hostname:${white} " NEW_HOSTNAME
if [[ ${NEW_HOSTNAME} =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then
ok_msg "'${NEW_HOSTNAME}' is a valid hostname!"
HOSTNAME_VALID="true"
while true; do
echo
read -p "${cyan}###### Do you want '${NEW_HOSTNAME}' to be the new hostname? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
HOSTENAME_CONFIRM="true"
break;;
N|n|No|no)
echo -e "###### > No"
echo -e "${red}Skip hostname change ...${white}"
HOSTENAME_CONFIRM="false"
break;;
*)
print_error "Invalid command!";;
esac
done
break
else
warn_msg "'${NEW_HOSTNAME}' is not a valid hostname!"
fi
done
}
function set_hostname(){
if [ "${HOSTNAME_VALID}" = "true" ] && [ "${HOSTENAME_CONFIRM}" = "true" ]; then
#check for dependencies
dep=(avahi-daemon)
dependency_check "${dep[@]}"
#execute operations
#get current hostname and write to variable
HOSTNAME=$(hostname)
#create host file if missing or create backup of existing one with current date&time
if [ -f /etc/hosts ]; then
status_msg "Creating backup of hosts file ..."
get_date
sudo cp "/etc/hosts /etc/hosts.${current_date}.bak"
ok_msg "Backup done!"
ok_msg "File:'/etc/hosts.${current_date}.bak'"
else
sudo touch /etc/hosts
fi
#set hostname in /etc/hostname
status_msg "Setting hostname to '${NEW_HOSTNAME}' ..."
status_msg "Please wait ..."
sudo hostnamectl set-hostname "${NEW_HOSTNAME}"
#write new hostname to /etc/hosts
status_msg "Writing new hostname to /etc/hosts ..."
echo "127.0.0.1 ${NEW_HOSTNAME}" | sudo tee -a /etc/hosts &>/dev/null
ok_msg "New hostname successfully configured!"
ok_msg "Remember to reboot for the changes to take effect!"
fi
}