style: substitute variables, rename variables

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-05-14 20:01:58 +02:00
parent 294aa47420
commit 64f4d16d16
8 changed files with 38 additions and 40 deletions

View File

@@ -173,13 +173,13 @@ function backup_klipperscreen() {
function backup_telegram_bot() { function backup_telegram_bot() {
local current_date local current_date
if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] ; then if [ -d "${TELEGRAM_BOT_DIR}" ] ; then
status_msg "Creating MoonrakerTelegramBot backup ..." status_msg "Creating MoonrakerTelegramBot backup ..."
check_for_backup_dir check_for_backup_dir
current_date=$(get_date) current_date=$(get_date)
status_msg "Timestamp: ${current_date}" status_msg "Timestamp: ${current_date}"
mkdir -p "${BACKUP_DIR}/MoonrakerTelegramBot-backups/${current_date}" mkdir -p "${BACKUP_DIR}/MoonrakerTelegramBot-backups/${current_date}"
cp -r "${MOONRAKER_TELEGRAM_BOT_DIR}" "${_}" cp -r "${TELEGRAM_BOT_DIR}" "${_}"
print_confirm "MoonrakerTelegramBot backup complete!" print_confirm "MoonrakerTelegramBot backup complete!"
else else
print_error "Can't backup MoonrakerTelegramBot directory!\n Not found!" print_error "Can't backup MoonrakerTelegramBot directory!\n Not found!"

View File

@@ -193,7 +193,7 @@ function start_flash_mcu() {
function start_flash_sd() { function start_flash_sd() {
local i=0 board_list=() device=${1} local i=0 board_list=() device=${1}
local flash_script="${HOME}/klipper/scripts/flash-sdcard.sh" local flash_script="${KLIPPER_DIR}/scripts/flash-sdcard.sh"
### write each supported board to the array to make it selectable ### write each supported board to the array to make it selectable
for board in $("${flash_script}" -l | tail -n +2); do for board in $("${flash_script}" -l | tail -n +2); do

View File

@@ -53,18 +53,18 @@ function set_globals() {
FLUIDD_TAGS="https://api.github.com/repos/fluidd-core/fluidd/tags" FLUIDD_TAGS="https://api.github.com/repos/fluidd-core/fluidd/tags"
#=============== KLIPPERSCREEN ================# #=============== KLIPPERSCREEN ================#
KLIPPERSCREEN_ENV_DIR="${HOME}/.KlipperScreen-env" KLIPPERSCREEN_ENV="${HOME}/.KlipperScreen-env"
KLIPPERSCREEN_DIR="${HOME}/KlipperScreen" KLIPPERSCREEN_DIR="${HOME}/KlipperScreen"
KLIPPERSCREEN_REPO="https://github.com/jordanruthe/KlipperScreen.git" KLIPPERSCREEN_REPO="https://github.com/jordanruthe/KlipperScreen.git"
#========== MOONRAKER-TELEGRAM-BOT ============# #========== MOONRAKER-TELEGRAM-BOT ============#
MOONRAKER_TELEGRAM_BOT_ENV_DIR="${HOME}/moonraker-telegram-bot-env" TELEGRAM_BOT_ENV="${HOME}/moonraker-telegram-bot-env"
MOONRAKER_TELEGRAM_BOT_DIR="${HOME}/moonraker-telegram-bot" TELEGRAM_BOT_DIR="${HOME}/moonraker-telegram-bot"
MOONRAKER_TELEGRAM_BOT_REPO="https://github.com/nlef/moonraker-telegram-bot.git" TELEGRAM_BOT_REPO="https://github.com/nlef/moonraker-telegram-bot.git"
#=============== PRETTY-GCODE =================# #=============== PRETTY-GCODE =================#
PGC_DIR="${HOME}/pgcode" PGC_DIR="${HOME}/pgcode"
PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode" PGC_REPO="https://github.com/Kragrathea/pgcode"
#================== NGINX =====================# #================== NGINX =====================#
NGINX_SA="/etc/nginx/sites-available" NGINX_SA="/etc/nginx/sites-available"

View File

@@ -150,7 +150,7 @@ function klipper_setup_dialog() {
function install_klipper_packages() { function install_klipper_packages() {
local packages python_version="${1}" local packages python_version="${1}"
local install_script="${HOME}/klipper/scripts/install-debian.sh" local install_script="${KLIPPER_DIR}/scripts/install-debian.sh"
status_msg "Reading dependencies..." status_msg "Reading dependencies..."
# shellcheck disable=SC2016 # shellcheck disable=SC2016

View File

@@ -64,9 +64,9 @@ function remove_klipperscreen() {
fi fi
### remove KlipperScreen VENV dir ### remove KlipperScreen VENV dir
if [ -d "${KLIPPERSCREEN_ENV_DIR}" ]; then if [ -d "${KLIPPERSCREEN_ENV}" ]; then
status_msg "Removing KlipperScreen VENV directory ..." status_msg "Removing KlipperScreen VENV directory ..."
rm -rf "${KLIPPERSCREEN_ENV_DIR}" && ok_msg "Directory removed!" rm -rf "${KLIPPERSCREEN_ENV}" && ok_msg "Directory removed!"
fi fi
### remove KlipperScreen service ### remove KlipperScreen service
@@ -111,8 +111,7 @@ function update_klipperscreen() {
git checkout -f master && ok_msg "Checkout successfull" git checkout -f master && ok_msg "Checkout successfull"
if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
status_msg "New dependecies detected..." status_msg "New dependecies detected..."
PYTHONDIR="${HOME}/.KlipperScreen-env" "${KLIPPERSCREEN_ENV}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
"${PYTHONDIR}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
ok_msg "Dependencies have been installed!" ok_msg "Dependencies have been installed!"
fi fi
ok_msg "Update complete!" ok_msg "Update complete!"
@@ -128,7 +127,7 @@ function get_klipperscreen_status() {
sf_count="$(klipperscreen_systemd | wc -w)" sf_count="$(klipperscreen_systemd | wc -w)"
### remove the "SERVICE" entry from the data array if a moonraker service is installed ### remove the "SERVICE" entry from the data array if a moonraker service is installed
local data_arr=(SERVICE "${KLIPPERSCREEN_DIR}" "${KLIPPERSCREEN_ENV_DIR}") local data_arr=(SERVICE "${KLIPPERSCREEN_DIR}" "${KLIPPERSCREEN_ENV}")
[ "${sf_count}" -gt 0 ] && unset "data_arr[0]" [ "${sf_count}" -gt 0 ] && unset "data_arr[0]"
### count+1 for each found data-item from array ### count+1 for each found data-item from array

View File

@@ -109,7 +109,7 @@ function telegram_bot_setup_dialog() {
function install_telegram_bot_dependencies() { function install_telegram_bot_dependencies() {
local packages local packages
local install_script="${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/install.sh" local install_script="${TELEGRAM_BOT_DIR}/scripts/install.sh"
### read PKGLIST from official install-script ### read PKGLIST from official install-script
status_msg "Reading dependencies..." status_msg "Reading dependencies..."
@@ -131,9 +131,9 @@ function install_telegram_bot_dependencies() {
function create_telegram_bot_virtualenv() { function create_telegram_bot_virtualenv() {
status_msg "Installing python virtual environment..." status_msg "Installing python virtual environment..."
### always create a clean virtualenv ### always create a clean virtualenv
[[ -d ${MOONRAKER_TELEGRAM_BOT_ENV_DIR} ]] && rm -rf "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" [[ -d ${TELEGRAM_BOT_ENV} ]] && rm -rf "${TELEGRAM_BOT_ENV}"
virtualenv -p /usr/bin/python3 --system-site-packages "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" virtualenv -p /usr/bin/python3 --system-site-packages "${TELEGRAM_BOT_ENV}"
"${MOONRAKER_TELEGRAM_BOT_ENV_DIR}"/bin/pip install -r "${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/requirements.txt" "${TELEGRAM_BOT_ENV}"/bin/pip install -r "${TELEGRAM_BOT_DIR}/scripts/requirements.txt"
} }
function telegram_bot_setup() { function telegram_bot_setup() {
@@ -145,8 +145,8 @@ function telegram_bot_setup() {
### step 1: clone telegram bot ### step 1: clone telegram bot
status_msg "Downloading Moonraker-Telegram-Bot ..." status_msg "Downloading Moonraker-Telegram-Bot ..."
### force remove existing Moonraker-Telegram-Bot dir ### force remove existing Moonraker-Telegram-Bot dir
[[ -d ${MOONRAKER_TELEGRAM_BOT_DIR} ]] && rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" [[ -d ${TELEGRAM_BOT_DIR} ]] && rm -rf "${TELEGRAM_BOT_DIR}"
cd "${HOME}" && git clone "${MOONRAKER_TELEGRAM_BOT_REPO}" cd "${HOME}" && git clone "${TELEGRAM_BOT_REPO}"
### step 2: install telegram bot dependencies and create python virtualenv ### step 2: install telegram bot dependencies and create python virtualenv
status_msg "Installing dependencies ..." status_msg "Installing dependencies ..."
@@ -206,7 +206,7 @@ function create_telegram_conf() {
function write_telegram_conf() { function write_telegram_conf() {
local cfg_dir=${1} cfg=${2} log=${3} local cfg_dir=${1} cfg=${2} log=${3}
local conf_template="${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/base_install_template" local conf_template="${TELEGRAM_BOT_DIR}/scripts/base_install_template"
[[ ! -d ${cfg_dir} ]] && mkdir -p "${cfg_dir}" [[ ! -d ${cfg_dir} ]] && mkdir -p "${cfg_dir}"
if [[ ! -f ${cfg} ]]; then if [[ ! -f ${cfg} ]]; then
@@ -269,7 +269,7 @@ function write_telegram_bot_service() {
sudo cp "${service_template}" "${service}" sudo cp "${service_template}" "${service}"
[[ -z ${i} ]] && sudo sed -i "s|instance %INST% ||" "${service}" [[ -z ${i} ]] && sudo sed -i "s|instance %INST% ||" "${service}"
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}" [[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${MOONRAKER_TELEGRAM_BOT_ENV_DIR}|; s|%DIR%|${MOONRAKER_TELEGRAM_BOT_DIR}|" "${service}" sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${TELEGRAM_BOT_ENV}|; s|%DIR%|${TELEGRAM_BOT_DIR}|" "${service}"
sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}" sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}"
fi fi
} }
@@ -298,18 +298,18 @@ function remove_telegram_bot_systemd() {
} }
function remove_telegram_bot_dir() { function remove_telegram_bot_dir() {
[[ ! -d ${MOONRAKER_TELEGRAM_BOT_DIR} ]] && return [[ ! -d ${TELEGRAM_BOT_DIR} ]] && return
status_msg "Removing Moonraker-Telegram-Bot directory ..." status_msg "Removing Moonraker-Telegram-Bot directory ..."
rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" rm -rf "${TELEGRAM_BOT_DIR}"
ok_msg "Directory removed!" ok_msg "Directory removed!"
} }
function remove_telegram_bot_env() { function remove_telegram_bot_env() {
[[ ! -d ${MOONRAKER_TELEGRAM_BOT_ENV_DIR} ]] && return [[ ! -d ${TELEGRAM_BOT_ENV} ]] && return
status_msg "Removing moonraker-telegram-bot-env directory ..." status_msg "Removing moonraker-telegram-bot-env directory ..."
rm -rf "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" rm -rf "${TELEGRAM_BOT_ENV}"
ok_msg "Directory removed!" ok_msg "Directory removed!"
} }
@@ -343,16 +343,16 @@ function remove_telegram_bot() {
function update_telegram_bot() { function update_telegram_bot() {
do_action_service "stop" "moonraker-telegram-bot" do_action_service "stop" "moonraker-telegram-bot"
if [[ ! -d ${MOONRAKER_TELEGRAM_BOT_DIR} ]]; then if [[ ! -d ${TELEGRAM_BOT_DIR} ]]; then
cd "${HOME}" && git clone "${MOONRAKER_TELEGRAM_BOT_REPO}" cd "${HOME}" && git clone "${TELEGRAM_BOT_REPO}"
else else
backup_before_update "moonraker-telegram-bot" backup_before_update "moonraker-telegram-bot"
status_msg "Updating Moonraker ..." status_msg "Updating Moonraker ..."
cd "${MOONRAKER_TELEGRAM_BOT_DIR}" && git pull cd "${TELEGRAM_BOT_DIR}" && git pull
### read PKGLIST and install possible new dependencies ### read PKGLIST and install possible new dependencies
install_telegram_bot_dependencies install_telegram_bot_dependencies
### install possible new python dependencies ### install possible new python dependencies
"${MOONRAKER_TELEGRAM_BOT_ENV_DIR}"/bin/pip install -r "${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/requirements.txt" "${TELEGRAM_BOT_ENV}"/bin/pip install -r "${TELEGRAM_BOT_DIR}/scripts/requirements.txt"
fi fi
ok_msg "Update complete!" ok_msg "Update complete!"
@@ -368,7 +368,7 @@ function get_telegram_bot_status() {
sf_count="$(telegram_bot_systemd | wc -w)" sf_count="$(telegram_bot_systemd | wc -w)"
### remove the "SERVICE" entry from the data array if a moonraker service is installed ### remove the "SERVICE" entry from the data array if a moonraker service is installed
local data_arr=(SERVICE "${MOONRAKER_TELEGRAM_BOT_DIR}" "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}") local data_arr=(SERVICE "${TELEGRAM_BOT_DIR}" "${TELEGRAM_BOT_ENV}")
(( sf_count > 0 )) && unset "data_arr[0]" (( sf_count > 0 )) && unset "data_arr[0]"
### count+1 for each found data-item from array ### count+1 for each found data-item from array
@@ -388,19 +388,19 @@ function get_telegram_bot_status() {
} }
function get_local_telegram_bot_commit() { function get_local_telegram_bot_commit() {
[[ ! -d ${MOONRAKER_TELEGRAM_BOT_DIR} || ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}/.git" ]] && return [[ ! -d ${TELEGRAM_BOT_DIR} || ! -d "${TELEGRAM_BOT_DIR}/.git" ]] && return
local commit local commit
cd "${MOONRAKER_TELEGRAM_BOT_DIR}" cd "${TELEGRAM_BOT_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}" echo "${commit}"
} }
function get_remote_telegram_bot_commit() { function get_remote_telegram_bot_commit() {
[[ ! -d ${MOONRAKER_TELEGRAM_BOT_DIR} || ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}/.git" ]] && return [[ ! -d ${TELEGRAM_BOT_DIR} || ! -d "${TELEGRAM_BOT_DIR}/.git" ]] && return
local commit local commit
cd "${MOONRAKER_TELEGRAM_BOT_DIR}" && git fetch origin -q cd "${TELEGRAM_BOT_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}" echo "${commit}"
} }

View File

@@ -127,7 +127,7 @@ function moonraker_setup_dialog() {
function install_moonraker_dependencies() { function install_moonraker_dependencies() {
local packages local packages
local install_script="${HOME}/moonraker/scripts/install-moonraker.sh" local install_script="${MOONRAKER_DIR}/scripts/install-moonraker.sh"
### read PKGLIST from official install-script ### read PKGLIST from official install-script
status_msg "Reading dependencies..." status_msg "Reading dependencies..."

View File

@@ -30,7 +30,7 @@ function install_pgc_for_klipper() {
dependency_check "${dep[@]}" dependency_check "${dep[@]}"
### clone repo ### clone repo
[ -d "${PGC_DIR}" ] && rm -rf "${PGC_DIR}" [ -d "${PGC_DIR}" ] && rm -rf "${PGC_DIR}"
cd "${HOME}" && git clone "${PGC_FOR_KLIPPER_REPO}" cd "${HOME}" && git clone "${PGC_REPO}"
### copy nginx config into destination directory ### copy nginx config into destination directory
sudo cp "${pgconfsrc}" "${pgconf}" sudo cp "${pgconfsrc}" "${pgconf}"
### replace default pi user in case the user is called different ### replace default pi user in case the user is called different
@@ -56,9 +56,9 @@ function install_pgc_for_klipper() {
function remove_prettygcode() { function remove_prettygcode() {
pgconf="/etc/nginx/sites-available/pgcode.local.conf" pgconf="/etc/nginx/sites-available/pgcode.local.conf"
pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf" pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
if [ -d "${HOME}/pgcode" ] || [ -f "${pgconf}" ] || [ -L "${pgconfsl}" ]; then if [ -d "${PGC_DIR}" ] || [ -f "${pgconf}" ] || [ -L "${pgconfsl}" ]; then
status_msg "Removing PrettyGCode for Klipper ..." status_msg "Removing PrettyGCode for Klipper ..."
rm -rf "${HOME}/pgcode" rm -rf "${PGC_DIR}"
sudo rm -f "${pgconf}" sudo rm -f "${pgconf}"
sudo rm -f "${pgconfsl}" sudo rm -f "${pgconfsl}"
sudo systemctl restart nginx sudo systemctl restart nginx
@@ -73,7 +73,6 @@ function remove_prettygcode() {
#=================================================# #=================================================#
function update_pgc_for_klipper() { function update_pgc_for_klipper() {
PGC_DIR="${HOME}/pgcode"
status_msg "Updating PrettyGCode for Klipper ..." status_msg "Updating PrettyGCode for Klipper ..."
cd "${PGC_DIR}" && git pull cd "${PGC_DIR}" && git pull
ok_msg "Update complete!" ok_msg "Update complete!"