11#! /bin/bash
22
3+ declare -A cont_array=(
4+ [portainer]=" Portainer"
5+ [nodered]=" Node-RED"
6+ [influxdb]=" InfluxDB"
7+ [telegraf]=" Telegraf (Requires InfluxDB and Mosquitto)"
8+ [grafana]=" Grafana"
9+ [mosquitto]=" Eclipse-Mosquitto"
10+ [postgres]=" Postgres"
11+ [adminer]=" Adminer"
12+ [openhab]=" openHAB"
13+ [zigbee2mqtt]=" zigbee2mqtt"
14+ [pihole]=" Pi-Hole"
15+ [plex]=" Plex media server"
16+ [tasmoadmin]=" TasmoAdmin"
17+ [rtl_433]=" RTL_433 to mqtt"
18+ [espruinohub]=" EspruinoHub"
19+
20+ )
21+ declare -a armhf_keys=(" portainer" " nodered" " influxdb" " grafana" " mosquitto" " telegraf" " postgres" " adminer" " openhab" " zigbee2mqtt" " pihole" " plex" " tasmoadmin" " rtl_433" " espruinohub" )
22+
23+ sys_arch=$( uname -m)
24+
325# timezones
426timezones () {
527
@@ -38,7 +60,7 @@ function yml_builder() {
3860 sevice_overwrite=$( whiptail --radiolist --title " Overwrite Option" --notags \
3961 " $1 service directory has been detected, use [SPACEBAR] to select you overwrite option" 20 78 12 \
4062 " none" " Do not overwrite" " ON" \
41- " env" " Preserve Environment and Config file " " OFF" \
63+ " env" " Preserve Environment and Config files " " OFF" \
4264 " full" " Pull full service from template" " OFF" \
4365 3>&1 1>&2 2>&3 )
4466
@@ -50,7 +72,7 @@ function yml_builder() {
5072 ;;
5173 " env" )
5274 echo " ...pulled $1 excluding env file"
53- rsync -a -q .templates/$1 / services/$1 / --exclude ' build.sh' --exclude ' $1.env' --exclude $( * .conf)
75+ rsync -a -q .templates/$1 / services/$1 / --exclude ' build.sh' --exclude ' $1.env' --exclude ' *.conf'
5476 ;;
5577 " none" )
5678 echo " ...$1 service not overwritten"
@@ -67,6 +89,8 @@ function yml_builder() {
6789 # if an env file exists check for timezone
6890 [ -f " ./services/$1 /$1 .env" ] && timezones ./services/$1 /$1 .env
6991
92+ # add new line then append service
93+ echo " " >> docker-compose.yml
7094 cat $service >> docker-compose.yml
7195
7296 # test for post build
@@ -118,23 +142,34 @@ case $mainmenu_selection in
118142 ;;
119143 # MAINMENU Build stack ------------------------------------------------------------
120144" build" )
121- container_selection=$( whiptail --title " Container Selection" --notags --separate-output --checklist \
122- " Use the [SPACEBAR] to select which containers you would like to install" 20 78 12 \
123- " portainer" " Portainer" " ON" \
124- " nodered" " Node-RED" " ON" \
125- " influxdb" " InfluxDB" " ON" \
126- " telegraf" " Telegraf (Requires InfluxDB and Mosquitto)" " OFF" \
127- " grafana" " Grafana" " ON" \
128- " mosquitto" " Eclipse-Mosquitto" " ON" \
129- " postgres" " Postgres" " OFF" \
130- " adminer" " Adminer" " OFF" \
131- " openhab" " openHAB" " OFF" \
132- " zigbee2mqtt" " zigbee2mqtt" " OFF" \
133- " pihole" " Pi-Hole" " OFF" \
134- " plex" " Plex media server" " OFF" \
135- " tasmoadmin" " TasmoAdmin" " OFF" \
136- " rtl_433" " RTL_433 to mqtt" " OFF" \
137- 3>&1 1>&2 2>&3 )
145+
146+ title=$' Container Selection'
147+ message=$' Use the [SPACEBAR] to select which containers you would like to install'
148+ entry_options=()
149+
150+ # check architecture and display appropriate menu
151+ if [ $( echo " $sys_arch " | grep -c " arm" ) ]; then
152+ keylist=(" ${armhf_keys[@]} " )
153+ else
154+ echo " your architecture is not supported yet"
155+ exit
156+ fi
157+
158+ # loop through the array of descriptions
159+ for index in " ${keylist[@]} " ; do
160+ entry_options+=(" $index " )
161+ entry_options+=(" ${cont_array[$index]} " )
162+
163+ # check selection
164+ if [ -f ./services/selection.txt ]; then
165+ [ $( grep " $index " ./services/selection.txt) ] && entry_options+=(" ON" ) || entry_options+=(" OFF" )
166+ else
167+ entry_options+=(" OFF" )
168+ fi
169+ done
170+
171+ container_selection=$( whiptail --title " $title " --notags --separate-output --checklist \
172+ " $message " 20 78 12 -- " ${entry_options[@]} " 3>&1 1>&2 2>&3 )
138173
139174 mapfile -t containers <<< " $container_selection"
140175
@@ -144,10 +179,14 @@ case $mainmenu_selection in
144179 echo " version: '2'" > docker-compose.yml
145180 echo " services:" >> docker-compose.yml
146181
182+ # store last sellection
183+ [ -f ./services/selection.txt ] && rm ./services/selection.txt
184+ touch ./services/selection.txt
147185 # Run yml_builder of all selected containers
148186 for container in " ${containers[@]} " ; do
149187 echo " Adding $container container"
150188 yml_builder " $container "
189+ echo " $container " >> ./services/selection.txt
151190 done
152191
153192 echo " docker-compose successfully created"
@@ -221,6 +260,7 @@ case $mainmenu_selection in
221260 " rclone" )
222261 sudo apt install -y rclone
223262 echo " Please run 'rclone config' to configure the rclone google drive backup"
263+
224264 # add enable file for rclone
225265 [ -d ~ /IOTstack/backups ] || sudo mkdir -p ~ /IOTstack/backups/
226266 sudo touch ~ /IOTstack/backups/rclone
0 commit comments