ppl-os/conf-tool.sh

69 lines
1.5 KiB
Bash
Raw Normal View History

2018-10-21 11:59:08 +00:00
#!/bin/bash
die() {
echo -e "ERROR: $1" 1>&2
exit 2
}
if [ "x$1" == "xread" ]; then
if [ ! -e .config ]; then
die "No config found. Run '$ bash conf-tool.sh'"
fi
. .config
echo "${!2}"
2018-10-21 12:13:16 +00:00
exit
2018-10-21 11:59:08 +00:00
fi
signing_key=$(snap keys | tail -n 1 | sed "s| |\n|g" | head -n 1) # value if no key exists: "No"
user_email=$(snap whoami | sed "s|email: ||g") # value if not signed in: "-"
read_prompt() {
read -p "> Enter $1 (default $2$3): " val
if [ -z "$val" ]; then
val="$2"
fi
echo "< $val"
}
if [ "$user_email" == "-" ]; then
die "User email is not set up. Please run:\n\n\t$ snap login"
fi
if [ "$signing_key" == "No" ]; then
die "Signing key is not set up. https://tutorials.ubuntu.com/tutorial/create-your-own-core-image#3"
fi
dev_user=$(echo "$user_email" | sed "s|@.*||g")
read_prompt "Device channel" "stable"
channel="$val"
read_prompt "Device environment" "dev" " - use prod for production"
dev_env="$val"
read_prompt "Development device username" "$dev_user" " - taken from user email"
dev_user="$val"
read_prompt "Development device address" "localhost" " - for qemu emulation"
dev_addr="$val"
read_prompt "Development device port" "8022" " - for qemu emulation, use 22 for real device"
dev_port="$val"
vals="CHANNEL=$channel
ENV=$dev_env
DEVICE_IP=$dev_addr
DEVICE_USERNAME=$dev_user
DEVICE_PORT=$dev_addr
USER_KEY=$signing_key
USER_EMAIL=$user_email"
echo "
$vals
"
2018-10-21 11:59:08 +00:00
read -p "Is this correct [y/N]:" v
if [[ "$v" == [yY]* ]]; then
echo "$vals" > .config
else
echo
bash $0
fi