forked from freifunk-berlin/bbb-configs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-images.sh
executable file
·99 lines (86 loc) · 2.83 KB
/
generate-images.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
#!/bin/bash
# prepare options list from directory search
unset locations i
while IFS= read -r -d $'\0' directory; do
prefix="./group_vars/location_"
location=${directory/#$prefix}
locations[i++]="$location"
done < <(find ./group_vars/ -maxdepth 1 -type d -name "location_*" -print0 | sort -z)
# show menu
echo "Usage:
This helper script allows you to perform bbb-config related tasks via an easy menu.
Either select a location by typing the corresponding number or one of the following
actions by just typing them.
Actions:
abort
return to the command line
all
generage images for all nodes and locations and return to the command line
clean
delete all temporary files generated by bbb-configs and wait for additional
commands
lint
check all configuration files by calling yamllint and ansible-lint and
return to the command line
requirements
install the requirements and wait for additional commands
" >&2
echo "The following locations were found:
" >&2
PS3="
Use a location number to generate images for that location or type an action: "
# allow the user to choose a location
unset location
select location in "${locations[@]}"
do
# abort if selected
if [[ "$REPLY" == abort ]]; then break; fi
# generate all images if selected
if [[ "$REPLY" == all ]]
then
ansible-playbook play.yml --tags image && echo "location of generated images: /tmp/ansible-openwrt/images"
break
fi
# delete old directories and get rid of artifacts
if [[ "$REPLY" == clean ]]
then
[ -d "/tmp/ansible-openwrt/" ] && rm -r /tmp/ansible-openwrt/
echo "tmp directory was deleted..."
continue
fi
# check all configurations files with ansible-lint
if [[ "$REPLY" == lint ]]
then
yamllint -d .config/yaml-lint.yml .
ansible-lint -c .config/ansible-lint.yml
break
fi
# install or update requirements
if [[ "$REPLY" == requirements ]]
then
pip3 install -r requirements.txt
continue
fi
# complain if no location was selected, and loop to ask again
if [[ "$location" == "" ]]
then
echo "'$REPLY' is not a valid selection"
continue
fi
# prepare list of nodes from file search
unset nodes i
while IFS= read -r -d $'\0' file; do
prefix="./host_vars/"
suffix="/base.yml"
node=${file/#$prefix}
node=${node%"$suffix"}
nodes[i++]="$node"
done < <(grep -rnwlZ './host_vars/' -e "location: ${location//_/-}$" | sort -z)
nodelist=$(IFS=, ; echo "${nodes[*]}")
# generate images
echo "firmwares for the following devices at $location will be generated:"
echo "$nodelist"
ansible-playbook play.yml --limit "$nodelist" --tags image && echo "location of generated images: /tmp/ansible-openwrt/images"
# break the loop
break
done