5
then echo "Please run script with sudo"
11
usage: $(basename $0) [options]
14
--clobber Will clear stored configurations and do a fresh run
18
TEMP=$(getopt -o c --long ,clobber -- "$@")
19
if [[ $? -ne 0 ]]; then
28
--clobber) clobber=1; shift ;;
35
mkdir -p $HOME/.pginstall
39
if [[ -n "$local" && "$local" =~ $3 ]]; then
40
## the value stored in the destination variable is already OK
41
echo "Using provided value [${local}] for: $1"
45
if [[ $# -eq 5 ]]; then
46
echo -n "${1} (default [${5}])"
57
[[ $local == "" ]] && local="$dfl"
58
if [[ "$local" =~ $3 ]]; then
61
echo " Please try again. [${local}] is not a valid value: $4"
66
function read_nonempty() {
67
if [[ $# -eq 3 ]]; then
68
read_raw "$1" "$2" "[^ ]+" "must be non-empty" "$3"
70
read_raw "$1" "$2" "[^ ]+" "must be non-empty"
74
function read_alnum() {
75
if [[ $# -eq 3 ]]; then
76
read_raw "$1" "$2" "^[0-9a-zA-Z]+$" "must use alphanumeric characters only" "$3"
78
read_raw "$1" "$2" "^[0-9a-zA-Z]+$" "must use alphanumeric characters only"
83
read_raw "$1" "$2" "^(ftp|http|https)://[^ ]+" "invalid schema (e.g. http://IP)"
86
function write_default_file() {
87
cat > $HOME/.pginstall/config <<DELIM__
88
MAAS_CONTROLLER_REGION_ADMIN_USERNAME="${MAAS_CONTROLLER_REGION_ADMIN_USERNAME}"
89
plumgrid_repo_url="${plumgrid_repo_url}"
90
lvm_keypath_content="${lvm_keypath_content}"
91
zone_name="${zone_name}"
96
function lcm_key_check() {
97
zone_name_=${zone_name}
99
zone_name="${zone_name_}"
100
read_alnum 'Enter LCM Canonical zone name' zone_name
101
read_url "Enter LCM repository base url" plumgrid_repo_url
102
echo -n "Checking ssh key on LCM for your deployment..."
103
ret=$(curl -Lks ${plumgrid_repo_url}/files/ssh_keys/zones/$zone_name/id_rsa.pub -o /tmp/id_rsa.pub -w '%{http_code}' || true)
104
[ $ret -eq 200 ] && break
105
echo "Unable to get ssh key from LCM for your deployment."
106
echo "Check zone name or retry after running canonical-pg-refresh.sh --key-only script on LCM and make sure your deployment shows up."
110
mkdir -p /var/lib/plumgrid/zones/$zone_name
111
mv /tmp/id_rsa.pub /var/lib/plumgrid/zones/$zone_name/id_rsa.pub
112
lvm_keypath_content="/var/lib/plumgrid/zones/${zone_name}/id_rsa.pub"
115
[[ -r $HOME/.pginstall/config && $clobber != 1 ]] && . $HOME/.pginstall/config
116
read_nonempty "Username of MAAS Region Admin User" MAAS_CONTROLLER_REGION_ADMIN_USERNAME "root"