From 4d76bb287ced450c88c5fae769ae9e0867c3bc2b Mon Sep 17 00:00:00 2001 From: "Kreato (Work)" Date: Thu, 25 Jul 2024 17:02:22 +0300 Subject: [PATCH] monofon: fix shellcheck errors/warnings --- scripts/monofon/monofon-health.sh | 12 ++++++------ scripts/monofon/rename_agent.sh | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/scripts/monofon/monofon-health.sh b/scripts/monofon/monofon-health.sh index 081f68b..9cc39a1 100755 --- a/scripts/monofon/monofon-health.sh +++ b/scripts/monofon/monofon-health.sh @@ -344,10 +344,10 @@ function rewrite_monofon_data() { fi fi - if [ -f $file ]; then + if [ -f "$file" ]; then # row_count=$(cat $file) #alarm "Monofon verilerin yeniden yazılması tamamlandı. Satır sayısı: $row_count" - rm $file + rm "$file" fi fi } @@ -356,8 +356,8 @@ function check_data_file() { echo_status "Checking data.json" data_timestamp="$TMP_PATH_SCRIPT/monofon_data-json.txt" data_file="/var/www/html/monofon-pano-yeni/data/data.json" - if [ -f $data_timestamp ]; then - before=$(cat $data_timestamp) + if [ -f "$data_timestamp" ]; then + before=$(cat "$data_timestamp") now=$(stat -c %y $data_file) if [ "$before" == "$now" ]; then alarm_check_down "data-json" "No changes made to file: $data_file" @@ -366,9 +366,9 @@ function check_data_file() { alarm_check_up "data-json" "Data file updated. File: $data_file" print_colour "data.json" "updated" fi - echo "$now" >$data_timestamp + echo "$now" >"$data_timestamp" fi - stat -c %y $data_file >$data_timestamp + stat -c %y $data_file >"$data_timestamp" } function main() { diff --git a/scripts/monofon/rename_agent.sh b/scripts/monofon/rename_agent.sh index 2d50113..fd49d98 100644 --- a/scripts/monofon/rename_agent.sh +++ b/scripts/monofon/rename_agent.sh @@ -1,7 +1,18 @@ -#/bin/bash +#!/usr/bin/env bash ###~ description: Rename a agent in Asterisk -[[ ! -n "$1" ]] && { echo "User ID is not defined..."; exit 1; } || { EXTEN=$1; }; -[[ ! -n "$2" ]] && { echo "Username is not defined..."; exit 1; } || { NAME="$2"; }; +if [[ -z "$1" ]]; then + echo "User ID is not defined..." + exit 1 +else + EXTEN=$1 +fi + +if [[ -z "$2" ]]; then + echo "Username is not defined..." + exit 1 +else + NAME="$2" +fi OLD_NAME="$(mysql -e "SELECT label FROM asterisk.fop2buttons WHERE exten = $EXTEN;" | sed '1d')" @@ -20,7 +31,7 @@ mysql -e "SELECT name, queue FROM qstats.monofon_agent WHERE extension = $EXTEN asterisk -rx "queue show" | grep "Local/$EXTEN@" echo "---------------------------------------" echo "Press Enter to continue..." -read +read -r asterisk -rx "database get AMPUSER/$EXTEN cidname" asterisk -rx "database put AMPUSER/$EXTEN cidname \"$NAME\"" @@ -46,11 +57,11 @@ else amportal a r fi -queue_list=($(asterisk -rx "queue show" | grep strategy | awk '{print $1}')) -for queue in ${queue_list[@]}; do +mapfile -t queue_list < <(asterisk -rx "queue show" | grep strategy | awk '{print $1}') +for queue in "${queue_list[@]}"; do member=$(asterisk -rx "queue show $queue" | grep "Local/$EXTEN@" | perl -ne '/\((\S+)/ && print "$1\n"') state_interface=$(asterisk -rx "queue show $queue" | grep "Local/$EXTEN@" | perl -ne '/from (\S+)\)/ && print "$1\n"') - if [[ ! -z "$member" ]]; then + if [[ -n "$member" ]]; then echo "User $EXTEN is in queue $queue" asterisk -rx "queue remove member $member from $queue" asterisk -rx "queue add member $member to $queue penalty 0 as \"$NAME\" state_interface $state_interface"