-
Notifications
You must be signed in to change notification settings - Fork 1
/
get
executable file
·210 lines (156 loc) · 5.71 KB
/
get
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
set -e
cat << "EOF"
___ ________ ________ ___ __ ___ ________ ________
|\ \ |\ __ \ |\ __ \ |\ \|\ \ |\ \ |\ ___ \ |\ ____\
\ \ \ \ \ \|\ \\ \ \|\ \\ \ \/ /|_\ \ \\ \ \\ \ \\ \ \___|
\ \ \ \ \ \\\ \\ \ \\\ \\ \ ___ \\ \ \\ \ \\ \ \\ \ \ ___
\ \ \____ \ \ \\\ \\ \ \\\ \\ \ \\ \ \\ \ \\ \ \\ \ \\ \ \|\ \
\ \_______\\ \_______\\ \_______\\ \__\\ \__\\ \__\\ \__\\ \__\\ \_______\
\|_______| \|_______| \|_______| \|__| \|__| \|__| \|__| \|__| \|_______|
________ ___ ________ ________ ________
|\ ____\ |\ \ |\ __ \ |\ ____\ |\ ____\
\ \ \___| \ \ \ \ \ \|\ \\ \ \___|_ \ \ \___|_
\ \ \ ___\ \ \ \ \ __ \\ \_____ \ \ \_____ \
\ \ \|\ \\ \ \____ \ \ \ \ \\|____|\ \ \|____|\ \
\ \_______\\ \_______\\ \__\ \__\ ____\_\ \ ____\_\ \
\|_______| \|_______| \|__|\|__||\_________\|\_________\
\|_________|\|_________|
Thanks for installing looking glass - github.com/glasslabs/looking-glass
EOF
function step() { tput bold && tput setaf 5 && echo "$@" && tput sgr0; }
function info() { tput bold && tput setaf 4 && echo "$@" && tput sgr0; }
function warn() { tput bold && tput setaf 3 && echo "$@" && tput sgr0; }
function success() { tput bold && tput setaf 2 && echo "$@" && tput sgr0; }
function err() { tput bold && tput setaf 1 && echo "$@" && tput sgr0; }
if test "$USER" == 'root'; then
err "Cowardly refusing to continue. Do not run as root."
exit 1
fi
ME_URL="https://github.com/glasslabs/installer/archive/main.zip"
ME_PATH="/tmp/installer"
TEMP_ME_FILE="/tmp/installer.zip"
ARCH="$(uname -m | cut -c1-5)"
RELEASES_URL="https://github.com/glasslabs/looking-glass/releases"
TEMP_FILE="/tmp/looking-glass.tar.gz"
USER="glass"
USER_HOME="/home/$USER"
check_version() {
if test "$ARCH" != "armv6" && test "$ARCH" != "armv7"; then
actual = $(uname -m)
err "ERROR: Unsupported architecture '$actual' for installer. Please install manually."
exit 1
fi
info "Arch Version supported"
}
extract_me() {
info "Extracting installer dependencies"
rm -rf "$ME_PATH" "$TEMP_ME_FILE"
curl -sL -o "$TEMP_ME_FILE" "$ME_URL"
mkdir -p "$ME_PATH"
unzip -qq "$TEMP_ME_FILE" -d "$ME_PATH"
mv "$ME_PATH"/*/* "$ME_PATH"
}
## Install Dependencies
install_deps() {
info "Installing dependencies"
sudo apt-get update -q
sudo apt-get install -q -y --no-install-recommends xserver-xorg-video-all xserver-xorg-input-all xserver-xorg-core \
xinit x11-xserver-utils git chromium-browser unclutter
}
## User functions
create_user() {
info "Setting up user"
if id -u "$USER" >/dev/null 2>&1; then
warn "User already exists. Skipping."
return
fi
step "Creating user"
sudo useradd -m -s "$(command -v bash)" -G adm,dialout,cdrom,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio $USER
step "Creating autologin for user"
sudo systemctl set-default multi-user.target
sudo ln -fs /lib/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
sudo cat <<EOF | sudo tee -a /etc/systemd/system/[email protected]/autologin.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM
EOF
}
setup_user() {
info "Setting up user"
sudo -u "$USER" -g "$USER" cp -a "$ME_PATH/home/." "$USER_HOME/"
if test -d "$USER_HOME/looking-glass"; then
warn "Config directory already exits. Skipping."
return
fi
step "Creating default config in $USER_HOME/looking-glass"
sudo -u "$USER" -g "$USER" mkdir -p "$USER_HOME/looking-glass/modules"
sudo -u "$USER" -g "$USER" mkdir -p "$USER_HOME/looking-glass/assets"
sudo -u "$USER" -g "$USER" touch "$USER_HOME/looking-glass/secrets.yaml"
sudo -u "$USER" -g "$USER" cp "$ME_PATH/config.yaml" "$USER_HOME/looking-glass/"
}
## Install Splashscreen
install_splashscreen() {
info "Setting splashscreen"
if ! command -v plymouth &> /dev/null; then
step "Installing plymouth"
sudo apt-get -q -y install plymouth plymouth-themes
fi
cmdline=/boot/cmdline.txt
if ! grep -q "splash" $cmdline ; then
step "Enabling splashscreen"
sudo sed -i $cmdline -e "s/$/ quiet splash plymouth.ignore-serial-consoles/"
fi
theme_dir="/usr/share/plymouth/themes"
if test ! -d "$theme_dir"; then
warn "Plymouth theme directory does not exist. Skipping."
return
fi
if test ! -d "$theme_dir/looking-glass"; then
sudo mkdir "$theme_dir/looking-glass"
fi
sudo cp -a "$ME_PATH/splashscreen/." "$theme_dir/looking-glass/"
if ! command -v plymouth-set-default-theme &> /dev/null; then
warn "Cannot set plymount theme."
return
fi
sudo plymouth-set-default-theme -R looking-glass
}
## Download and install looking glass
latest_version() {
curl -sL -o /dev/null -w %{url_effective} "$RELEASES_URL/latest" |
rev |
cut -f1 -d'/' |
rev
}
install_looking_glass() {
info "Installing Looking Glass"
test -z "$VERSION" && VERSION="$(latest_version)"
if test -z "$VERSION"; then
err "ERROR: Could not determine latest version"
exit 1
fi
if test -z "$ARCH"; then
err "ERROR: Could not determine arch to use"
exit 1
fi
rm -f "$TEMP_FILE"
curl -sL -o "$TEMP_FILE" "$RELEASES_URL/download/$VERSION/looking-glass_${VERSION}_linux_$ARCH.tar.gz"
sudo tar -zxf "$TEMP_FILE" -C /usr/local/bin/ glass
}
## Handle reboot
do_reboot () {
info 'Reboot? (y/N)' && read x && [[ "$x" == "y" ]] && /sbin/reboot;
}
## script main
check_version
install_deps
extract_me
create_user
setup_user
install_splashscreen
install_looking_glass
success "Config: $USER_HOME/looking-glass"
success "Modules: $USER_HOME/looking-glass/modules"
success "Install Completed."
do_reboot