90 lines
No EOL
1.9 KiB
Bash
Executable file
90 lines
No EOL
1.9 KiB
Bash
Executable file
function show_usage() {
|
|
echo "Usage: $0 [-e <email>] [-s <server>] [-v] [-d]"
|
|
echo "Options:"
|
|
echo " -e <email> Set email address"
|
|
echo " -s <server> Set server URL"
|
|
echo " -v Get module version"
|
|
echo " -d Get debug mode status"
|
|
exit 1
|
|
}
|
|
|
|
function set_email() {
|
|
if [[ "$1" == "" ]]; then
|
|
echo "[ERROR] Email address is required when using -e"
|
|
show_usage
|
|
fi
|
|
|
|
local email="$1"
|
|
local config_file="/data/adb/beesrv/config.txt"
|
|
|
|
touch "$config_file"
|
|
|
|
grep -v "^EMAIL=" "$config_file" > "$config_file.tmp" 2>/dev/null || true
|
|
echo "EMAIL=$email" >> "$config_file.tmp"
|
|
mv "$config_file.tmp" "$config_file"
|
|
|
|
echo "Success"
|
|
}
|
|
|
|
function set_server() {
|
|
if [[ "$1" == "" ]]; then
|
|
echo "[ERROR] Server URL is required when using -s"
|
|
show_usage
|
|
fi
|
|
|
|
local server_url="$1"
|
|
local config_file="/data/adb/beesrv/config.txt"
|
|
|
|
touch "$config_file"
|
|
|
|
grep -v "^SERVER=" "$config_file" > "$config_file.tmp" 2>/dev/null || true
|
|
echo "SERVER=$server_url" >> "$config_file.tmp"
|
|
mv "$config_file.tmp" "$config_file"
|
|
|
|
echo "Success"
|
|
}
|
|
|
|
function get_version() {
|
|
local mod_prop
|
|
mod_prop="$(dirname "$0")/../module.prop"
|
|
if [ -f "$mod_prop" ]; then
|
|
version=$(grep "version=" "$mod_prop" | cut -d'=' -f2)
|
|
echo "$version"
|
|
else
|
|
echo "Unknown"
|
|
fi
|
|
}
|
|
|
|
function get_debug_mode() {
|
|
local config_file="/data/adb/beesrv/config.txt"
|
|
if [ -f "$config_file" ] && grep -q "^DEBUG=true$" "$config_file"; then
|
|
echo "true"
|
|
else
|
|
echo "false"
|
|
fi
|
|
}
|
|
|
|
while getopts "e:s:vd" opt; do
|
|
case ${opt} in
|
|
e )
|
|
set_email "$OPTARG"
|
|
;;
|
|
s )
|
|
set_server "$OPTARG"
|
|
;;
|
|
v )
|
|
get_version
|
|
;;
|
|
d )
|
|
get_debug_mode
|
|
;;
|
|
\? )
|
|
echo "[ERROR] Invalid option -$OPTARG"
|
|
show_usage
|
|
;;
|
|
: )
|
|
echo "[ERROR] Option -$OPTARG requires an argument"
|
|
show_usage
|
|
;;
|
|
esac
|
|
done |