Skip to content

Commit f34582d

Browse files
committedJan 20, 2022
Add brackets to all bash variable references.
1 parent f5062ec commit f34582d

16 files changed

+102
-125
lines changed
 

‎backup_minecraft_to_local.sh

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
#!/bin/bash
22
export SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd )
3-
source $SCRIPT_DIR/config/backup_config
4-
source $SCRIPT_DIR/config/sync_config
3+
source ${SCRIPT_DIR}/config/backup_config
4+
source ${SCRIPT_DIR}/config/sync_config
55

6-
source $SCRIPT_DIR/lib/minecraft_server_control.sh
7-
source $SCRIPT_DIR/lib/date_utils.sh
8-
source $SCRIPT_DIR/lib/progress_timer.sh
6+
source ${SCRIPT_DIR}/lib/minecraft_server_control.sh
7+
source ${SCRIPT_DIR}/lib/date_utils.sh
8+
source ${SCRIPT_DIR}/lib/progress_timer.sh
99

1010
run_zip_backup()
1111
{
1212
local current_date=$(get_current_date_as_YYYY_mm_dd)
1313

14-
local backup_dir=$BACKUPS_DIR/$current_date
14+
local backup_dir=${BACKUPS_DIR}/${current_date}
1515

16-
local source=$SYNC_DESTINATION
17-
local destination=$backup_dir/minecraft-$SERVER_NAME-$current_date.zip
16+
local source=${SYNC_DESTINATION}
17+
local destination=${backup_dir}/minecraft-${SERVER_NAME}-${current_date}.zip
1818

19-
mkdir -p $backup_dir
19+
mkdir -p ${backup_dir}
2020

21-
zip -r -9 $destination $source -x $source/rdiff-backup-data/**\*
21+
zip -r -9 ${destination} ${source} -x ${source}/rdiff-backup-data/**\*
2222

23-
printf "Backup zip file created: $destination\n"
23+
printf "Backup zip file created: ${destination}\n"
2424
}
2525

2626
backup_minecraft_to_local()
2727
{
28-
if $SYNC_ENABLED; then
28+
if ${SYNC_ENABLED}; then
2929
printf "This script will not run while syncing is enabled. It can be disabled in config/sync_config. Exiting...\n"
3030
exit 1
3131
fi

‎backup_wiki_files_to_local.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#!/bin/bash
22
export SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd )
3-
source $SCRIPT_DIR/config/backup_config
4-
source $SCRIPT_DIR/config/wiki_config
3+
source ${SCRIPT_DIR}/config/backup_config
4+
source ${SCRIPT_DIR}/config/wiki_config
55

6-
source $SCRIPT_DIR/lib/date_utils.sh
6+
source ${SCRIPT_DIR}/lib/date_utils.sh
77

88
backup_wiki_files_to_local()
99
{
1010
local current_date=$(get_current_date_as_YYYY_mm_dd)
1111

12-
local backup_dir=$BACKUPS_DIR/$current_date
12+
local backup_dir=${BACKUPS_DIR}/${current_date}
1313

14-
local source=$MEDIAWIKI_DIR
15-
local destination=$backup_dir/mediawiki-files-$current_date.zip
14+
local source=${MEDIAWIKI_DIR}
15+
local destination=${backup_dir}/mediawiki-files-${current_date}.zip
1616

17-
mkdir -p $backup_dir
17+
mkdir -p ${backup_dir}
1818

1919
printf "Creating mediawiki zip file...\n"
20-
zip -r -9 $destination $source
21-
printf "Mediawiki zip file created: $destination\n"
20+
zip -r -9 ${destination} ${source}
21+
printf "Mediawiki zip file created: ${destination}\n"
2222
}
2323

2424
backup_wiki_files_to_local

‎connect_container_to_mysql.sh

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ PIPE_DIR=/home/frumple/scripts/pipes
1818
PIPE_NAME=connect_container_to_mysql
1919

2020
# Full path to the named pipe
21-
PIPE_PATH="$PIPE_DIR/$PIPE_NAME"
21+
PIPE_PATH="${PIPE_DIR}/${PIPE_NAME}"
2222

2323
# Name of the docker network to connect the container to
2424
DOCKER_MYSQL_NETWORK_NAME=mysql-net
2525

2626
connect_container_to_mysql()
2727
{
28-
if [[ -p $PIPE_PATH ]]; then
29-
echo "Named pipe already exists: $PIPE_PATH"
28+
if [[ -p ${PIPE_PATH} ]]; then
29+
printf "Named pipe already exists: ${PIPE_PATH}\n"
3030
else
31-
echo "Creating named pipe: $PIPE_PATH"
32-
mkdir $PIPE_DIR
33-
mkfifo $PIPE_PATH
31+
printf "Creating named pipe: ${PIPE_PATH}\n"
32+
mkdir ${PIPE_DIR}
33+
mkfifo ${PIPE_PATH}
3434
fi
3535

36-
echo "Now listening for container IDs from named pipe..."
36+
printf "Now listening for container IDs from named pipe...\n"
3737

3838
while
39-
local container_id=$(cat $PIPE_PATH)
40-
echo "Running: docker network connect $DOCKER_MYSQL_NETWORK_NAME $container_id"
41-
docker network connect $DOCKER_MYSQL_NETWORK_NAME $container_id
42-
[[ ! -z $container_id ]]
39+
local container_id=$(cat ${PIPE_PATH})
40+
printf "Running: docker network connect ${DOCKER_MYSQL_NETWORK_NAME} ${container_id}\n"
41+
docker network connect ${DOCKER_MYSQL_NETWORK_NAME} ${container_id}
42+
[[ ! -z ${container_id} ]]
4343
do true; done
4444

45-
echo "Unable to read pipe, exiting..."
45+
printf "Unable to read pipe, exiting...\n"
4646
}
4747

4848
connect_container_to_mysql

‎lib/date_utils.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
get_current_date_as_YYYY_mm_dd() {
44
local current_date=`date +"%Y-%m-%d"`
5-
printf "%s" $current_date
5+
printf "%s" ${current_date}
66
}

‎lib/discord_utils.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ send_message_to_discord() {
66
local username=$2
77

88
if [[ -z ${username} ]]; then
9-
${SCRIPT_DIR}/lib/vendor/discord.sh --webhook-url="$DISCORD_WEBHOOK" --text "${text}"
9+
${SCRIPT_DIR}/lib/vendor/discord.sh --webhook-url="${DISCORD_WEBHOOK}" --text "${text}"
1010
else
11-
${SCRIPT_DIR}/lib/vendor/discord.sh --webhook-url="$DISCORD_WEBHOOK" --text "${text}" --username "${username}"
11+
${SCRIPT_DIR}/lib/vendor/discord.sh --webhook-url="${DISCORD_WEBHOOK}" --text "${text}" --username "${username}"
1212
fi
1313
}

‎lib/dynmap_utils.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ get_pretty_world_name()
99
get_pretty_map_name()
1010
{
1111
local map_name="$1"
12-
if [[ $map_name == "surface" ]]; then
12+
if [[ ${map_name} == "surface" ]]; then
1313
echo "3D"
1414
else
1515
echo "Flat"

‎lib/log_utils.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
source $SCRIPT_DIR/config/base_config
2+
source ${SCRIPT_DIR}/config/base_config
33

44
get_last_matching_line()
55
{
@@ -11,7 +11,7 @@ get_last_matching_line()
1111
search_number_of_lines=100
1212
fi
1313

14-
tail -n $search_number_of_lines $log_file_path | grep -P "$regex" | tail -n 1
14+
tail -n ${search_number_of_lines} ${log_file_path} | grep -P "${regex}" | tail -n 1
1515
}
1616

1717
get_number_of_matching_lines()
@@ -24,5 +24,5 @@ get_number_of_matching_lines()
2424
search_number_of_lines=100
2525
fi
2626

27-
tail -n $search_number_of_lines $log_file_path | grep -c -P "$regex"
27+
tail -n ${search_number_of_lines} ${log_file_path} | grep -c -P "${regex}"
2828
}

‎lib/minecraft_server_control.sh

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
2-
source $SCRIPT_DIR/config/base_config
3-
source $SCRIPT_DIR/config/log_config
4-
source $SCRIPT_DIR/config/minecraft_config
2+
source ${SCRIPT_DIR}/config/base_config
3+
source ${SCRIPT_DIR}/config/log_config
4+
source ${SCRIPT_DIR}/config/minecraft_config
55

6-
source $SCRIPT_DIR/lib/log_utils.sh
7-
source $SCRIPT_DIR/lib/pterodactyl_utils.sh
6+
source ${SCRIPT_DIR}/lib/log_utils.sh
7+
source ${SCRIPT_DIR}/lib/pterodactyl_utils.sh
88

99
run_minecraft_command()
1010
{
@@ -26,24 +26,24 @@ tellraw_in_minecraft()
2626
local italic_option=
2727
local underline_option=
2828

29-
if [[ $options == *"bold"* ]]; then
29+
if [[ ${options} == *"bold"* ]]; then
3030
bold_option=", \\\"bold\\\":true"
3131
fi
3232

33-
if [[ $options == *"italic"* ]]; then
33+
if [[ ${options} == *"italic"* ]]; then
3434
italic_option=", \\\"italic\\\":true"
3535
fi
3636

37-
if [[ $options == *"underlined"* ]]; then
37+
if [[ ${options} == *"underlined"* ]]; then
3838
underlined_option=", \\\"underlined\\\":true"
3939
fi
4040

41-
local json="{\\\"text\\\":\\\"$text\\\", \\\"color\\\":\\\"$color\\\"$bold_option$italic_option$underlined_option}"
41+
local json="{\\\"text\\\":\\\"${text}\\\", \\\"color\\\":\\\"${color}\\\"${bold_option}${italic_option}${underlined_option}}"
4242

4343
run_minecraft_command "tellraw @a $json"
4444

4545
# /tellraw doesn't get recorded in the server logs, use an Essentials /customtext command called /log to print the text content into the logs
46-
run_minecraft_command "log $text"
46+
run_minecraft_command "log ${text}"
4747
}
4848

4949
enter_readonly_mode_in_minecraft()
@@ -62,14 +62,14 @@ save_minecraft_world()
6262
local command="save-all"
6363
local save_all_time_in_seconds=1
6464

65-
if $flush; then
65+
if ${flush}; then
6666
command+=" flush"
6767
fi
6868

69-
run_minecraft_command "$command"
69+
run_minecraft_command "${command}"
7070
sleep 1
7171

72-
while [ $(get_number_of_matching_lines "Saved the game" "$LATEST_LOG_PATH" $SAVE_ALL_SEARCH_NUMBER_OF_LINES) -lt 1 ] && [ $save_all_time_in_seconds -lt $SAVE_ALL_TIMEOUT_IN_SECONDS ]
72+
while [ $(get_number_of_matching_lines "Saved the game" "${LATEST_LOG_PATH}" ${SAVE_ALL_SEARCH_NUMBER_OF_LINES}) -lt 1 ] && [ ${save_all_time_in_seconds} -lt ${SAVE_ALL_TIMEOUT_IN_SECONDS} ]
7373
do
7474
sleep 1
7575
((save_all_time_in_seconds++))

‎lib/progress_timer.sh

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/bin/bash
2-
source $SCRIPT_DIR/lib/discord_utils.sh
3-
source $SCRIPT_DIR/lib/minecraft_server_control.sh
4-
source $SCRIPT_DIR/lib/time_utils.sh
2+
source ${SCRIPT_DIR}/lib/discord_utils.sh
3+
source ${SCRIPT_DIR}/lib/minecraft_server_control.sh
4+
source ${SCRIPT_DIR}/lib/time_utils.sh
55

66
timer_text()
77
{
8-
if [[ -z $tellraw_color ]] && [[ -z $tellraw_options ]]; then
8+
if [[ -z ${tellraw_color} ]] && [[ -z ${tellraw_options} ]]; then
99
say_in_minecraft "$1"
1010
else
11-
tellraw_in_minecraft "$1" "$tellraw_color" "$tellraw_options"
11+
tellraw_in_minecraft "$1" "${tellraw_color}" "${tellraw_options}"
1212
fi
1313

14-
if [[ ! -z $send_to_discord ]]; then
15-
send_message_to_discord "$1" "$discord_username"
14+
if [[ ! -z ${send_to_discord} ]]; then
15+
send_message_to_discord "$1" "${discord_username}"
1616
fi
1717
}
1818

@@ -23,64 +23,64 @@ run_progress_timer()
2323
local task_function=$1
2424
shift
2525

26-
local start_message="Starting $task_function..."
27-
local progress_message="$task_function in progress"
28-
local finish_message="$task_function complete"
26+
local start_message="Starting ${task_function}..."
27+
local progress_message="${task_function} in progress"
28+
local finish_message="${task_function} complete"
2929

3030
local message_interval_in_seconds=1
3131
local show_hours=false
3232

3333
while getopts "s:p:f:m:h:c:o:d:u:" OPTION
3434
do
35-
case $OPTION in
36-
s) start_message="$OPTARG"
35+
case ${OPTION} in
36+
s) start_message="${OPTARG}"
3737
;;
38-
p) progress_message="$OPTARG"
38+
p) progress_message="${OPTARG}"
3939
;;
40-
f) finish_message="$OPTARG"
40+
f) finish_message="${OPTARG}"
4141
;;
42-
m) message_interval_in_seconds=$OPTARG
42+
m) message_interval_in_seconds=${OPTARG}
4343
;;
44-
h) show_hours=$OPTARG
44+
h) show_hours=${OPTARG}
4545
;;
46-
c) tellraw_color="$OPTARG"
46+
c) tellraw_color="${OPTARG}"
4747
;;
48-
o) tellraw_options="$OPTARG"
48+
o) tellraw_options="${OPTARG}"
4949
;;
50-
d) send_to_discord=$OPTARG
50+
d) send_to_discord=${OPTARG}
5151
;;
52-
u) discord_username="$OPTARG"
52+
u) discord_username="${OPTARG}"
5353
;;
5454
?) printf "Usage: %s <task_function> [-s <start_message>] [-p <progress_message>] [-f <finish_message>] [-m <message_interval>] [-h <show_hours>] [-c <tellraw_color>] [-o <tellraw_options>] [-d <send_to_discord>] [-u <discord_username>]" $(basename $0) >&2
5555
exit 2
5656
;;
5757
esac
5858
done
59-
shift $(($OPTIND - 1))
59+
shift $((${OPTIND} - 1))
6060

6161
local start_time=$(get_current_unix_time)
62-
local elapsed_time=$start_time
62+
local elapsed_time=${start_time}
6363
local formatted_time=""
6464

65-
timer_text "$start_message"
65+
timer_text "${start_message}"
6666

67-
$task_function &
67+
${task_function} &
6868
background_pid=$!
6969

70-
trap "kill $background_pid 2> /dev/null" EXIT
70+
trap "kill ${background_pid} 2> /dev/null" EXIT
7171

72-
while kill -0 $background_pid 2> /dev/null
72+
while kill -0 ${background_pid} 2> /dev/null
7373
do
7474
sleep 1
75-
elapsed_time=$(get_elapsed_unix_time $start_time)
75+
elapsed_time=$(get_elapsed_unix_time ${start_time})
7676

77-
modulus=$(($elapsed_time % $message_interval_in_seconds))
78-
if [ "$modulus" -eq 0 ]; then
79-
formatted_time=$(unix_time_to_minutes_seconds $elapsed_time $show_hours)
80-
timer_text "$progress_message: $formatted_time"
77+
modulus=$((${elapsed_time} % ${message_interval_in_seconds}))
78+
if [ "${modulus}" -eq 0 ]; then
79+
formatted_time=$(unix_time_to_minutes_seconds ${elapsed_time} ${show_hours})
80+
timer_text "${progress_message}: ${formatted_time}"
8181
fi
8282
done
8383

84-
formatted_time=$(unix_time_to_minutes_seconds $elapsed_time $show_hours)
85-
timer_text "$finish_message: $formatted_time"
84+
formatted_time=$(unix_time_to_minutes_seconds ${elapsed_time} ${show_hours})
85+
timer_text "${finish_message}: ${formatted_time}"
8686
}

‎lib/pterodactyl_utils.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
source $SCRIPT_DIR/config/pterodactyl_config
2+
source ${SCRIPT_DIR}/config/pterodactyl_config
33

44
send_pterodactyl_client_api_request() {
55
local endpoint=$1

‎lib/time_utils.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
get_elapsed_unix_time() {
44
local start_unix_time=$1
55
local current_unix_time=$(get_current_unix_time)
6-
if [ -z "$start_unix_time" ]; then
7-
start_unix_time=$current_unix_time
6+
if [ -z "${start_unix_time}" ]; then
7+
start_unix_time=${current_unix_time}
88
fi
99
local elapsed_unix_time=$((current_unix_time - start_unix_time))
10-
printf $elapsed_unix_time
10+
printf ${elapsed_unix_time}
1111
}
1212

1313
get_current_unix_time() {
@@ -18,13 +18,13 @@ unix_time_to_minutes_seconds() {
1818
local unix_time=$1
1919
local show_hours=$2
2020

21-
local unix_minutes=$((($unix_time / 60) % 60))
22-
local unix_seconds=$(($unix_time % 60))
21+
local unix_minutes=$(((${unix_time} / 60) % 60))
22+
local unix_seconds=$((${unix_time} % 60))
2323

24-
if $show_hours; then
25-
local unix_hours=$(($unix_time / 3600))
26-
printf "%dh %dm %ds" $unix_hours $unix_minutes $unix_seconds
24+
if ${show_hours}; then
25+
local unix_hours=$((${unix_time} / 3600))
26+
printf "%dh %dm %ds" ${unix_hours} ${unix_minutes} ${unix_seconds}
2727
else
28-
printf "%dm %ds" $unix_minutes $unix_seconds
28+
printf "%dm %ds" ${unix_minutes} ${unix_seconds}
2929
fi
3030
}

‎print_temp_dynmap_reminder.sh

-13
This file was deleted.

‎restart_server.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
export SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd )
3-
source $SCRIPT_DIR/lib/minecraft_server_control.sh
3+
source ${SCRIPT_DIR}/lib/minecraft_server_control.sh
44

55
restart_server()
66
{

‎restore_minecraft_server.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
export SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd )
3-
source $SCRIPT_DIR/config/sync_config
3+
source ${SCRIPT_DIR}/config/sync_config
44

55
restore_minecraft_server()
66
{
@@ -10,13 +10,13 @@ restore_minecraft_server()
1010
restore_time=$1
1111
fi
1212

13-
if $SYNC_ENABLED; then
13+
if ${SYNC_ENABLED}; then
1414
printf "This script will not run while syncing is enabled. Exiting...\n"
1515
exit
1616
fi
1717

18-
mkdir -p $SYNC_SOURCE
19-
rdiff-backup -r $restore_time -v $SYNC_VERBOSITY $SYNC_DESTINATION $SYNC_SOURCE
18+
mkdir -p ${SYNC_SOURCE}
19+
rdiff-backup -r ${restore_time} -v ${SYNC_VERBOSITY} ${SYNC_DESTINATION} ${SYNC_SOURCE}
2020
}
2121

2222
restore_minecraft_server $1

‎template.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
export SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd )
3-
source $SCRIPT_DIR/lib/minecraft_server_control.sh
3+
source ${SCRIPT_DIR}/lib/minecraft_server_control.sh
44

55
template()
66
{

‎test.sh

-10
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.