style: move ! inside double brackets
my preferred way of writing them Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
@@ -65,12 +65,12 @@ function klipper_setup_dialog(){
|
||||
|
||||
### ask for amount of instances
|
||||
local klipper_count re="^[1-9][0-9]*$"
|
||||
while ! [[ ${klipper_count} =~ ${re} ]]; do
|
||||
while [[ ! ${klipper_count} =~ ${re} ]]; do
|
||||
read -p "${cyan}###### Number of Klipper instances to set up:${white} " -i "1" -e klipper_count
|
||||
### break if input is valid
|
||||
[[ ${klipper_count} =~ ${re} ]] && break
|
||||
error_msg "Invalid input:"
|
||||
error_msg "● Input not a number"
|
||||
### error messages on invalid input
|
||||
error_msg "Input not a number"
|
||||
done && select_msg "${klipper_count}"
|
||||
user_input+=("${klipper_count}")
|
||||
|
||||
@@ -120,7 +120,7 @@ function klipper_setup_dialog(){
|
||||
### get user input for custom names
|
||||
if [[ "${custom_names}" == "true" ]]; then
|
||||
local i=1 name="" re="^[0-9a-zA-Z]+$"
|
||||
while ! [[ ${name} =~ ${re} && ${i} -gt ${klipper_count} ]]; do
|
||||
while [[ ! ${name} =~ ${re} && ${i} -le ${klipper_count} ]]; do
|
||||
read -p "${cyan}###### Name for instance #${i}:${white} " name
|
||||
if [[ ${name} =~ ${re} ]]; then
|
||||
select_msg "Name: ${name}"
|
||||
@@ -287,13 +287,13 @@ function write_example_printer_cfg(){
|
||||
local cfg_template="${KIAUH_SRCDIR}/resources/printer.cfg"
|
||||
|
||||
### create a config directory if it doesn't exist
|
||||
if ! [[ -d "${cfg_dir}" ]]; then
|
||||
if [[ ! -d "${cfg_dir}" ]]; then
|
||||
status_msg "Creating '${cfg_dir}' ..."
|
||||
mkdir -p "${cfg_dir}"
|
||||
fi
|
||||
|
||||
### create a minimal config if there is no printer.cfg
|
||||
if ! [[ -f "${cfg}" ]]; then
|
||||
if [[ ! -f "${cfg}" ]]; then
|
||||
status_msg "Creating minimal example printer.cfg ..."
|
||||
cp "${cfg_template}" "${cfg}"
|
||||
fi
|
||||
@@ -549,7 +549,7 @@ function get_klipper_cfg_dir() {
|
||||
|
||||
### returns the major python version the klippy-env was created with
|
||||
function get_klipper_python_ver() {
|
||||
! [[ -d ${KLIPPY_ENV} ]] && return
|
||||
[[ ! -d ${KLIPPY_ENV} ]] && return
|
||||
|
||||
local version
|
||||
version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1)
|
||||
|
||||
@@ -54,21 +54,20 @@ function telegram_bot_setup_dialog(){
|
||||
blank_line
|
||||
echo -e "| Please select the number of Telegram Bot instances to |"
|
||||
echo -e "| install. Usually one Telegram Bot instance per |"
|
||||
echo -e "| Moonraker instance is required but you may not |"
|
||||
echo -e "| Moonraker instance is required, but you may not |"
|
||||
echo -e "| install more Telegram Bot instances than available |"
|
||||
echo -e "| Moonraker instances. |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local re="^[1-9][0-9]*$"
|
||||
while ! [[ ${telegram_bot_count} =~ ${re} && ${telegram_bot_count} -le ${moonraker_count} ]]; do
|
||||
while [[ ! ${telegram_bot_count} =~ ${re} || ${telegram_bot_count} -gt ${moonraker_count} ]]; do
|
||||
read -p "${cyan}###### Number of Telegram Bot instances to set up:${white} " -i "${moonraker_count}" -e telegram_bot_count
|
||||
### break if input is valid
|
||||
[[ ${telegram_bot_count} =~ ${re} && ${telegram_bot_count} -le ${moonraker_count} ]] && break
|
||||
### conditional error messages
|
||||
error_msg "Invalid input:"
|
||||
! [[ ${telegram_bot_count} =~ ${re} ]] && error_msg "● Input not a number"
|
||||
((telegram_bot_count > moonraker_count)) && error_msg "● Number of Telegram Bot instances larger than existing Moonraker instances"
|
||||
[[ ! ${telegram_bot_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( telegram_bot_count > moonraker_count )) && error_msg "Number of Telegram Bot instances larger than existing Moonraker instances"
|
||||
done && select_msg "${telegram_bot_count}"
|
||||
else
|
||||
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grather than one!"
|
||||
@@ -207,9 +206,9 @@ function create_telegram_conf(){
|
||||
function write_telegram_conf(){
|
||||
local cfg_dir=${1} cfg=${2} log=${3}
|
||||
local conf_template="${MOONRAKER_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
|
||||
status_msg "Creating telegram.conf in ${cfg_dir} ..."
|
||||
cp "${conf_template}" "${cfg}"
|
||||
sed -i "s|some_log_path|${log}|g" "${cfg}"
|
||||
@@ -263,7 +262,7 @@ function write_telegram_bot_service(){
|
||||
local service_template="${KIAUH_SRCDIR}/resources/moonraker-telegram-bot.service"
|
||||
|
||||
### replace all placeholders
|
||||
if ! [[ -f "${service}" ]]; then
|
||||
if [[ ! -f "${service}" ]]; then
|
||||
status_msg "Creating Telegram Bot Service ${i} ..."
|
||||
sudo cp "${service_template}" "${service}"
|
||||
[[ -z ${i} ]] && sudo sed -i "s|instance %INST% ||" "${service}"
|
||||
@@ -295,14 +294,14 @@ function remove_telegram_bot_systemd() {
|
||||
}
|
||||
|
||||
function remove_telegram_bot_dir() {
|
||||
! [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]] && return
|
||||
[[ ! -d ${MOONRAKER_TELEGRAM_BOT_DIR} ]] && return
|
||||
status_msg "Removing Moonraker-Telegram-Bot directory ..."
|
||||
rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_telegram_bot_env() {
|
||||
! [[ -d "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" ]] && return
|
||||
[[ ! -d ${MOONRAKER_TELEGRAM_BOT_ENV_DIR} ]] && return
|
||||
status_msg "Removing moonraker-telegram-bot-env directory ..."
|
||||
rm -rf "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
@@ -332,7 +331,7 @@ function remove_telegram_bot(){
|
||||
|
||||
function update_telegram_bot(){
|
||||
do_action_service "stop" "moonraker-telegram-bot"
|
||||
if ! [[ -d ${MOONRAKER_TELEGRAM_BOT_DIR} ]]; then
|
||||
if [[ ! -d ${MOONRAKER_TELEGRAM_BOT_DIR} ]]; then
|
||||
cd "${HOME}" && git clone "${MOONRAKER_TELEGRAM_BOT_REPO}"
|
||||
else
|
||||
backup_before_update "moonraker-telegram-bot"
|
||||
@@ -378,7 +377,7 @@ function get_telegram_bot_status(){
|
||||
|
||||
function get_local_telegram_bot_commit(){
|
||||
local commit
|
||||
! [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]] || ! [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}"/.git ]] && return
|
||||
[[ ! -d ${MOONRAKER_TELEGRAM_BOT_DIR} || ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}/.git" ]] && return
|
||||
cd "${MOONRAKER_TELEGRAM_BOT_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
@@ -386,7 +385,7 @@ function get_local_telegram_bot_commit(){
|
||||
|
||||
function get_remote_telegram_bot_commit(){
|
||||
local commit
|
||||
! [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]] || ! [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}"/.git ]] && return
|
||||
[[ ! -d ${MOONRAKER_TELEGRAM_BOT_DIR} || ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}/.git" ]] && return
|
||||
cd "${MOONRAKER_TELEGRAM_BOT_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
|
||||
@@ -73,20 +73,19 @@ function moonraker_setup_dialog(){
|
||||
blank_line
|
||||
echo -e "| Please select the number of Moonraker instances to |"
|
||||
echo -e "| install. Usually one Moonraker instance per Klipper |"
|
||||
echo -e "| instance is required but you may not install more |"
|
||||
echo -e "| instance is required, but you may not install more |"
|
||||
echo -e "| Moonraker instances than available Klipper instances. |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local re="^[1-9][0-9]*$"
|
||||
while ! [[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]]; do
|
||||
while [[ ! ${moonraker_count} =~ ${re} || ${moonraker_count} -gt ${klipper_count} ]]; do
|
||||
read -p "${cyan}###### Number of Moonraker instances to set up:${white} " -i "${klipper_count}" -e moonraker_count
|
||||
### break if input is valid
|
||||
[[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]] && break
|
||||
### conditional error messages
|
||||
error_msg "Invalid input:"
|
||||
! [[ ${moonraker_count} =~ ${re} ]] && error_msg "● Input not a number"
|
||||
((moonraker_count > klipper_count)) && error_msg "● Number of Moonraker instances larger than existing Klipper instances"
|
||||
[[ ! ${moonraker_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( moonraker_count > klipper_count )) && error_msg "Number of Moonraker instances larger than installed Klipper instances"
|
||||
done && select_msg "${moonraker_count}"
|
||||
else
|
||||
log_error "Internal error. klipper_count of '${klipper_count}' not equal or grather than one!"
|
||||
|
||||
@@ -46,19 +46,18 @@ function octoprint_setup_dialog(){
|
||||
blank_line
|
||||
echo -e "| Please select the number of OctoPrint instances to |"
|
||||
echo -e "| install. Usually one OctoPrint instance per Klipper |"
|
||||
echo -e "| instance is required but you may not install more |"
|
||||
echo -e "| instance is required, but you may not install more |"
|
||||
echo -e "| OctoPrint instances than available Klipper instances. |"
|
||||
bottom_border
|
||||
|
||||
local re="^[1-9][0-9]*$"
|
||||
while ! [[ ${octoprint_count} =~ ${re} && ${octoprint_count} -le ${klipper_count} ]]; do
|
||||
while [[ ! ${octoprint_count} =~ ${re} || ${octoprint_count} -gt ${klipper_count} ]]; do
|
||||
read -p "${cyan}###### Number of OctoPrint instances to set up:${white} " -i "${klipper_count}" -e octoprint_count
|
||||
### break if input is valid
|
||||
[[ ${octoprint_count} =~ ${re} ]] && break
|
||||
### conditional error messages
|
||||
error_msg "Invalid Input:"
|
||||
! [[ ${octoprint_count} =~ ${re} ]] && error_msg "● Input not a number"
|
||||
((octoprint_count > klipper_count)) && error_msg "● Number of OctoPrint instances larger than existing Klipper instances"
|
||||
[[ ! ${octoprint_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( octoprint_count > klipper_count )) && error_msg "Number of OctoPrint instances larger than existing Klipper instances"
|
||||
done && select_msg "${octoprint_count}"
|
||||
else
|
||||
log_error "Internal error. octoprint_count of '${octoprint_count}' not equal or grather than one!"
|
||||
@@ -140,7 +139,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}!"
|
||||
@@ -247,8 +246,8 @@ OCTOPRINT
|
||||
ok_msg "Ok!"
|
||||
|
||||
### create config.yaml
|
||||
if ! [[ -f ${basedir}/config.yaml ]]; then
|
||||
! [[ -d ${basedir} ]] && mkdir "${basedir}"
|
||||
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
|
||||
@@ -312,7 +311,7 @@ function remove_octoprint_service(){
|
||||
}
|
||||
|
||||
function remove_octoprint_sudoers(){
|
||||
! [[ -f /etc/sudoers.d/octoprint-shutdown ]] && return
|
||||
[[ ! -f /etc/sudoers.d/octoprint-shutdown ]] && return
|
||||
### remove sudoers file
|
||||
sudo rm -f /etc/sudoers.d/octoprint-shutdown
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user