forked from aaronwmorris/indi-allsky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_usb_automount.sh
executable file
·238 lines (174 loc) · 5.43 KB
/
setup_usb_automount.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash
#set -x # command tracing
set -o errexit
set -o nounset
PATH=/bin:/usr/bin
export PATH
if [ ! -f "/etc/os-release" ]; then
echo
echo "Unable to determine OS from /etc/os-release"
echo
exit 1
fi
source /etc/os-release
DISTRO_ID="${ID:-unknown}"
DISTRO_VERSION_ID="${VERSION_ID:-unknown}"
CPU_ARCH=$(uname -m)
echo
echo "#######################################################"
echo "### Welcome to the indi-allsky USB automount script ###"
echo "#######################################################"
if [[ "$(id -u)" == "0" ]]; then
echo "Please do not run this script as root"
echo "Re-run this script as the user which will execute the indi-allsky software"
echo
echo
exit 1
fi
if [[ -f "/etc/astroberry.version" ]]; then
echo "Please do not run this script on an Astroberry server"
echo "Astroberry has native automount support"
echo
echo
exit 1
fi
echo
echo
echo "This script sets up USB automount (udisks2) for your Allsky camera"
echo
echo
echo "Distribution: $DISTRO_ID"
echo "Release: $DISTRO_VERSION_ID"
echo "Arch: $CPU_ARCH"
echo
echo
echo
echo "Setup proceeding in 10 seconds... (control-c to cancel)"
echo
sleep 10
# Run sudo to ask for initial password
sudo true
echo "**** Installing packages... ****"
if [[ "$DISTRO_ID" == "raspbian" && "$DISTRO_VERSION_ID" == "12" ]]; then
sudo apt-get update
sudo apt-get -y install \
udisks2 \
udiskie \
exfatprogs \
dosfstools
elif [[ "$DISTRO_ID" == "raspbian" && "$DISTRO_VERSION_ID" == "11" ]]; then
sudo apt-get update
sudo apt-get -y install \
udisks2 \
udiskie \
exfatprogs \
dosfstools
elif [[ "$DISTRO_ID" == "raspbian" && "$DISTRO_VERSION_ID" == "10" ]]; then
sudo apt-get update
sudo apt-get -y install \
udisks2 \
udiskie \
exfat-utils \
dosfstools
elif [[ "$DISTRO_ID" == "debian" && "$DISTRO_VERSION_ID" == "12" ]]; then
sudo apt-get update
sudo apt-get -y install \
udisks2 \
udiskie \
exfatprogs \
dosfstools
elif [[ "$DISTRO_ID" == "debian" && "$DISTRO_VERSION_ID" == "11" ]]; then
sudo apt-get update
sudo apt-get -y install \
udisks2 \
udiskie \
exfatprogs \
dosfstools
elif [[ "$DISTRO_ID" == "debian" && "$DISTRO_VERSION_ID" == "10" ]]; then
sudo apt-get update
sudo apt-get -y install \
udisks2 \
udiskie \
exfat-utils \
dosfstools
elif [[ "$DISTRO_ID" == "ubuntu" && "$DISTRO_VERSION_ID" == "24.04" ]]; then
sudo apt-get update
sudo apt-get -y install \
udisks2 \
udiskie \
exfatprogs \
dosfstools
elif [[ "$DISTRO_ID" == "ubuntu" && "$DISTRO_VERSION_ID" == "22.04" ]]; then
sudo apt-get update
sudo apt-get -y install \
udisks2 \
udiskie \
exfatprogs \
dosfstools
elif [[ "$DISTRO_ID" == "ubuntu" && "$DISTRO_VERSION_ID" == "20.04" ]]; then
sudo apt-get update
sudo apt-get -y install \
udisks2 \
udiskie \
exfat-utils \
dosfstools
else
echo "Unknown distribution $DISTRO_ID $DISTRO_VERSION_ID ($CPU_ARCH)"
exit 1
fi
# find script directory for service setup
SCRIPT_DIR=$(dirname "$0")
cd "$SCRIPT_DIR/.."
ALLSKY_DIRECTORY=$PWD
cd "$OLDPWD"
echo "**** Setup policy kit permissions ****"
TMP_POLKIT=$(mktemp)
if [ -d "/etc/polkit-1/rules.d" ]; then
sed \
-e "s|%ALLSKY_USER%|$USER|g" \
"${ALLSKY_DIRECTORY}/service/90-indi-allsky.rules" > "$TMP_POLKIT"
sudo cp -f "$TMP_POLKIT" "/etc/polkit-1/rules.d/90-indi-allsky.rules"
sudo chown root:root "/etc/polkit-1/rules.d/90-indi-allsky.rules"
sudo chmod 644 "/etc/polkit-1/rules.d/90-indi-allsky.rules"
# remove legacy config
if sudo test -f "/etc/polkit-1/localauthority/50-local.d/90-org.aaronwmorris.indi-allsky.pkla"; then
sudo rm -f "/etc/polkit-1/localauthority/50-local.d/90-org.aaronwmorris.indi-allsky.pkla"
fi
else
# legacy pkla
sed \
-e "s|%ALLSKY_USER%|$USER|g" \
"${ALLSKY_DIRECTORY}/service/90-org.aaronwmorris.indi-allsky.pkla" > "$TMP_POLKIT"
sudo cp -f "$TMP_POLKIT" "/etc/polkit-1/localauthority/50-local.d/90-org.aaronwmorris.indi-allsky.pkla"
sudo chown root:root "/etc/polkit-1/localauthority/50-local.d/90-org.aaronwmorris.indi-allsky.pkla"
sudo chmod 644 "/etc/polkit-1/localauthority/50-local.d/90-org.aaronwmorris.indi-allsky.pkla"
fi
[[ -f "$TMP_POLKIT" ]] && rm -f "$TMP_POLKIT"
# create users systemd folder
[[ ! -d "${HOME}/.config/systemd/user" ]] && mkdir -p "${HOME}/.config/systemd/user"
cp -f "${ALLSKY_DIRECTORY}/service/udiskie-automount.service" "${HOME}/.config/systemd/user/udiskie-automount.service"
chmod 644 "${HOME}/.config/systemd/user/udiskie-automount.service"
systemctl --user daemon-reload
systemctl --user enable udiskie-automount.service
systemctl --user start udiskie-automount.service
echo
echo "Please insert your USB media now"
echo
# shellcheck disable=SC2034
read -n1 -r -p "Press any key to continue..." anykey
# Allow web server access to mounted media
if [[ -d "/media/${USER}" ]]; then
sudo chmod ugo+x "/media/${USER}"
else
echo
echo
echo "Media not detected..."
echo "You may need to run this script again once you insert your media"
echo "for the correct access permissions for the web server"
echo
fi
echo
echo
echo "USB automounting is now enabled... enjoy"
echo
echo