Skip to content

Commit 4947834

Browse files
committed
More portable argument parsing
macOS uses Bash 3.X and argument parsing works differently in that version, breaking ghe-detect-leaked-ssh-keys. /cc @sridharavinash
1 parent 0954735 commit 4947834

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

share/github-backup-utils/ghe-detect-leaked-ssh-keys

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,22 @@ set -e
1313

1414
usage() {
1515
grep '^#/' < "$0" | cut -c 4-
16+
exit 2
1617
}
1718

1819
TEMPDIR=$(mktemp -d)
1920

20-
# Parse args.
21-
ARGS=$(getopt --name "$0" --long help,snapshot: --options hs -- "$@") || {
22-
usage
23-
exit 2
24-
}
25-
eval set -- $ARGS
26-
2721
while [ $# -gt 0 ]; do
2822
case "$1" in
2923
-h|--help)
3024
usage
31-
exit 2
3225
;;
3326
-s|--snapshot)
34-
shift 2
35-
snapshot=$1
36-
;;
37-
--)
27+
snapshot=$2
3828
shift
39-
break
29+
;;
30+
*)
31+
usage
4032
;;
4133
esac
4234
shift
@@ -61,6 +53,10 @@ keys="ssh_host_dsa_key.pub ssh_host_ecdsa_key.pub ssh_host_ed25519_key.pub ssh_h
6153

6254
# Get all the host ssh keys tar from all snapshots directories
6355
if [ -n "$snapshot" ]; then
56+
if [ ! -d "$snapshot" ]; then
57+
echo "Invalid snapshot directory: $snapshot" >&2
58+
exit 1
59+
fi
6460
ssh_tars=$(find "$snapshot" -maxdepth 1 -type f -iname 'ssh-host-keys.tar')
6561
else
6662
ssh_tars=$(find "$GHE_DATA_DIR" -maxdepth 2 -type f -iname 'ssh-host-keys.tar')

0 commit comments

Comments
 (0)