-
Notifications
You must be signed in to change notification settings - Fork 24
/
generate-images.sh
executable file
·96 lines (84 loc) · 2.72 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
#!/bin/bash
# prepare options list by searching through group_vars/ and locations/
unset locations i
for location in $({
while IFS= read -r -d $'\0' file; do
prefix="./locations/"
l=${file/#$prefix}
echo "${l%.yml}"
done < <(find ./locations/ -name "*.yml" -print0)
while IFS= read -r -d $'\0' directory; do
prefix="./group_vars/location_"
echo "${directory/#$prefix}"
done < <(find ./group_vars/ -maxdepth 1 -type d -name "location_*" -print0)
} | sort); do
locations[i++]="$location"
done
# 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/images"
break
fi
# delete old directories and get rid of artifacts
if [[ "$REPLY" == clean ]]
then
[ -d "./tmp/" ] && rm -r ./tmp/
echo "tmp directory was deleted..."
continue
fi
# check all configurations files with ansible-lint
if [[ "$REPLY" == lint ]]
then
yamllint -d .github/linters/.yaml-lint.yml .
ansible-lint -c .github/linters/.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
# generate images
echo "firmwares for the following location will be generated: $location"
echo 'executing: ansible-playbook play.yml --limit "'"$location"'-*" --tags image'
ansible-playbook play.yml --limit "$location-*" --tags image && echo "location of generated images: ./tmp/images"
# break the loop
break
done