-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirstrun.sh.cfg
121 lines (102 loc) · 3.27 KB
/
firstrun.sh.cfg
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
#!/bin/bash -e
#
# firstrun.sh
# Adapted from firstrun.sh that the RPi imager creates
# Adds locale generation which does not seem to be done.
#
# ERROR failed to start command from kernel command line discussed in
# https://hub.mender.io/t/walkthrough-for-raspberry-pi-4b-fails-to-boot/5405
#
# Env vars beginning with S_ will be updated by sed during image creation
#
# NOTE: Any errors here will result in Failed to start Command from Kernel Command Line error
#
###### Hostname (first boot will have default hostname so need to replace it)
CURRENT_HOSTNAME=`cat /etc/hostname | tr -d " \t\n\r"`
echo TARGET >/etc/hostname
sed -i "s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\tTARGET/g" /etc/hosts
###### Enable ssh
systemctl enable ssh
###### User configuration
FIRSTUSER=`getent passwd 1000 | cut -d: -f1`
FIRSTUSERHOME=`getent passwd 1000 | cut -d: -f6`
if [ -f /usr/lib/userconf-pi/userconf ]; then
# Seems 64-bit image contains this script to ensure a FIRSTUSER is set up
/usr/lib/userconf-pi/userconf 'S_USER' 'S_PWD'
else
# Not sure any of this matters...may not even work!
if [[ -z "${FIRSTUSER}" ]]; then
# No $FIRSTUSER with uid 1000 so create S_USER with group and home
useradd -u 1000 -g 1000 -n S_USER
else
if [[ "$FIRSTUSER" != "S_USER" ]]; then
# FIRSTUSER already exists and not S_USER so rename name, home, default group
usermod -l "S_USER" "$FIRSTUSER"
usermod -m -d "/home/S_USER" "S_USER"
groupmod -n "S_USER" "$FIRSTUSER"
else
# $FIRSTUSER exists and is already S_USER (very unlikely!), so nothing to do
:
fi
fi
# Update password
echo "S_USER:"'S_PWD' | chpasswd -e
# sudo
if [[ -f /etc/sudoers.d/010_pi-nopasswd ]]; then
# Was sudo so update name
sed -i "s/^$FIRSTUSER /S_USER /" /etc/sudoers.d/010_pi-nopasswd
else
# Was not sudo so make it so
usermod -aG sudo S_USER
fi
fi
###### WiFi
cat > /etc/wpa_supplicant/wpa_supplicant.conf <<'WPAEOF'
country=S_WIFICOUNTRY
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
ap_scan=1
update_config=1
network={
ssid="S_SSID"
psk=S_PSK
}
WPAEOF
chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf
rfkill unblock wifi
for filename in /var/lib/systemd/rfkill/*:wlan ; do
echo 0 > $filename
done
###### Locale--jln added
# Locale from original RPi imager results in errors, this has been debugged
# from /use/bin/raspi-config (script)
LOCALE_LINE=S_LOCALE_LINE
export LC_ALL=C
export LANG=C
#LG="/etc/locale.gen"
NEW_LANG="$(echo ${LOCALE_LINE} | cut -f1 -d " ")"
echo "${LOCALE_LINE}" > /etc/locale.gen
update-locale --no-checks LANG
update-locale --no-checks "LANG=${NEW_LANG}"
dpkg-reconfigure -f noninteractive locales
##### Timezone
rm -f /etc/localtime
echo "S_TZ" >/etc/timezone
dpkg-reconfigure -f noninteractive tzdata
###### Keyboard
# In original RPi imager has errors
# Error: /usr/bin/ckbcomp: Can not find file "symbols/US" in any known directory (journalcrl -xe)
# Setting XBKLAYOUT="us" (lowercase) seems to fix
# Do this after setting locale above!
cat >/etc/default/keyboard <<'KBEOF'
XKBMODEL="pc105"
XKBLAYOUT=S_KBSYMBOLS
XKBVARIANT=""
XKBOPTIONS=""
KBEOF
dpkg-reconfigure -f noninteractive keyboard-configuration
###### Clean up
# firstrun.sh contains secrets so delete
rm -f /boot/firstrun.sh
# Remove systemd commands that execute firstrun.sh
sed -i 's| systemd.run.*||g' /boot/cmdline.txt
exit 0