Skip to content

Commit

Permalink
monofon: fix shellcheck errors/warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kreatoo committed Jul 25, 2024
1 parent c45a08e commit 4d76bb2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
12 changes: 6 additions & 6 deletions scripts/monofon/monofon-health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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"
Expand All @@ -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() {
Expand Down
25 changes: 18 additions & 7 deletions scripts/monofon/rename_agent.sh
Original file line number Diff line number Diff line change
@@ -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')"

Expand All @@ -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\""
Expand All @@ -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"
Expand Down

0 comments on commit 4d76bb2

Please sign in to comment.