1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#!/bin/bash -e
CFG_FILE="${REMOTE_CFG_FILE:-$(pwd)/remote.setup.cfg}"
show_help() {
echo "usage: remote.setup config --host <host> --port <port> --user <USER> [--pass <PASS>] [--cert <CERT>]"
echo " remote.setup get-config-path"
echo ""
echo "Available options:"
echo " -h --help show this help message."
echo ""
}
get_config_path() {
echo "$CFG_FILE"
}
config() {
local host port user pass cert
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
show_help
exit
;;
--host)
host="$2"
shift 2
;;
--port)
port="$2"
shift 2
;;
--user)
user="$2"
shift 2
;;
--pass)
pass="$2"
shift 2
;;
--cert)
cert="$2"
shift 2
;;
*)
echo "tests.remote: unknown option $1" >&2
exit 1
;;
esac
done
if [ -z "$host" ] || [ -z "$port" ] || [ -z "$user" ]; then
echo "remote.setup: host, port and user values are required"
exit 1
fi
if [ -n "$pass" ] && [ -z "$(command -v sshpass)" ]; then
echo "remote.setup: sshpass tool is required when password is configured"
fi
if [ -n "$cert" ] && ! [ -f "$cert" ]; then
echo "remote.setup: certificate is set but file does not exist"
exit 1
fi
rm -f "$CFG_FILE"
echo "export TESTS_REMOTE_HOST=$host" > "$CFG_FILE"
# shellcheck disable=SC2129
echo "export TESTS_REMOTE_PORT=$port" >> "$CFG_FILE"
echo "export TESTS_REMOTE_USER=$user" >> "$CFG_FILE"
echo "export TESTS_REMOTE_PASS=$pass" >> "$CFG_FILE"
echo "export TESTS_REMOTE_CERT=$cert" >> "$CFG_FILE"
}
main() {
local subcommand="$1"
local action=
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
*)
action=$(echo "$subcommand" | tr '-' '_')
shift
break
;;
esac
done
if [ -z "$(declare -f "$action")" ]; then
echo "remote.setup: no such command: $subcommand"
show_help
exit 1
fi
"$action" "$@"
}
main "$@"
|