-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild_base.sh
164 lines (127 loc) · 5.74 KB
/
build_base.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
#!/bin/bash
# Exit on error
# If something goes wrong just stop.
# it allows the user to see issues at once rather than having
# scroll back and figure out what went wrong.
set -e
# if $USER is different from "pi" (the default) rename "pi" to "$USER"
if [ "$USER" != "pi" ]; then
# 1. Change the username in /etc/passwd
echo "Renaming user in /etc/passwd..."
sed -i "s/^pi:/$USER:/g" "/etc/passwd"
# 2. Change the group name in /etc/group
echo "Renaming user in /etc/group..."
sed -i "s/\bpi\b/$USER/g" "/etc/group"
# 3. Rename the home directory from /home/pi to /home/newuser
echo "Renaming home directory..."
# replace "pi"" with "$USER" in /etc/passwd
sed -i "s|pi:|$USER:|g" "/etc/passwd"
mv "/home/pi" "/home/$USER"
# 4. Change ownership of the new home directory
echo "Updating file ownership..."
chown -R 1000:1000 "/home/$USER" # Replace 1000:1000 with the correct UID:GID if needed
# 5. Change the password in /etc/shadow
echo "Changing user password to $PASSWORD..."
NEW_HASHED_PASSWORD=$(openssl passwd -6 "$PASSWORD")
echo "hashed password: $NEW_HASHED_PASSWORD..."
sed -i "s#^pi:.*#$USER:$NEW_HASHED_PASSWORD:18720:0:99999:7:::#g" "/etc/shadow"
# 6. don't let raspbian force to change username on first boot
echo "Disabling first boot user setup wizard..."
echo "$USER:$NEW_HASHED_PASSWORD" > /boot/firmware/userconf.txt
chmod 600 /boot/firmware/userconf.txt
# 7. Add the new user to the sudo group
echo "Adding $USER to the sudo group..."
sed -i "/^sudo:/s/pi/$USER/" /etc/group
echo "User has been renamed, added to sudo group, and password updated."
fi
# Function to add user to group in /etc/group
add_user_to_group() {
local user=$1
local group=$2
if ! grep -q "^$group:" /etc/group; then
echo "Group $group doesn't exist"
return 1
fi
if ! grep -q "^$group:.*\b$user\b" /etc/group; then
echo "Adding $user to $group"
sed -i "/^$group:/s/$/,$user/" /etc/group
else
echo "$user is already in $group"
fi
}
echo "Adding $USER to the ovos group..."
# Create the 'ovos' group if it doesn't exist
if ! getent group ovos > /dev/null; then
groupadd ovos
fi
add_user_to_group $USER ovos
echo "Patching userconf to ensure 'ovos' group always exists..."
cp -v /mounted-github-repo/patches/userconf /usr/lib/userconf-pi/userconf
echo "Changing system hostname to $HOSTNAME..."
# Update /etc/hostname
echo "$HOSTNAME" > /etc/hostname
# Update /etc/hosts to reflect the new hostname
sed -i "s/127.0.1.1.*$/127.0.1.1\t$HOSTNAME/" /etc/hosts
echo "Enabling ssh..."
ln -s /etc/systemd/system/sshd.service /etc/systemd/system/multi-user.target.wants/
touch /boot/firmware/ssh
echo "Enabling autologin..."
# patch first bootscript to ensure autologin is enabled, otherwise OVOS doesnt launch!
cp -v /mounted-github-repo/patches/firstboot /usr/lib/raspberrypi-sys-mods/firstboot
mkdir -p /var/lib/userconf-pi/
touch /var/lib/userconf-pi/autologin
# Update package list and install necessary tools
echo "Updating base system..."
apt-get update
apt-get install -y --no-install-recommends jq git unzip curl build-essential fake-hwclock userconf-pi swig python3-dev python3-pip fbi libasound2-dev mosh dirmngr
# what else can be removed to make the system even lighter?
apt purge -y cups ppp
echo "Setting up libcamera..."
apt install -y python3-libcamera python3-kms++ libcap-dev
echo "Setting rfkill default value..."
cp -v /mounted-github-repo/tuning/rfkill_default.conf /etc/modprobe.d/rfkill_default.conf
echo "Installing uv and sdnotify..."
pip install sdnotify uv --break-system-packages
echo "Installing Pipewire..."
bash /mounted-github-repo/packages/setup_pipewire.sh
echo "Installing KDEConnect..."
bash /mounted-github-repo/packages/setup_kdeconnect.sh
echo "Installing Librespot..."
bash /mounted-github-repo/packages/setup_spotify.sh
echo "Installing upmpdcli for DLNA playback"
curl -o /etc/apt/sources.list.d/upmpdcli.list https://www.lesbonscomptes.com/upmpdcli/pages/upmpdcli-rbookworm.list
curl -o /usr/share/keyrings/lesbonscomptes.gpg https://www.lesbonscomptes.com/pages/lesbonscomptes.gpg
apt update && apt install -y upmpdcli mpd
cp -v /mounted-github-repo/tuning/mpd.conf /etc/mpd.conf
cp -v /mounted-github-repo/tuning/upmpdcli.conf /etc/upmpdcli.conf
ln -s /usr/lib/systemd/system/mpd.service /etc/systemd/system/multi-user.target.wants/mpd.service
#echo "Installing Balena Wifi-connect..."
#bash /mounted-github-repo/packages/setup_balena_wifi.sh
echo "Tuning base system..."
cp -v /mounted-github-repo/patches/boot_config.txt /boot/firmware/config.txt
#bash /mounted-github-repo/tuning/setup_ramdisk.sh
bash /mounted-github-repo/tuning/setup_zram.sh
#bash /mounted-github-repo/tuning/setup_cpugovernor.sh
bash /mounted-github-repo/tuning/setup_wlan0power.sh
bash /mounted-github-repo/tuning/setup_fstab.sh
bash /mounted-github-repo/tuning/setup_sysctl.sh
bash /mounted-github-repo/tuning/setup_udev.sh
bash /mounted-github-repo/tuning/setup_nmanager.sh
# make boot faster by printing less stuff and skipping file system checks
grep -q "quiet fastboot" /boot/firmware/cmdline.txt || sed -i 's/$/ quiet fastboot/' /boot/firmware/cmdline.txt
# support for mk1
sed -i 's/console=serial0,115200//g' /boot/firmware/cmdline.txt
echo "Ensuring permissions for $USER user..."
# Replace 1000:1000 with the correct UID:GID if needed
chown -R 1000:1000 /home/$USER
# Enable lingering for the user
echo "Enabling lingering for $USER user ..."
# Enable lingering by creating the directory
mkdir -p /var/lib/systemd/linger
# Create an empty file with the user's name
touch /var/lib/systemd/linger/$USER
# Ensure correct permissions
chown root:root /var/lib/systemd/linger/$USER
chmod 644 /var/lib/systemd/linger/$USER
echo "Cleaning up apt packages..."
apt-get --purge autoremove -y && apt-get clean