-
Notifications
You must be signed in to change notification settings - Fork 20
/
update_local.sh
executable file
·129 lines (103 loc) · 4.43 KB
/
update_local.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
#!/usr/bin/env bash
# update scripts and service files on a locally attached device
# will not overwrite any existing buttons_settings.py or chromium_settings.sh
# will not overwrite xorg.conf
# will not overwrite vnc_passwd
# this is intended to run on the host device, and expects key-based ssh authentication has already been setup with superbird
set -e
# all config lives in image_config.sh
source ./image_config.sh
#### Functions
deploy_service() {
# copy given service file and restart that service
SVC_NAME="$1"
echo "deploying $SVC_NAME"
ssh "${USER_NAME}@${HOST_NAME}" "sudo touch /lib/systemd/system/$SVC_NAME"
ssh "${USER_NAME}@${HOST_NAME}" "sudo chown ${USER_NAME} /lib/systemd/system/$SVC_NAME"
scp "./files/data/lib/systemd/system/$SVC_NAME" "${USER_NAME}@${HOST_NAME}":/lib/systemd/system/
ssh "${USER_NAME}@${HOST_NAME}" "sudo systemctl restart $SVC_NAME" >/dev/null 2>&1
ssh "${USER_NAME}@${HOST_NAME}" "sudo ln -sf /lib/systemd/system/$SVC_NAME /etc/systemd/system/multi-user.target.wants/$SVC_NAME"
}
deploy_script() {
# copy given script file
# does not change file mode, presumes new file is correct mode already
SCR_NAME="$1"
scp "./files/data/scripts/$SCR_NAME" "${USER_NAME}@${HOST_NAME}":/scripts/
}
deploy_script_if_missing() {
# deploy script only if it is missing
# does not change file mode, presumes new file is correct mode already
SCR_NAME="$1"
SCR_MISSING=$(ssh "${USER_NAME}@${HOST_NAME}" "if [ ! -f /scripts/$SCR_NAME ]; then echo missing; fi")
if [ "$SCR_MISSING" == "missing" ]; then
deploy_script "$SCR_NAME"
fi
}
#### Entrypoint
echo ""
echo "Upgrading locally connected device"
echo ""
echo "Installing packages"
# install packages, most of which should already be installed
ssh "${USER_NAME}@${HOST_NAME}" "sudo apt update && sudo apt install -y --no-install-recommends --no-install-suggests chromium python3-minimal python3-pip tigervnc-scraping-server"
# install required python packages via pip
ssh "${USER_NAME}@${HOST_NAME}" "sudo chown -R ${USER_NAME} /scripts"
deploy_script requirements.txt
ssh "${USER_NAME}@${HOST_NAME}" "sudo python3 -m pip install -r /scripts/requirements.txt --break-system-packages"
echo ""
echo "Deploying scripts and services"
# Now deploy scripts and services
# deploy inittab and fstab
scp "./files/data/etc/inittab" "${USER_NAME}@${HOST_NAME}":/tmp/inittab
ssh "${USER_NAME}@${HOST_NAME}" "sudo mv /tmp/inittab /etc/inittab"
scp "./files/data/etc/fstab" "${USER_NAME}@${HOST_NAME}":/tmp/fstab
ssh "${USER_NAME}@${HOST_NAME}" "sudo mv /tmp/fstab /etc/fstab"
# check if /dev/settings is mounted, if not then format settings, and mount it (restart chromium)
CFG_MISSING=$(ssh "${USER_NAME}@${HOST_NAME}" " mount |grep -q /dev/settings || echo missing")
if [ "$CFG_MISSING" == "missing" ]; then
echo "Migrating chromium profile at /config to use settings partition"
ssh "${USER_NAME}@${HOST_NAME}" "sudo systemctl stop chromium" # dont need to start it, will get restarted when re-deployed later
ssh "${USER_NAME}@${HOST_NAME}" "sudo umount /config" # just in case
ssh "${USER_NAME}@${HOST_NAME}" "sudo rm -r /config"
ssh "${USER_NAME}@${HOST_NAME}" "sudo mkfs.ext4 -F /dev/settings"
ssh "${USER_NAME}@${HOST_NAME}" "sudo mkdir /config"
ssh "${USER_NAME}@${HOST_NAME}" "sudo mount /config"
fi
deploy_script_if_missing buttons_settings.py
deploy_script_if_missing chromium_settings.sh
deploy_script_if_missing vnc_passwd
deploy_script buttons_app.py
deploy_script clear_display.sh
deploy_script setup_backlight.sh
deploy_script setup_display.sh
deploy_script setup_usbgadget.sh
deploy_script setup_vnc.sh
deploy_script start_buttons.sh
deploy_script start_chromium.sh
echo ""
echo "Deploying services, You can ignore the warnings about reloading units"
echo ""
deploy_service backlight.service
deploy_service buttons.service
deploy_service chromium.service
deploy_service vnc.service
echo "Generating /etc/hosts"
HOSTS_CONTENT=$(
cat <<- EOHF
# generated by $0
127.0.0.1 localhost
127.0.0.1 $HOST_NAME
::1 localhost $HOST_NAME ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
${USBNET_PREFIX}.1 host
EOHF
)
echo "$HOSTS_CONTENT" > /tmp/hosts
scp /tmp/hosts "${USER_NAME}@${HOST_NAME}":/tmp/hosts
ssh "${USER_NAME}@${HOST_NAME}" "sudo cp /tmp/hosts /etc/hosts"
rm /tmp/hosts
deploy_service usbgadget.service
echo ""
echo "Done deploying to device"
echo ""