-
Notifications
You must be signed in to change notification settings - Fork 0
/
debian
executable file
·116 lines (92 loc) · 2.23 KB
/
debian
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
#!/usr/bin/env bash
set -e
catch_error() {
ret=$?
exec 1<&3 2<&4
if [[ $ret -ne 0 ]]; then
error_echo "failed" >&2
tail -n50 ./logfile.txt >&2
fi
cleanup
exit $ret
}
cleanup() {
rm ./logfile.txt
}
finalize() {
fancy_echo "Cleaning up and rebooting"
cleanup
sudo apt clean
sudo apt autoclean
sudo apt autoremove
sudo reboot || true
}
consistent_echo() {
string=$1
string_length=$(echo $string | wc -m)
space_character_length=$((($MAX_ECHO_LENGTH - $string_length) / 2))
filler=$(printf -v dash '%*s' $space_character_length ''; printf '%s' ${dash// /$SPACE_CHARACTER})
echo $filler$string$filler
}
fancy_echo() {
string=$(consistent_echo "$1")
printf "\n\e[32m$string\e[0m\n"
}
error_echo() {
string=$(consistent_echo "$1")
printf "\n\e[31m$string\e[0m\n"
}
terminal_width() {
if [ -z "$TERM" ]; then
tput cols
else
echo 50
fi
}
capture_output() {
if [ -z "$VERBOSE" ]; then
exec 3<&1 4<&2
$@ 1> ./logfile.txt 2>&1
else
$@
fi
}
run_build() {
local build_file=$1
while read config; do
fancy_echo "Running configuration for '$config'"
source $BUILDS_DIRECTORY/$config
cd $WORKING_DIRECTORY
done < "$build_file"
}
trap catch_error EXIT
WORKING_DIRECTORY=`pwd`
SUPPORT_DIRECTORY=$WORKING_DIRECTORY/support
BUILDS_DIRECTORY=$WORKING_DIRECTORY/builds
MAX_ECHO_LENGTH=$(terminal_width)
SPACE_CHARACTER="-"
machine_type=laptop
if [[ ! -z "$1" && "$1" != -* ]]; then
machine_type=$1
OPTIND=2
fi
while getopts "z" options; do
case $options in
z)
VERBOSE=true
;;
esac
done
fancy_echo "Running system install of $machine_type for $(id)"
fancy_echo "Checking system before installation"
run_build "$SUPPORT_DIRECTORY/required.build"
fancy_echo "Installing required setup packages"
capture_output < "$SUPPORT_DIRECTORY/base.packages" xargs sudo apt -y install
fancy_echo "Running setup build"
run_build "$SUPPORT_DIRECTORY/setup.build"
sudo apt update
capture_output < "$SUPPORT_DIRECTORY/$machine_type.packages" xargs sudo apt -y install
run_build "$SUPPORT_DIRECTORY/$machine_type.build"
fancy_echo "Add users to $machine_type groups"
capture_output "sudo usermod -aG $(paste -sd ',' $SUPPORT_DIRECTORY/$machine_type.groups) $USER"
finalize