-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-stage2
executable file
·107 lines (101 loc) · 2.74 KB
/
install-stage2
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
#!/bin/bash
echo "Rembember to install devicetree overlay. See uEnv.txt (Insert uboot_overlay_addr0=BB-UART4-00A0.dtbo)"
set -e # Halt on error
#set -x # bash Debug setting
USER=debian
run_cmd() {
if $@ #1>/dev/null 2>&1
then
return 0
else
echo "ERROR: running command $@"
exit 1
fi
}
perror() {
printf "ERROR: %s\n" "$*" >&2
}
if [ $EUID -ne 0 ]
then
echo -e "ERROR: You need root credentials to run this script"
exit
fi
echo "Preparing Beagleboard black"
echo "Prepared for: Debian GNU/Linux 12 (bookworm)"
if [ `lsb_release -rs 2>/dev/null` -ne 12 ]
then
echo "WARNING: You are installing on GNU/Linux `lsb_release -rs 2>/dev/null`"
sleep 5
fi
echo "Checking if DK locale settings installed"
if ! grep -q 'da_DK.utf8' - <<< $(locale -a)
then
LOCALE="da_DK.utf8"
echo "Installing support for $LOCALE"
sed -i 's!# da_DK.UTF-8 UTF-8!da_DK.UTF-8 UTF-8!' /etc/locale.gen
locale-gen
fi
TZ="Europe/Copenhagen"
echo "Checking timezone is $TZ"
if ! grep -q $TZ - <<< $(timedatectl)
then
echo "Setting timezone to $TZ"
run_cmd timedatectl set-timezone $TZ
fi
echo "Creating Users"
DAEMON="mbus"
if ! grep $DAEMON /etc/passwd
then
sudo adduser --disabled-login --no-create-home --system --group --comment "M-bus user" $DAEMON
groupmod --append --users $DAEMON dialout # Permission to use serial lines
groupmod --append --users $DAEMON systemd-journal
groupmod --append --users $DAEMON i2c
groupmod --append --users $DAEMON gpio
fi
echo -en "Cheking if nats-server installed.....: "
if ! systemctl status nats-server > /dev/null 2>&1
then
echo -e "[Not installed]\nInstalling"
apt -y install nats-server
else
echo -e "[Installed]"
fi
echo -en "Cheking if mosquitto clients is installed.....: "
if ! which mosquitto_sub > /dev/null 2>&1
then
echo -e "[Not installed]\nInstalling"
apt -y install mosquitto-clients
else
echo -e "[Installed]"
fi
echo -en "Cheking if nats-client installed.....: "
if ! nats >/dev/null 2>&1
then
echo -e "[Not installed]\nInstalling"
wget https://github.com/nats-io/natscli/releases/download/v0.1.5/nats-0.1.5-arm7.deb
apt -y install ./nats-0.1.5-arm7.deb
else
echo -e "[Installed]"
fi
echo -en "Cheking if UART4 device tree installed.....: "
UART4OVERLAY="BB-UART4-00A0.dtbo"
if ! grep -q $UART4OVERLAY /boot/uEnv.txt
then
echo -e "[Not installed]\nInstalling"
UBOOTVAR="uboot_overlay_addr0"
OVERLAYFILE="/boot/dtbs/$(uname -r)/overlays/${UART4OVERLAY}"
if test ! -f $OVERLAYFILE
then
perror "Missing device tree overlay: $OVERLAYFILE"
echo "Fuck"
exit 1
fi
sed -i "s!#${UBOOTVAR}=<file0>.dtbo!${UBOOTVAR}=${OVERLAYFILE}!" /boot/uEnv.txt
if ! grep -q $UART4OVERLAY /boot/uEnv.txt
then
perror "Substitution failed in file /boot/uEnv.txt setting: ${UBOOTVAR}=${OVERLAYFILE}"
exit
fi
else
echo -e "[Installed]"
fi