-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.sh
116 lines (82 loc) · 2.62 KB
/
seed.sh
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
### ======= Runtime parameters
INTERFACE=$(ip route | grep default | cut -d ' ' -f 5)
IP=$(ip -4 addr show dev $INTERFACE | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
TMP_DIR="/tmp"
REPO="https://raw.githubusercontent.com/clemi2408/deploy/main"
LIBS=("commons.sh" "ipv6.sh" "rsyslog.sh" "lxd.sh" "maaspower.sh" "maas.sh" "juju.sh")
### ======= Argument constants
ARG_INSTALL="install"
ARG_REMOVE="remove"
ARG_INSTALL_CONTROLLER="installController"
ARG_REMOVE_CONTROLLER="removeController"
### ======= Functions
downloadLibs(){
for lib in ${LIBS[@]}; do
local url="$REPO/$lib"
local target="$TMP_DIR/lib/$lib"
echo "INFO: Downloading lib $lib via $url to $target"
curl -s -o $target $url
source "$target"
done
}
showHelp(){
echo "ERROR: Call ./seed.sh {$ARG_INSTALL|$ARG_REMOVE|$ARG_INSTALL_CONTROLLER|$ARG_REMOVE_CONTROLLER} configFile"
exit 1
}
checkArgs(){
if [ $# -ne 1 ]; then
echo "ERROR: Invalid argument length: $#"
showHelp
fi
if [ ! -f "$2" ]; then
echo "ERROR: Config File $2 not found"
showHelp
fi
}
loadConfig(){
local configFile="$1"
echo "INFO: Using config file $configFile"
echo "CONFIG: Start"
cat $configFile
echo "CONFIG: End"
echo "INFO: Loading config file $configFile"
source "$configFile"
}
### ======= Start
checkArgs "$@"
loadConfig "$2"
case "$1" in
"$ARG_INSTALL")
downloadLibs
commons_createFolder "$SEED_DIR"
ipv6_disable
rsyslog_enableRemote "$SEED_DIR"
lxd_install "$SEED_DIR" "$IP" "$LXD_PORT" "$INTERFACE" "$LXD_PROJECT_NAME" "$LXD_SECRET"
maaspower_install "$SEED_DIR" "$IP" "$MAASPOWER_PORT" "$MAASPOWER_USER" "$MAASPOWER_PASSWORD" "$MAASPOWER_USB_ID"
maas_install "$SEED_DIR" "$IP" "$MAAS_ADMIN_USER" "$MAAS_ADMIN_PASSWORD" "$IP" "$MAAS_GATEWAY_IP" "$MAAS_DNS_IP" "$MAAS_NTP_IP" "$IP" "$LXD_PORT" "$LXD_PROJECT_NAME" "$LXD_SECRET" "$MAAS_SSH_KEY" "$MAAS_DHCP_START" "$MAAS_DHCP_END"
juju_installClient "$JUJU_LOCAL_USER" "$MAAS_ADMIN_USER"
;;
"$ARG_REMOVE")
downloadLibs
juju_removeClient "$JUJU_LOCAL_USER"
maas_remove "$SEED_DIR"
maaspower_remove "$SEED_DIR"
lxd_remove "$SEED_DIR"
rsyslog_disableRemote "$SEED_DIR"
ipv6_enable
commons_deleteFolder "$SEED_DIR"
apt-get -y autoremove
;;
"$ARG_INSTALL_CONTROLLER")
downloadLibs
juju_installController "$JUJU_LOCAL_USER" "$LXD_PROJECT_NAME" "$JUJU_USER" "$JUJU_PASSWORD"
;;
"$ARG_REMOVE_CONTROLLER")
downloadLibs
juju_removeController "$JUJU_LOCAL_USER"
;;
*)
showHelp
;;
esac