Skip to content

Commit

Permalink
trying the firtboot script in the recipe-vm
Browse files Browse the repository at this point in the history
  • Loading branch information
Heus-Sueh committed Sep 3, 2024
1 parent 7c9d14b commit b6ca628
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
6 changes: 3 additions & 3 deletions files/scripts/firstboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ generate_hash() {
# Create a unique hash based on the current timestamp and a random number
local hash
hash=$(echo "$(date +%s) $RANDOM" | sha256sum | cut -d' ' -f1)
echo "Hash: $hash" >"$FIRSTBOOT_FILE"
echo "$hash" >"$FIRSTBOOT_FILE"
}

# Function to run modular commands and scripts
Expand All @@ -19,7 +19,7 @@ run_modules() {
# Example commands
echo "Setting up the environment..."
# Command to install packages, update the system, etc.
# sudo apt update && sudo apt upgrade -y
xdg-user-dirs-update

echo "Running theme setup script..."
# Example of running an external script
Expand All @@ -46,7 +46,7 @@ if [[ ! -f "$FIRSTBOOT_FILE" ]]; then

# Disable the systemd service after successful execution
echo "Disabling firstboot systemd service..."
sudo systemctl disable firstboot.service
systemctl disable firstboot.service

else
echo "First boot script has already run. Nothing to do."
Expand Down
53 changes: 53 additions & 0 deletions files/system/usr/bin/firstboot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail

# File to indicate that the script has already run
FIRSTBOOT_FILE="$HOME/.config/firstboot/firstboot_done"

# Function to generate a hash and write it to the firstboot file
generate_hash() {
# Create a unique hash based on the current timestamp and a random number
local hash
hash=$(echo "$(date +%s) $RANDOM" | sha256sum | cut -d' ' -f1)
echo "$hash" >"$FIRSTBOOT_FILE"
}

# Function to run modular commands and scripts
run_modules() {
# Add your commands and scripts here that you want to run on the first boot

# Example commands
echo "Setting up the environment..."
# Command to install packages, update the system, etc.
xdg-user-dirs-update

echo "Running theme setup script..."
# Example of running an external script
flatpak override --filesystem=xdg-data/themes
flatpak override --filesystem=xdg-data/icons
flatpak override --filesystem=xdg-config/gtk-3.0
flatpak override --filesystem=xdg-config/gtk-4.0
flatpak override --filesystem=xdg-config/Kvantum
# ./setup_theme.sh

echo "Initial setup completed!"
}

# Check if the script has already run
if [[ ! -f "$FIRSTBOOT_FILE" ]]; then
echo "First boot detected. Running setup script..."
run_modules

# Create the file to indicate that the script has run
touch "$FIRSTBOOT_FILE"

# Generate and store the hash in the firstboot file
generate_hash

# Disable the systemd service after successful execution
echo "Disabling firstboot systemd service..."
systemctl disable firstboot.service

else
echo "First boot script has already run. Nothing to do."
fi
8 changes: 8 additions & 0 deletions recipes/recipe-vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ modules:
- from-file: modules/vm.yml
- from-file: modules/common-scripts.yml
# ---------------------------------------------------------------------------------------------------------------------------
# Scripts
- type: script
snippets:
# - "mv example example2"
scripts:
# - example.sh
# ---------------------------------------------------------------------------------------------------------------------------
# SystemD
- type: systemd
system:
enabled:
- sddm-boot.service
- firstboot.service
# ----------------------------------------------------------------------------------------------------------------------------
# Signing
- type: signing # this sets up the proper policy & signing files for signed images to work fully
Expand Down

0 comments on commit b6ca628

Please sign in to comment.