Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 27, 2024
1 parent 476a249 commit 4b713d6
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 75 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_img.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: build headless image

on:
push:
workflow_dispatch:

jobs:
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: test build no-OVOS headless image

on:
push:
workflow_dispatch:

jobs:
modify-rpi-image:
runs-on: ubuntu-latest
steps:
-
name: Checkout repository
uses: actions/checkout@v4
-
name: Add OVOS to Raspberry Pi OS Bookworm
uses: dtcooper/rpi-image-modifier@v1
id: create-image
env:
USER: 'ovos'
PASSWORD: 'ovos'
HOSTNAME: "raspOVOS"
with:
base-image-url: https://downloads.raspberrypi.com/raspios_lite_arm64/images/raspios_lite_arm64-2024-11-19/2024-11-19-raspios-bookworm-arm64-lite.img.xz
image-path: raspOVOS-NO-OVOS-bookworm-arm64-lite.img
compress-with-xz: true
cache: true
mount-repository: true
env-vars: USER,PASSWORD
script-path: build_base.sh
-
name: Print outputs
shell: bash
run: |
echo 'image-path: ${{ steps.create-image.outputs.image-path }}'
echo 'image-size: ${{ steps.create-image.outputs.image-size }}'
echo 'image-sha256sum: ${{ steps.create-image.outputs.image-sha256sum }}'
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: raspOVOS-NO-OVOS-bookworm-arm64-lite-${{ github.run_id }}
release_name: raspOVOS-NO-OVOS-bookworm-arm64-lite-${{ github.run_id }}
body: |
testing base OS setup only
draft: true
prerelease: false
-
name: Upload to releases
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
file: ${{ steps.create-image.outputs.image-path }}
release_id: ${{ steps.create_release.outputs.id }}
draft: true
overwrite: true
prerelease: true
verbose: true
92 changes: 92 additions & 0 deletions build_base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/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/^pi:/^$USER:/g" "/etc/group"

# 3. Rename the home directory from /home/pi to /home/newuser
echo "Renaming home directory..."
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

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..."
touch /boot/firmware/ssh

# Update package list and install necessary tools
echo "Updating base system..."
apt-get update
apt-get install -y --no-install-recommends git unzip curl build-essential

echo "Installing Pipewire..."
bash /mounted-github-repo/setup_pipewire.sh

echo "Tuning base system..."
cp -v /mounted-github-repo/boot_config.txt /boot/firmware/config.txt
bash /mounted-github-repo/setup_ramdisk.sh
bash /mounted-github-repo/setup_zram.sh
bash /mounted-github-repo/setup_cpugovernor.sh
bash /mounted-github-repo/setup_wlan0power.sh
bash /mounted-github-repo/setup_fstab.sh
bash /mounted-github-repo/setup_sysctl.sh
bash /mounted-github-repo/setup_udev.sh
bash /mounted-github-repo/setup_kernel_modules.sh
bash /mounted-github-repo/setup_nmanager.sh
# make boot faster by printing less stuff and skipping file system checks
grep -q "quiet fastboot" /boot/cmdline.txt || sed -i 's/$/ quiet fastboot/' /boot/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
78 changes: 3 additions & 75 deletions build_raspOVOS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,18 @@
# 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/^pi:/^$USER:/g" "/etc/group"

# 3. Rename the home directory from /home/pi to /home/newuser
echo "Renaming home directory..."
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

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..."
touch /boot/firmware/ssh
bash /mounted-github-repo/build_base.sh

# Update package list and install necessary tools
echo "Updating base system..."
apt-get update
apt-get install -y --no-install-recommends git unzip curl i2c-tools fbi swig mpv libssl-dev libfann-dev portaudio19-dev libpulse-dev build-essential python3-dev python3-pip

echo "Installing Pipewire..."
bash /mounted-github-repo/setup_pipewire.sh
echo "Installing system packages..."
apt-get install -y --no-install-recommends i2c-tools fbi swig mpv libssl-dev libfann-dev portaudio19-dev libpulse-dev python3-dev python3-pip

echo "Installing KDEConnect..."
apt-get install -y --no-install-recommends kdeconnect
cp -v /mounted-github-repo/kdeconnect.service /etc/systemd/system/kdeconnect.service
chmod 644 /etc/systemd/system/kdeconnect.service
ln -s /etc/systemd/system/kdeconnect.service /etc/systemd/system/multi-user.target.wants/kdeconnect.service

echo "Tuning base system..."
cp -v /mounted-github-repo/boot_config.txt /boot/firmware/config.txt
bash /mounted-github-repo/setup_ramdisk.sh
bash /mounted-github-repo/setup_zram.sh
bash /mounted-github-repo/setup_cpugovernor.sh
bash /mounted-github-repo/setup_wlan0power.sh
bash /mounted-github-repo/setup_fstab.sh
bash /mounted-github-repo/setup_sysctl.sh
bash /mounted-github-repo/setup_udev.sh
bash /mounted-github-repo/setup_kernel_modules.sh
bash /mounted-github-repo/setup_nmanager.sh

# splashscreen
echo "Creating OVOS splashscreen..."
mkdir -p /opt/ovos
Expand Down Expand Up @@ -210,17 +150,5 @@ 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

0 comments on commit 4b713d6

Please sign in to comment.