Skip to content

Commit 3d8fb00

Browse files
authored
Merge pull request #631 from github/oakeyc/shellcheck
Add formatting + shellcheck to ghe-backup-config
2 parents 5fe3243 + 75154a7 commit 3d8fb00

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

share/github-backup-utils/ghe-backup-config

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#
1616

1717
# Assume this script lives in share/github-backup-utils/ when setting the root
18-
GHE_BACKUP_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"
18+
GHE_BACKUP_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
1919

2020
# Get the version from the version file.
21-
BACKUP_UTILS_VERSION="$(cat $GHE_BACKUP_ROOT/share/github-backup-utils/version)"
21+
BACKUP_UTILS_VERSION="$(cat "$GHE_BACKUP_ROOT/share/github-backup-utils/version")"
2222

2323
# If a version check was requested, show the current version and exit
2424
if [ -n "$GHE_SHOW_VERSION" ]; then
@@ -28,9 +28,9 @@ fi
2828

2929
# Check for "--help|-h" in args or GHE_SHOW_HELP=true and show usage
3030
# shellcheck disable=SC2120 # the script name is always referenced
31-
print_usage () {
31+
print_usage() {
3232
grep '^#/' <"$0" | cut -c 4-
33-
exit ${1:-1}
33+
exit "${1:-1}"
3434
}
3535

3636
if [ -n "$GHE_SHOW_HELP" ]; then
@@ -46,7 +46,7 @@ fi
4646
# Add the bin and share/github-backup-utils dirs to PATH
4747
PATH="$GHE_BACKUP_ROOT/bin:$GHE_BACKUP_ROOT/share/github-backup-utils:$PATH"
4848
# shellcheck source=share/github-backup-utils/bm.sh
49-
. $GHE_BACKUP_ROOT/share/github-backup-utils/bm.sh
49+
. "$GHE_BACKUP_ROOT/share/github-backup-utils/bm.sh"
5050

5151
# Save off GHE_HOSTNAME from the environment since we want it to override the
5252
# backup.config value when set.
@@ -87,7 +87,7 @@ ghe_parallel_check() {
8787
GHE_PARALLEL_COMMAND_OPTIONS="-j $GHE_PARALLEL_MAX_JOBS"
8888
# Default to the number of max rsync jobs to the same as GHE_PARALLEL_MAX_JOBS, if not set.
8989
# This is only applicable to ghe-restore-repositories currently.
90-
: ${GHE_PARALLEL_RSYNC_MAX_JOBS:="$GHE_PARALLEL_MAX_JOBS"}
90+
: "${GHE_PARALLEL_RSYNC_MAX_JOBS:="$GHE_PARALLEL_MAX_JOBS"}"
9191
fi
9292

9393
if [ -n "$GHE_PARALLEL_RSYNC_MAX_JOBS" ]; then
@@ -115,14 +115,14 @@ fi
115115
if [ -n "$GHE_VERBOSE" ]; then
116116
if [ -n "$GHE_VERBOSE_LOG" ]; then
117117
if [ "$GHE_PARALLEL_ENABLED" != "yes" ]; then
118-
exec 3>> "$GHE_VERBOSE_LOG"
118+
exec 3>>"$GHE_VERBOSE_LOG"
119119
else
120120
if ! echo | awk '{ print strftime("%b %d %H:%M:%S"); fflush(); }' &>/dev/null; then
121121
echo "Error: awk command failed. Please install https://www.gnu.org/software/gawk" 1>&2
122122
exit 1
123123
fi
124124
calling_script_name="$(caller | sed 's:.*/::')"
125-
exec 3> >(awk -v c=$calling_script_name '{ print strftime("%b %d %H:%M:%S"), c":", $0; fflush(); }' >> "$GHE_VERBOSE_LOG")
125+
exec 3> >(awk -v c="$calling_script_name" '{ print strftime("%b %d %H:%M:%S"), c":", $0; fflush(); }' >>"$GHE_VERBOSE_LOG")
126126
fi
127127
else
128128
exec 3>&1
@@ -149,12 +149,12 @@ fi
149149
# Convert the data directory path to an absolute path, basing any relative
150150
# paths on the backup-utils root, and using readlink, if available, to
151151
# canonicalize the path.
152-
if [ ${GHE_DATA_DIR:0:1} != "/" ]; then
153-
GHE_DATA_DIR="$( cd "$GHE_BACKUP_ROOT" && readlink -m "$GHE_DATA_DIR" 2> /dev/null || echo "$GHE_BACKUP_ROOT/$GHE_DATA_DIR" )"
152+
if [ "${GHE_DATA_DIR:0:1}" != "/" ]; then
153+
GHE_DATA_DIR="$(cd "$GHE_BACKUP_ROOT" && readlink -m "$GHE_DATA_DIR" 2>/dev/null || echo "$GHE_BACKUP_ROOT/$GHE_DATA_DIR")"
154154
fi
155155

156156
# Assign the Release File path if it hasn't been provided (eg: by test suite)
157-
: ${GHE_RELEASE_FILE:="/etc/github/enterprise-release"}
157+
: "${GHE_RELEASE_FILE:="/etc/github/enterprise-release"}"
158158

159159
# Check that utils are not being run directly on GHE appliance.
160160
if [ -f "$GHE_RELEASE_FILE" ]; then
@@ -238,7 +238,7 @@ export GHE_SNAPSHOT_DIR
238238
# Adjusts remote paths based on the version of the remote appliance. This is
239239
# called immediately after the remote version is obtained by
240240
# ghe_remote_version_required(). Child processes inherit the values set here.
241-
ghe_remote_version_config () {
241+
ghe_remote_version_config() {
242242
GHE_REMOTE_DATA_USER_DIR="$GHE_REMOTE_DATA_DIR/user"
243243
export GHE_REMOTE_DATA_DIR GHE_REMOTE_DATA_USER_DIR
244244
export GHE_REMOTE_LICENSE_FILE
@@ -249,7 +249,7 @@ ghe_remote_version_config () {
249249

250250
# If we don't have a readlink command, parse ls -l output.
251251
if ! type readlink 1>/dev/null 2>&1; then
252-
readlink () {
252+
readlink() {
253253
if [ -x "$1" ]; then
254254
ls -ld "$1" | sed 's/.*-> //'
255255
else
@@ -264,7 +264,7 @@ fi
264264
# that need the remote version should use this function instead of calling
265265
# ghe-host-check directly to reduce ssh roundtrips. The top-level ghe-backup and
266266
# ghe-restore commands establish the version for all subcommands.
267-
ghe_remote_version_required () {
267+
ghe_remote_version_required() {
268268
if [ -z "$GHE_REMOTE_VERSION" ]; then
269269
_out=$(ghe-host-check "$@")
270270
echo "$_out"
@@ -287,8 +287,8 @@ ghe_remote_version_required () {
287287
ghe_parse_version() {
288288
local version_major version_minor version_patch
289289
version_major=$(echo "${1#v}" | cut -f 1 -d .)
290-
version_minor=$(echo "$1" | cut -f 2 -d .)
291-
version_patch=$(echo "$1" | cut -f 3 -d .)
290+
version_minor=$(echo "$1" | cut -f 2 -d .)
291+
version_patch=$(echo "$1" | cut -f 3 -d .)
292292
version_patch=${version_patch%%[a-zA-Z]*}
293293

294294
echo "$version_major $version_minor $version_patch"
@@ -300,7 +300,7 @@ ghe_parse_version() {
300300
#
301301
# Scripts use these variables to alter behavior based on what's supported on the
302302
# appliance version.
303-
ghe_parse_remote_version () {
303+
ghe_parse_remote_version() {
304304
# shellcheck disable=SC2046 # Word splitting is required to populate the variables
305305
read -r GHE_VERSION_MAJOR GHE_VERSION_MINOR GHE_VERSION_PATCH <<<$(ghe_parse_version $1)
306306
export GHE_VERSION_MAJOR GHE_VERSION_MINOR GHE_VERSION_PATCH
@@ -309,23 +309,23 @@ ghe_parse_remote_version () {
309309
# Parses the <host> part out of a "<host>:<port>" or just "<host>" string.
310310
# This is used primarily to break hostspecs with non-standard ports down for
311311
# rsync commands.
312-
ssh_host_part () {
312+
ssh_host_part() {
313313
[ "${1##*:}" = "$1" ] && echo "$1" || echo "${1%:*}"
314314
}
315315

316316
# Parses the <port> part out of a "<host>:<port>" or just "<host>" string.
317317
# This is used primarily to break hostspecs with non-standard ports down for
318318
# rsync commands.
319-
ssh_port_part () {
319+
ssh_port_part() {
320320
[ "${1##*:}" = "$1" ] && echo 22 || echo "${1##*:}"
321321
}
322322

323323
# Usage: ghe_remote_logger <message>...
324324
# Log a message to /var/log/syslog on the remote instance.
325325
# Note: Use sparingly. Remote logging requires an ssh connection per invocation.
326-
ghe_remote_logger () {
326+
ghe_remote_logger() {
327327
echo "$@" |
328-
ghe-ssh "$GHE_HOSTNAME" -- logger -t backup-utils || true
328+
ghe-ssh "$GHE_HOSTNAME" -- logger -t backup-utils || true
329329
}
330330

331331
# Usage: ghe_verbose <message>
@@ -345,15 +345,14 @@ ghe_debug() {
345345
echo -e "Debug: $*" 1>&3
346346
elif [ -p /dev/stdin ]; then
347347
echo "\n" 1>&3
348-
while read line
349-
do
348+
while read line; do
350349
echo -e "Debug: $line" 1>&3
351-
done < /dev/stdin
350+
done </dev/stdin
352351
fi
353352
}
354353

355354
version() {
356-
echo "${@#v}" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
355+
echo "${@#v}" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
357356
}
358357

359358
# The list of gists returned by the source changed in 2.16.23, 2.17.14,
@@ -362,10 +361,10 @@ version() {
362361
# In newer versions, gist paths are unmodified, and only other repo types
363362
# are truncated with `dirname`.
364363
fix_paths_for_ghe_version() {
365-
if [[ "$GHE_REMOTE_VERSION" =~ 2.16. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.16.23)" ]] || \
366-
[[ "$GHE_REMOTE_VERSION" =~ 2.17. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.17.14)" ]] || \
367-
[[ "$GHE_REMOTE_VERSION" =~ 2.18. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.18.8)" ]] || \
368-
[[ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.19.3)" ]]; then
364+
if [[ "$GHE_REMOTE_VERSION" =~ 2.16. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.16.23)" ]] ||
365+
[[ "$GHE_REMOTE_VERSION" =~ 2.17. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.17.14)" ]] ||
366+
[[ "$GHE_REMOTE_VERSION" =~ 2.18. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.18.8)" ]] ||
367+
[[ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.19.3)" ]]; then
369368
GIST_FILTER="-e /gist/b"
370369
else
371370
unset GIST_FILTER
@@ -382,11 +381,11 @@ fix_paths_for_ghe_version() {
382381
sed $GIST_FILTER -e 's/\/$//; s/^[^\/]*$/./; s/\/[^\/]*$//'
383382
}
384383

385-
is_binary_backup_feature_on(){
384+
is_binary_backup_feature_on() {
386385
ghe-ssh "$GHE_HOSTNAME" ghe-config --true "mysql.backup.binary"
387386
}
388387

389388
# Check if the backup is binary by looking up the sentinel file
390-
is_binary_backup(){
389+
is_binary_backup() {
391390
test -f "$1/mysql-binary-backup-sentinel"
392-
}
391+
}

0 commit comments

Comments
 (0)