style(octoprint.sh): tweak code style

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-05-14 18:15:29 +02:00
parent 2bcb441287
commit c1cc1f0d19

View File

@@ -67,6 +67,7 @@ function octoprint_setup_dialog(){
user_input+=("${octoprint_count}")
### confirm instance amount
local yn
while true; do
(( octoprint_count == 1 )) && local question="Install OctoPrint?"
(( octoprint_count > 1 )) && local question="Install ${octoprint_count} OctoPrint instances?"
@@ -139,7 +140,7 @@ function install_octoprint(){
### create and activate the virtualenv
status_msg "Installing python virtual environment..."
if [[ ! -d "${tmp}" ]]; then
if [[ ! -d ${tmp} ]]; then
mkdir -p "${tmp}"
else
error_msg "Cannot create temporary directory in ${HOME}!"
@@ -149,10 +150,12 @@ function install_octoprint(){
fi
cd "${tmp}" && virtualenv --python=python3 venv
### activate virtualenv
source venv/bin/activate
pip install pip --upgrade
pip install --no-cache-dir octoprint
### leave virtualenv
deactivate
cd "${HOME}"
@@ -169,9 +172,11 @@ function install_octoprint(){
if install_octoprint_python_env "${tmp}"; then
status_msg "Installing OctoPrint ..."
octo_env="${HOME}/OctoPrint"
### rename the temporary directory to the correct name
[[ -d ${octo_env} ]] && rm -rf "${octo_env}"
mv "${tmp}" "${octo_env}"
### replace the temporary directory name with the actual one in ${octo_env}/venv/bin/python/octoprint
sed -i "s|${tmp}|${octo_env}|" "${octo_env}/venv/bin/octoprint"
else
@@ -186,9 +191,11 @@ function install_octoprint(){
for (( i=1; i <= octoprint_count; i++ )); do
status_msg "Installing OctoPrint instance ${i}(${names[${j}]}) ..."
octo_env="${HOME}/OctoPrint_${names[${j}]}"
### rename the temporary directory to the correct name
[[ -d ${octo_env} ]] && rm -rf "${octo_env}"
cp -r "${tmp}" "${octo_env}"
### replace the temporary directory name with the actual one in ${octo_env}/venv/bin/python/octoprint
sed -i "s|${tmp}|${octo_env}|" "${octo_env}/venv/bin/octoprint"
j=$(( j + 1 ))
@@ -223,8 +230,10 @@ function create_octoprint_service(){
config_yaml="${basedir}/config.yaml"
restart_cmd="sudo service octoprint-${names[${j}]} restart"
fi
(( octoprint_count == 1 )) && status_msg "Creating OctoPrint Service ..."
(( octoprint_count > 1 )) && status_msg "Creating OctoPrint Service ${i}(${names[${j}]}) ..."
sudo /bin/sh -c "cat > ${service}" << OCTOPRINT
[Unit]
Description=Starts OctoPrint on startup
@@ -241,6 +250,7 @@ ExecStart=${octo_env}/venv/bin/octoprint --basedir ${basedir} --config ${config_
[Install]
WantedBy=multi-user.target
OCTOPRINT
port=$(( port + 1 ))
j=$(( j + 1 ))
ok_msg "Ok!"
@@ -248,8 +258,10 @@ OCTOPRINT
### create config.yaml
if [[ ! -f ${basedir}/config.yaml ]]; then
[[ ! -d ${basedir} ]] && mkdir "${basedir}"
(( octoprint_count == 1 )) && status_msg "Creating config.yaml ..."
(( octoprint_count > 1 )) && status_msg "Creating config.yaml for instance ${i}(${names[${j}]}) ..."
/bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML
serial:
additionalPorts:
@@ -272,6 +284,7 @@ function add_reboot_permission(){
if [[ -f /etc/sudoers.d/octoprint-shutdown ]]; then
sudo mv /etc/sudoers.d/octoprint-shutdown /etc/sudoers.d/octoprint-shutdown.old
fi
#create new permission file
status_msg "Add reboot permission to user '${USER}' ..."
cd "${HOME}" && echo "${USER} ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown
@@ -283,6 +296,7 @@ function add_reboot_permission(){
function print_op_ip_list(){
local ip octoprint_count="${1}" port=5000
ip=$(hostname -I | cut -d" " -f1)
for (( i=1; i <= octoprint_count; i++ )); do
echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}"
port=$(( port + 1 ))
@@ -294,8 +308,9 @@ function print_op_ip_list(){
#=================================================#
function remove_octoprint_service(){
###remove all octoprint services
[[ -z "$(octoprint_systemd)" ]] && return
###remove all octoprint services
status_msg "Removing OctoPrint Systemd Services ..."
for service in $(octoprint_systemd | cut -d"/" -f5)
do
@@ -305,6 +320,7 @@ function remove_octoprint_service(){
sudo rm -f "${SYSTEMD}/${service}"
ok_msg "Done!"
done
### reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
@@ -312,6 +328,7 @@ function remove_octoprint_service(){
function remove_octoprint_sudoers(){
[[ ! -f /etc/sudoers.d/octoprint-shutdown ]] && return
### remove sudoers file
sudo rm -f /etc/sudoers.d/octoprint-shutdown
}
@@ -370,5 +387,6 @@ function get_octoprint_status(){
else
status="Incomplete!"
fi
echo "${status}"
}