feat: KIAUH v4.0.0 #191
@@ -1,52 +1,53 @@
|
|||||||
function set_nginx_cfg(){
|
function set_nginx_cfg(){
|
||||||
if [ "$SET_NGINX_CFG" = "true" ]; then
|
if [ "${SET_NGINX_CFG}" = "true" ]; then
|
||||||
|
local cfg="${SRCDIR}/kiauh/resources/${1}"
|
||||||
#check for dependencies
|
#check for dependencies
|
||||||
dep=(nginx)
|
dep=(nginx)
|
||||||
dependency_check
|
dependency_check "${dep[@]}"
|
||||||
#execute operations
|
#execute operations
|
||||||
status_msg "Creating Nginx configuration for $1 ..."
|
status_msg "Creating Nginx configuration for ${1} ..."
|
||||||
#copy content from resources to the respective nginx config file
|
#copy content from resources to the respective nginx config file
|
||||||
cat ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg > ${SRCDIR}/kiauh/resources/$1
|
cat "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" > "${cfg}"
|
||||||
##edit the nginx config file before moving it
|
##edit the nginx config file before moving it
|
||||||
sed -i "s/<<UI>>/$1/g" ${SRCDIR}/kiauh/resources/$1
|
sed -i "s/<<UI>>/${1}/g" "${cfg}"
|
||||||
if [ "$SET_LISTEN_PORT" != "$DEFAULT_PORT" ]; then
|
if [ "${SET_LISTEN_PORT}" != "${DEFAULT_PORT}" ]; then
|
||||||
status_msg "Configuring port for $1 ..."
|
status_msg "Configuring port for $1 ..."
|
||||||
#set listen port ipv4
|
#set listen port ipv4
|
||||||
sed -i "s/listen\s[0-9]*;/listen $SET_LISTEN_PORT;/" ${SRCDIR}/kiauh/resources/$1
|
sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg}"
|
||||||
#set listen port ipv6
|
#set listen port ipv6
|
||||||
sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:$SET_LISTEN_PORT;/" ${SRCDIR}/kiauh/resources/$1
|
sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg}"
|
||||||
fi
|
fi
|
||||||
#set correct user
|
#set correct user
|
||||||
if [ "$1" = "mainsail" ] || [ "$1" = "fluidd" ]; then
|
if [ "${1}" = "mainsail" ] || [ "${1}" = "fluidd" ]; then
|
||||||
sudo sed -i "/root/s/pi/${USER}/" ${SRCDIR}/kiauh/resources/$1
|
sudo sed -i "/root/s/pi/${USER}/" "${cfg}"
|
||||||
fi
|
fi
|
||||||
#moving the config file into correct directory
|
#moving the config file into correct directory
|
||||||
sudo mv ${SRCDIR}/kiauh/resources/$1 /etc/nginx/sites-available/$1
|
sudo mv "${cfg}" "/etc/nginx/sites-available/${1}"
|
||||||
ok_msg "Nginx configuration for $1 was set!"
|
ok_msg "Nginx configuration for $1 was set!"
|
||||||
if [ "$SET_LISTEN_PORT" != "" ]; then
|
if [ -n "${SET_LISTEN_PORT}" ]; then
|
||||||
ok_msg "$1 listening on port $SET_LISTEN_PORT!"
|
ok_msg "${1} listening on port ${SET_LISTEN_PORT}!"
|
||||||
else
|
else
|
||||||
ok_msg "$1 listening on default port $DEFAULT_PORT!"
|
ok_msg "${1} listening on default port ${DEFAULT_PORT}!"
|
||||||
fi
|
fi
|
||||||
#remove nginx default config
|
#remove nginx default config
|
||||||
[ -e /etc/nginx/sites-enabled/default ] && sudo rm /etc/nginx/sites-enabled/default
|
[ -e "/etc/nginx/sites-enabled/default" ] && sudo rm "/etc/nginx/sites-enabled/default"
|
||||||
#create symlink for own sites
|
#create symlink for own sites
|
||||||
[ ! -e /etc/nginx/sites-enabled/$1 ] && sudo ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/
|
[ ! -e "/etc/nginx/sites-enabled/${1}" ] && sudo ln -s "/etc/nginx/sites-available/${1}" "/etc/nginx/sites-enabled/"
|
||||||
restart_nginx
|
restart_nginx
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_listen_port(){
|
function read_listen_port(){
|
||||||
LISTEN_PORT=$(grep listen /etc/nginx/sites-enabled/$1 | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
LISTEN_PORT=$(grep listen "/etc/nginx/sites-enabled/${1}" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||||
}
|
}
|
||||||
|
|
||||||
function detect_enabled_sites(){
|
function detect_enabled_sites(){
|
||||||
#check if there is another UI config already installed
|
#check if there is another UI config already installed
|
||||||
#and reads the port they are listening on
|
#and reads the port they are listening on
|
||||||
if [ -e /etc/nginx/sites-enabled/mainsail ]; then
|
if [ -e "/etc/nginx/sites-enabled/mainsail" ]; then
|
||||||
SITE_ENABLED="true" && MAINSAIL_ENABLED="true"
|
SITE_ENABLED="true" && MAINSAIL_ENABLED="true"
|
||||||
read_listen_port "mainsail"
|
read_listen_port "mainsail"
|
||||||
MAINSAIL_PORT=$LISTEN_PORT
|
MAINSAIL_PORT=${LISTEN_PORT}
|
||||||
#echo "debug: Mainsail listens on port: $MAINSAIL_PORT"
|
#echo "debug: Mainsail listens on port: $MAINSAIL_PORT"
|
||||||
else
|
else
|
||||||
MAINSAIL_ENABLED="false"
|
MAINSAIL_ENABLED="false"
|
||||||
@@ -54,7 +55,7 @@ function detect_enabled_sites(){
|
|||||||
if [ -e /etc/nginx/sites-enabled/fluidd ]; then
|
if [ -e /etc/nginx/sites-enabled/fluidd ]; then
|
||||||
SITE_ENABLED="true" && FLUIDD_ENABLED="true"
|
SITE_ENABLED="true" && FLUIDD_ENABLED="true"
|
||||||
read_listen_port "fluidd"
|
read_listen_port "fluidd"
|
||||||
FLUIDD_PORT=$LISTEN_PORT
|
FLUIDD_PORT=${LISTEN_PORT}
|
||||||
#echo "debug: Fluidd listens on port: $FLUIDD_PORT"
|
#echo "debug: Fluidd listens on port: $FLUIDD_PORT"
|
||||||
else
|
else
|
||||||
FLUIDD_ENABLED="false"
|
FLUIDD_ENABLED="false"
|
||||||
@@ -62,7 +63,7 @@ function detect_enabled_sites(){
|
|||||||
if [ -e /etc/nginx/sites-enabled/octoprint ]; then
|
if [ -e /etc/nginx/sites-enabled/octoprint ]; then
|
||||||
SITE_ENABLED="true" && OCTOPRINT_ENABLED="true"
|
SITE_ENABLED="true" && OCTOPRINT_ENABLED="true"
|
||||||
read_listen_port "octoprint"
|
read_listen_port "octoprint"
|
||||||
OCTOPRINT_PORT=$LISTEN_PORT
|
OCTOPRINT_PORT=${LISTEN_PORT}
|
||||||
#echo "debug: OctoPrint listens on port: $OCTOPRINT_PORT"
|
#echo "debug: OctoPrint listens on port: $OCTOPRINT_PORT"
|
||||||
else
|
else
|
||||||
OCTOPRINT_ENABLED="false"
|
OCTOPRINT_ENABLED="false"
|
||||||
@@ -81,7 +82,7 @@ function create_custom_hostname(){
|
|||||||
bottom_border
|
bottom_border
|
||||||
while true; do
|
while true; do
|
||||||
read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn
|
read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn
|
||||||
case "$yn" in
|
case "${yn}" in
|
||||||
Y|y|Yes|yes)
|
Y|y|Yes|yes)
|
||||||
user_input_hostname
|
user_input_hostname
|
||||||
break;;
|
break;;
|
||||||
@@ -105,13 +106,13 @@ function user_input_hostname(){
|
|||||||
bottom_border
|
bottom_border
|
||||||
while true; do
|
while true; do
|
||||||
read -p "${cyan}###### Please set the new hostname:${white} " NEW_HOSTNAME
|
read -p "${cyan}###### Please set the new hostname:${white} " NEW_HOSTNAME
|
||||||
if [[ $NEW_HOSTNAME =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then
|
if [[ ${NEW_HOSTNAME} =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then
|
||||||
ok_msg "'$NEW_HOSTNAME' is a valid hostname!"
|
ok_msg "'${NEW_HOSTNAME}' is a valid hostname!"
|
||||||
HOSTNAME_VALID="true"
|
HOSTNAME_VALID="true"
|
||||||
while true; do
|
while true; do
|
||||||
echo
|
echo
|
||||||
read -p "${cyan}###### Do you want '$NEW_HOSTNAME' to be the new hostname? (Y/n):${white} " yn
|
read -p "${cyan}###### Do you want '${NEW_HOSTNAME}' to be the new hostname? (Y/n):${white} " yn
|
||||||
case "$yn" in
|
case "${yn}" in
|
||||||
Y|y|Yes|yes|"")
|
Y|y|Yes|yes|"")
|
||||||
echo -e "###### > Yes"
|
echo -e "###### > Yes"
|
||||||
HOSTENAME_CONFIRM="true"
|
HOSTENAME_CONFIRM="true"
|
||||||
@@ -122,22 +123,21 @@ function user_input_hostname(){
|
|||||||
HOSTENAME_CONFIRM="false"
|
HOSTENAME_CONFIRM="false"
|
||||||
break;;
|
break;;
|
||||||
*)
|
*)
|
||||||
print_unkown_cmd
|
print_error "Invalid command!";;
|
||||||
print_msg && clear_msg;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
warn_msg "'$NEW_HOSTNAME' is not a valid hostname!"
|
warn_msg "'${NEW_HOSTNAME}' is not a valid hostname!"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_hostname(){
|
function set_hostname(){
|
||||||
if [ "$HOSTNAME_VALID" = "true" ] && [ "$HOSTENAME_CONFIRM" = "true" ]; then
|
if [ "${HOSTNAME_VALID}" = "true" ] && [ "${HOSTENAME_CONFIRM}" = "true" ]; then
|
||||||
#check for dependencies
|
#check for dependencies
|
||||||
dep=(avahi-daemon)
|
dep=(avahi-daemon)
|
||||||
dependency_check
|
dependency_check "${dep[@]}"
|
||||||
#execute operations
|
#execute operations
|
||||||
#get current hostname and write to variable
|
#get current hostname and write to variable
|
||||||
HOSTNAME=$(hostname)
|
HOSTNAME=$(hostname)
|
||||||
@@ -145,19 +145,19 @@ function set_hostname(){
|
|||||||
if [ -f /etc/hosts ]; then
|
if [ -f /etc/hosts ]; then
|
||||||
status_msg "Creating backup of hosts file ..."
|
status_msg "Creating backup of hosts file ..."
|
||||||
get_date
|
get_date
|
||||||
sudo cp /etc/hosts /etc/hosts."$current_date".bak
|
sudo cp "/etc/hosts /etc/hosts.${current_date}.bak"
|
||||||
ok_msg "Backup done!"
|
ok_msg "Backup done!"
|
||||||
ok_msg "File:'/etc/hosts."$current_date".bak'"
|
ok_msg "File:'/etc/hosts.${current_date}.bak'"
|
||||||
else
|
else
|
||||||
sudo touch /etc/hosts
|
sudo touch /etc/hosts
|
||||||
fi
|
fi
|
||||||
#set hostname in /etc/hostname
|
#set hostname in /etc/hostname
|
||||||
status_msg "Setting hostname to '$NEW_HOSTNAME' ..."
|
status_msg "Setting hostname to '${NEW_HOSTNAME}' ..."
|
||||||
status_msg "Please wait ..."
|
status_msg "Please wait ..."
|
||||||
sudo hostnamectl set-hostname "$NEW_HOSTNAME"
|
sudo hostnamectl set-hostname "${NEW_HOSTNAME}"
|
||||||
#write new hostname to /etc/hosts
|
#write new hostname to /etc/hosts
|
||||||
status_msg "Writing 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
|
echo "127.0.0.1 ${NEW_HOSTNAME}" | sudo tee -a /etc/hosts &>/dev/null
|
||||||
ok_msg "New hostname successfully configured!"
|
ok_msg "New hostname successfully configured!"
|
||||||
ok_msg "Remember to reboot for the changes to take effect!"
|
ok_msg "Remember to reboot for the changes to take effect!"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user