mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 10:34:28 +05:00
new function: allow hostname to be set
This commit is contained in:
@@ -255,3 +255,78 @@ read_octoprint_service_status(){
|
|||||||
OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service "
|
OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service "
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 "| This option is completely optional and can also be |"
|
||||||
|
echo -e "| done at a later point in time if you are unsure. |"
|
||||||
|
echo -e "| |"
|
||||||
|
echo -e "| Example: If you set the hostname to 'my-printer' |"
|
||||||
|
echo -e "| you can open Mainsail by browsing to: |"
|
||||||
|
echo -e "| http://my-printer.local |"
|
||||||
|
bottom_border
|
||||||
|
while true; do
|
||||||
|
echo -e "${cyan}"
|
||||||
|
read -p "###### Do you want to change the hostname? (Y/n): " yn
|
||||||
|
echo -e "${default}"
|
||||||
|
case "$yn" in
|
||||||
|
Y|y|Yes|yes|"") set_hostname; break;;
|
||||||
|
N|n|No|no) break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
set_hostname(){
|
||||||
|
#check for existing avahi installation
|
||||||
|
status_msg "Checking for necessary Avahi installation ..."
|
||||||
|
if ! [[ $(dpkg-query -f'${Status}' --show avahi-daemon 2>/dev/null) = *\ installed ]]; then
|
||||||
|
status_msg "Installing Avahi ..."
|
||||||
|
sudo apt-get install avahi-daemon -y && ok_msg "Avahi successfully installed!"
|
||||||
|
fi
|
||||||
|
ok_msg "Avahi found!"
|
||||||
|
#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
|
||||||
|
echo
|
||||||
|
top_border
|
||||||
|
echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${default} |"
|
||||||
|
echo -e "| ${red}No special characters allowed!${default} |"
|
||||||
|
echo -e "| ${red}No leading or trailing '-' allowed!${default} |"
|
||||||
|
bottom_border
|
||||||
|
while true; do
|
||||||
|
echo -e "${cyan}"
|
||||||
|
read -p "###### Please set the new hostname: " NEW_HOSTNAME
|
||||||
|
echo -e "${default}"
|
||||||
|
if [[ $NEW_HOSTNAME =~ ^[^\-]+([0-9a-z]\-{0,1})+[^\-]+$ ]]; then
|
||||||
|
ok_msg "'$NEW_HOSTNAME' is a valid hostname!"
|
||||||
|
#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 ..."
|
||||||
|
if cat /etc/hosts | grep "###set by kiauh" &>/dev/null; then
|
||||||
|
sudo sed -i "/###set by kiauh/s/\<$HOSTNAME\>/$NEW_HOSTNAME/" /etc/hosts
|
||||||
|
else
|
||||||
|
echo "127.0.0.1 $NEW_HOSTNAME ###set by kiauh" | sudo tee -a /etc/hosts &>/dev/null
|
||||||
|
fi
|
||||||
|
ok_msg "New hostname successfully configured!"
|
||||||
|
ok_msg "You need to reboot your machine for changes to take effect!"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
warn_msg "'$NEW_HOSTNAME' is not a valid hostname!"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
@@ -6,8 +6,8 @@ mainsail_install_routine(){
|
|||||||
#execute operation
|
#execute operation
|
||||||
#disable octoprint service if installed
|
#disable octoprint service if installed
|
||||||
disable_octoprint_service
|
disable_octoprint_service
|
||||||
disable_wrong_webserver
|
disable_haproxy_lighttpd
|
||||||
remove_wrong_webserver
|
remove_haproxy_lighttpd
|
||||||
install_moonraker
|
install_moonraker
|
||||||
if [ "$ERROR" != 1 ]; then
|
if [ "$ERROR" != 1 ]; then
|
||||||
check_printer_cfg
|
check_printer_cfg
|
||||||
@@ -16,7 +16,9 @@ mainsail_install_routine(){
|
|||||||
config_nginx_mainsail
|
config_nginx_mainsail
|
||||||
test_api
|
test_api
|
||||||
test_nginx
|
test_nginx
|
||||||
install_mainsail && ok_msg "Mainsail installation complete!"; echo
|
install_mainsail
|
||||||
|
create_custom_hostname
|
||||||
|
ok_msg "Mainsail installation complete!"; echo
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
ERROR_MSG=" Please install Klipper first!\n Skipping..."
|
ERROR_MSG=" Please install Klipper first!\n Skipping..."
|
||||||
@@ -168,7 +170,7 @@ gcode:
|
|||||||
DEFAULT_CFG
|
DEFAULT_CFG
|
||||||
}
|
}
|
||||||
|
|
||||||
disable_wrong_webserver(){
|
disable_haproxy_lighttpd(){
|
||||||
if systemctl is-active haproxy -q; then
|
if systemctl is-active haproxy -q; then
|
||||||
status_msg "Stopping haproxy service ..."
|
status_msg "Stopping haproxy service ..."
|
||||||
sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!"
|
sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!"
|
||||||
@@ -179,7 +181,7 @@ disable_wrong_webserver(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_wrong_webserver(){
|
remove_haproxy_lighttpd(){
|
||||||
rem=(haproxy lighttpd)
|
rem=(haproxy lighttpd)
|
||||||
for remove in "${rem[@]}"
|
for remove in "${rem[@]}"
|
||||||
do
|
do
|
||||||
@@ -193,6 +195,7 @@ remove_wrong_webserver(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
config_nginx_mainsail(){
|
config_nginx_mainsail(){
|
||||||
|
USER=$(whoami)
|
||||||
if ! [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]]; then
|
if ! [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]]; then
|
||||||
status_msg "Installing Nginx ..."
|
status_msg "Installing Nginx ..."
|
||||||
sudo apt-get install nginx -y && ok_msg "Nginx successfully installed!"
|
sudo apt-get install nginx -y && ok_msg "Nginx successfully installed!"
|
||||||
@@ -203,6 +206,8 @@ config_nginx_mainsail(){
|
|||||||
status_msg "Create Nginx configuration ..."
|
status_msg "Create Nginx configuration ..."
|
||||||
cat ${HOME}/kiauh/resources/mainsail_nginx.cfg > ${HOME}/kiauh/resources/mainsail
|
cat ${HOME}/kiauh/resources/mainsail_nginx.cfg > ${HOME}/kiauh/resources/mainsail
|
||||||
sudo mv ${HOME}/kiauh/resources/mainsail /etc/nginx/sites-available/mainsail
|
sudo mv ${HOME}/kiauh/resources/mainsail /etc/nginx/sites-available/mainsail
|
||||||
|
#make sure the config is for the correct user
|
||||||
|
sudo sed -i "/root/s/pi/$USER/" /etc/nginx/sites-available/mainsail
|
||||||
if [ -e /etc/nginx/sites-enabled/default ]; then
|
if [ -e /etc/nginx/sites-enabled/default ]; then
|
||||||
sudo rm /etc/nginx/sites-enabled/default
|
sudo rm /etc/nginx/sites-enabled/default
|
||||||
fi
|
fi
|
||||||
@@ -258,4 +263,5 @@ install_mainsail(){
|
|||||||
wget -q -O mainsail.zip $MAINSAIL_URL && status_msg "Extracting archive ..." && unzip -o mainsail.zip && rm mainsail.zip
|
wget -q -O mainsail.zip $MAINSAIL_URL && status_msg "Extracting archive ..." && unzip -o mainsail.zip && rm mainsail.zip
|
||||||
### write mainsail version to file for update check reasons
|
### write mainsail version to file for update check reasons
|
||||||
echo "$MAINSAIL_VERSION" > $MAINSAIL_DIR/version
|
echo "$MAINSAIL_VERSION" > $MAINSAIL_DIR/version
|
||||||
|
echo
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user