From 108cda3cd6ae58aecdd441a5446be9adc2c8f409 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 8 Jan 2022 21:14:05 +0100 Subject: [PATCH] shellcheck: apply fixes for SC2086 --- scripts/install_dwc2.sh | 36 +++++++++---------- scripts/install_klipper_webui.sh | 60 ++++++++++++++++---------------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index e439208..89e5097 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -39,7 +39,7 @@ dwc_setup_dialog(){ while true; do echo top_border - if [ $INSTANCE_COUNT -gt 1 ]; then + if [ "$INSTANCE_COUNT" -gt 1 ]; then printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!" else echo -e "| 1 Klipper instance was found! | " @@ -118,7 +118,7 @@ dwc_setup(){ ### step 1: get dwc2-for-klipper status_msg "Downloading DWC2-for-Klipper-Socket ..." - cd ${HOME} && git clone $DWC2FK_REPO + cd "${HOME}" && git clone "$DWC2FK_REPO" ok_msg "Download complete!" ### step 2: install dwc2 dependencies and create python virtualenv @@ -127,7 +127,7 @@ dwc_setup(){ create_dwc_virtualenv ### step 3: create dwc2.cfg folder and dwc2.cfg - [ ! -d $DWC_CONF_LOC ] && mkdir -p $DWC_CONF_LOC + [ ! -d "$DWC_CONF_LOC" ] && mkdir -p "$DWC_CONF_LOC" dwc_cfg_creation ### step 4: download Duet Web Control @@ -135,7 +135,7 @@ dwc_setup(){ ### step 5: create dwc instances INSTANCE=1 - if [ $INSTANCE_COUNT -eq $INSTANCE ]; then + if [ "$INSTANCE_COUNT" -eq $INSTANCE ]; then create_single_dwc_instance else #create_multi_dwc_instance @@ -147,18 +147,18 @@ download_dwc_webui(){ #get Duet Web Control GET_DWC2_URL=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4) status_msg "Downloading DWC2 Web UI ..." - [ ! -d $DWC2_DIR ] && mkdir -p $DWC2_DIR - cd $DWC2_DIR && wget $GET_DWC2_URL + [ ! -d "$DWC2_DIR" ] && mkdir -p "$DWC2_DIR" + cd "$DWC2_DIR" && wget "$GET_DWC2_URL" ok_msg "Download complete!" status_msg "Extracting archive ..." unzip -q -o *.zip for f_ in $(find . | grep '.gz') do - gunzip -f ${f_} + gunzip -f "${f_}" done ok_msg "Done!" status_msg "Writing DWC version to file ..." - echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/.version + echo "$GET_DWC2_URL" | cut -d/ -f8 > "$DWC2_DIR/.version" ok_msg "Done!" status_msg "Remove downloaded archive ..." rm -rf *.zip && ok_msg "Done!" && ok_msg "Duet Web Control installed!" @@ -178,7 +178,7 @@ install_dwc_packages() # Install desired packages status_msg "Installing packages..." - sudo apt-get install --yes ${PKGLIST} + sudo apt-get install --yes "${PKGLIST}" } create_dwc_virtualenv() @@ -186,10 +186,10 @@ create_dwc_virtualenv() status_msg "Installing python virtual environment..." # Create virtualenv if it doesn't already exist - [ ! -d ${DWC_ENV} ] && virtualenv -p /usr/bin/python3 ${DWC_ENV} + [ ! -d "${DWC_ENV}" ] && virtualenv -p /usr/bin/python3 "${DWC_ENV}" # Install/update dependencies - ${DWC_ENV}/bin/pip install tornado==6.0.4 + "${DWC_ENV}"/bin/pip install tornado==6.0.4 } create_single_dwc_startscript(){ @@ -303,7 +303,7 @@ create_single_dwc_instance(){ create_multi_dwc_instance(){ status_msg "Setting up $INSTANCE_COUNT instances of Duet Web Control ..." - while [ $INSTANCE -le $INSTANCE_COUNT ]; do + while [ $INSTANCE -le "$INSTANCE_COUNT" ]; do ### multi instance variables DWC_LOG=/tmp/dwc-$INSTANCE.log DWC_CFG="$DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" @@ -348,7 +348,7 @@ dwc_cfg_creation(){ dwc_ip_list=() ### create single instance dwc2.cfg file - if [ $INSTANCE_COUNT -eq $INSTANCE ]; then + if [ "$INSTANCE_COUNT" -eq $INSTANCE ]; then ### set port PORT=$DEFAULT_PORT @@ -356,8 +356,8 @@ dwc_cfg_creation(){ dwc_ip_list+=("$HOSTNAME:$PORT") status_msg "Creating dwc2.cfg in $DWC_CONF_LOC" - [ ! -d $DWC_CONF_LOC ] && mkdir -p $DWC_CONF_LOC - if [ ! -f $DWC_CONF_LOC/dwc2.cfg ]; then + [ ! -d "$DWC_CONF_LOC" ] && mkdir -p "$DWC_CONF_LOC" + if [ ! -f "$DWC_CONF_LOC/dwc2.cfg" ]; then create_single_dwcfk_cfg && ok_msg "dwc2.cfg created!" else warn_msg "There is already a file called 'dwc2.cfg'!" @@ -366,7 +366,7 @@ dwc_cfg_creation(){ ### create multi instance moonraker.conf files else - while [ $INSTANCE -le $INSTANCE_COUNT ]; do + while [ $INSTANCE -le "$INSTANCE_COUNT" ]; do ### set each instance to its own port PORT=$(expr $DEFAULT_PORT + $INSTANCE - 1) @@ -375,8 +375,8 @@ dwc_cfg_creation(){ ### start the creation of each instance status_msg "Creating dwc2.cfg for instance #$INSTANCE" - [ ! -d $DWC_CONF_LOC/printer_$INSTANCE ] && mkdir -p $DWC_CONF_LOC/printer_$INSTANCE - if [ ! -f $DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg ]; then + [ ! -d "$DWC_CONF_LOC/printer_$INSTANCE" ] && mkdir -p "$DWC_CONF_LOC/printer_$INSTANCE" + if [ ! -f "$DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" ]; then create_multi_dwcfk_cfg && ok_msg "dwc2.cfg created!" else warn_msg "There is already a file called 'dwc2.cfg'!" diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index afb5e33..6795928 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -104,8 +104,8 @@ install_webui(){ ### process possible disruptive services process_disruptive_services - [ $1 == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail " - [ $1 == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd " + [ "$1" == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail " + [ "$1" == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd " ### exit mainsail/fluidd setup if moonraker not found if [ $moonraker_chk_ok = "false" ]; then @@ -127,7 +127,7 @@ install_webui(){ fi ### ask user to install the recommended webinterface macros - if ! ls $klipper_cfg_loc/kiauh_macros.cfg 2>/dev/null 1>&2 || ! ls $klipper_cfg_loc/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then + if ! ls "$klipper_cfg_loc"/kiauh_macros.cfg 2>/dev/null 1>&2 || ! ls "$klipper_cfg_loc"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then get_user_selection_kiauh_macros "$IF_NAME2" fi ### create /etc/nginx/conf.d/upstreams.conf @@ -161,12 +161,12 @@ symlink_webui_nginx_log(){ [ ! -d "$LPATH" ] && mkdir -p "$LPATH" if [ -f "$UI_ACCESS_LOG" ] && [ ! -L "$LPATH/$1-access.log" ]; then status_msg "Creating symlink for $UI_ACCESS_LOG ..." - ln -s $UI_ACCESS_LOG "$LPATH" + ln -s "$UI_ACCESS_LOG" "$LPATH" ok_msg "OK!" fi if [ -f "$UI_ERROR_LOG" ] && [ ! -L "$LPATH/$1-error.log" ]; then status_msg "Creating symlink for $UI_ERROR_LOG ..." - ln -s $UI_ERROR_LOG "$LPATH" + ln -s "$UI_ERROR_LOG" "$LPATH" ok_msg "OK!" fi } @@ -178,25 +178,25 @@ install_kiauh_macros(){ ### create a backup of the config folder backup_klipper_config_dir ### handle multi printer.cfg - if ls $klipper_cfg_loc/printer_* 2>/dev/null 1>&2; then + if ls "$klipper_cfg_loc"/printer_* 2>/dev/null 1>&2; then for config in $(find $klipper_cfg_loc/printer_*/printer.cfg); do - path=$(echo $config | rev | cut -d"/" -f2- | rev) - if [ ! -f $path/kiauh_macros.cfg ]; then + path=$(echo "$config" | rev | cut -d"/" -f2- | rev) + if [ ! -f "$path/kiauh_macros.cfg" ]; then ### copy kiauh_macros.cfg to config location status_msg "Creating macro config file ..." - cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $path + cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "$path" ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" $path/printer.cfg + sed -i "1 i [include kiauh_macros.cfg]" "$path/printer.cfg" ok_msg "$path/kiauh_macros.cfg created!" fi done ### handle single printer.cfg - elif [ -f $klipper_cfg_loc/printer.cfg ] && [ ! -f $klipper_cfg_loc/kiauh_macros.cfg ]; then + elif [ -f "$klipper_cfg_loc/printer.cfg" ] && [ ! -f "$klipper_cfg_loc/kiauh_macros.cfg" ]; then ### copy kiauh_macros.cfg to config location status_msg "Creating macro config file ..." - cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $klipper_cfg_loc + cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "$klipper_cfg_loc" ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" $klipper_cfg_loc/printer.cfg + sed -i "1 i [include kiauh_macros.cfg]" "$klipper_cfg_loc/printer.cfg" ok_msg "$klipper_cfg_loc/kiauh_macros.cfg created!" fi ### restart klipper service to parse the modified printer.cfg @@ -216,7 +216,7 @@ mainsail_port_check(){ select_mainsail_port fi else - DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) SET_LISTEN_PORT=$DEFAULT_PORT fi SET_NGINX_CFG="true" @@ -237,7 +237,7 @@ fluidd_port_check(){ select_fluidd_port fi else - DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) SET_LISTEN_PORT=$DEFAULT_PORT fi SET_NGINX_CFG="true" @@ -323,10 +323,10 @@ mainsail_setup(){ MAINSAIL_DL_URL=$(curl -s $MAINSAIL_REPO_API | grep browser_download_url | cut -d'"' -f4 | head -1) ### remove existing and create fresh mainsail folder, then download mainsail - [ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR - mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR + [ -d "$MAINSAIL_DIR" ] && rm -rf "$MAINSAIL_DIR" + mkdir "$MAINSAIL_DIR" && cd $MAINSAIL_DIR status_msg "Downloading Mainsail $MAINSAIL_VERSION ..." - wget $MAINSAIL_DL_URL && ok_msg "Download complete!" + wget "$MAINSAIL_DL_URL" && ok_msg "Download complete!" ### extract archive status_msg "Extracting archive ..." @@ -343,8 +343,8 @@ mainsail_setup(){ } enable_mainsail_remotemode(){ - rm -f $MAINSAIL_DIR/config.json - echo -e "{\n \"remoteMode\":true\n}" >> $MAINSAIL_DIR/config.json + rm -f "$MAINSAIL_DIR/config.json" + echo -e "{\n \"remoteMode\":true\n}" >> "$MAINSAIL_DIR/config.json" } fluidd_setup(){ @@ -352,10 +352,10 @@ fluidd_setup(){ FLUIDD_DL_URL=$(curl -s $FLUIDD_REPO_API | grep browser_download_url | cut -d'"' -f4 | head -1) ### remove existing and create fresh fluidd folder, then download fluidd - [ -d $FLUIDD_DIR ] && rm -rf $FLUIDD_DIR - mkdir $FLUIDD_DIR && cd $FLUIDD_DIR + [ -d "$FLUIDD_DIR" ] && rm -rf "$FLUIDD_DIR" + mkdir "$FLUIDD_DIR" && cd $FLUIDD_DIR status_msg "Downloading Fluidd $FLUIDD_VERSION ..." - wget $FLUIDD_DL_URL && ok_msg "Download complete!" + wget "$FLUIDD_DL_URL" && ok_msg "Download complete!" ### extract archive status_msg "Extracting archive ..." @@ -374,7 +374,7 @@ set_upstream_nginx_cfg(){ [ -f "$NGINX_CONFD/common_vars.conf" ] && sudo mv "$NGINX_CONFD/common_vars.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_common_vars.conf" ### transfer ownership of backed up files from root to ${USER} for log in $(ls "$BACKUP_DIR/nginx_cfg"); do - sudo chown ${USER} "$BACKUP_DIR/nginx_cfg/$log" + sudo chown "${USER}" "$BACKUP_DIR/nginx_cfg/$log" done ### copy nginx configs to target destination if [ ! -f "$NGINX_CONFD/upstreams.conf" ]; then @@ -391,15 +391,15 @@ fetch_webui_ports(){ WEBIFS=(mainsail fluidd octoprint dwc2) for interface in "${WEBIFS[@]}"; do if [ -f "/etc/nginx/sites-available/${interface}" ]; then - port=$(grep -E "listen" /etc/nginx/sites-available/$interface | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2) - if [ ! -n "$(grep -E "${interface}_port" $INI_FILE)" ]; then - sed -i '$a'"${interface}_port=${port}" $INI_FILE + port=$(grep -E "listen" "/etc/nginx/sites-available/$interface" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2) + if [ ! -n "$(grep -E "${interface}_port" "$INI_FILE")" ]; then + sed -i '$a'"${interface}_port=${port}" "$INI_FILE" else - sed -i "/^${interface}_port/d" $INI_FILE - sed -i '$a'"${interface}_port=${port}" $INI_FILE + sed -i "/^${interface}_port/d" "$INI_FILE" + sed -i '$a'"${interface}_port=${port}" "$INI_FILE" fi else - sed -i "/^${interface}_port/d" $INI_FILE + sed -i "/^${interface}_port/d" "$INI_FILE" fi done }