Creating script which runs on first startup only. This is used to copy /etc/skel files to first user's home directory.

This commit is contained in:
Roland 2024-06-18 16:17:54 -06:00
parent e18b1b0552
commit 336ef1abb4
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 33 additions and 2 deletions

View file

@ -0,0 +1,12 @@
[Unit]
Description=Run script at first startup
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/opt/wrolpi/wrolpi/scripts/first_startup.sh
RemainAfterExit=true
StandardOutput=journal
[Install]
WantedBy=multi-user.target

View file

@ -12,9 +12,7 @@ alias la='ll -a'
EOF
# Create WROLPi user. This user will own the media directory, API, and App.
# The `pi` user will be the maintainer's user.
useradd -md /home/wrolpi wrolpi -s "$(command -v bash)"
usermod -aG pi wrolpi
# Change default postgresql port to 5432.
sed -i 's/port = 5433/port = 5432/' /etc/postgresql/15/main/postgresql.conf
@ -50,6 +48,8 @@ chown wrolpi:wrolpi /media/wrolpi
cp /opt/wrolpi/etc/raspberrypios/wrolpi-*.service /etc/systemd/system/
cp /opt/wrolpi/etc/raspberrypios/wrolpi.target /etc/systemd/system/
# Enable first startup script.
systemctl enable wrolpi-first-startup.service
# NetworkManager for the hotspot.
systemctl enable NetworkManager

19
wrolpi/scripts/first_startup.sh Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env bash
# This script is run once on the first startup of a Raspberry Pi.
# Copy skeleton files to first users home directory.
USER_HOME=$(getent passwd 1000 | cut -d: -f6)
if [ "$(ls -A /etc/skel)" ]; then
echo "Files found in /etc/skel, copying to $USER_HOME..."
# Copy files from /etc/skel to the user's home directory
cp -r /etc/skel/. "$USER_HOME"
# Change ownership to the user with UID 1000
chown -R 1000:1000 "$USER_HOME"
echo "Files copied successfully."
else
echo "No files found in /etc/skel."
exit 1
fi
# Do not run this script again.
systemctl disable wrolpi-first-startup.service