-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall-rpi-script.sh
executable file
·61 lines (45 loc) · 1.11 KB
/
install-rpi-script.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
#!/bin/bash
if [ -z "$1" ]; then
echo "Format: $0 <path_to_root_rpi_filesystem_sdcard>"
exit 1
fi
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 2
fi
if [ ! -d "$1" ]; then
echo "Directory not exists: -$1-"
exit 3
fi
for dir in \
"$1/etc/systemd/system/multi-user.target.wants" \
"$1/lib/systemd/system" \
"$1/opt"
do
if [ ! -d "$dir" ]; then
echo "The target directory does not appear to be a root Raspberry Pi OS: -$dir-"
exit 3
fi
done
cp rpi-do-on-start.sh $1/opt
cd $1
cat > lib/systemd/system/rpi-do-on-start.service << EOL
[Unit]
Description=RPI Unattended Install on Startup
[Service]
ExecStart=/opt/rpi-do-on-start-launcher.sh
Type=idle
[Install]
WantedBy=multi-user.target
EOL
ln -s /lib/systemd/system/rpi-do-on-start.service etc/systemd/system/multi-user.target.wants
cat > opt/rpi-do-on-start-launcher.sh << EOL
#!/bin/bash
systemctl disable rpi-do-on-start.service
rm /lib/systemd/system/rpi-do-on-start.service
/opt/rpi-do-on-start.sh
rm /opt/rpi-do-on-start-launcher.sh
rm /opt/rpi-do-on-start.sh
EOL
chmod +x opt/rpi-do-on-start-launcher.sh
chmod +x opt/rpi-do-on-start.sh