Skip to content

Commit

Permalink
Fix testing
Browse files Browse the repository at this point in the history
  • Loading branch information
NeroReflex committed Jun 23, 2024
1 parent 5d6f560 commit 5fb28a7
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 57 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Fix files permission
run: |
chmod +x frzr* __frzr*
- name: Run tests
run: |
cd test
./run.sh
- name: Test Install
run: |
chmod +x test/*.sh
docker run -u root --rm --entrypoint=/workdir/test/test-install.sh -v $(pwd):/workdir -v /dev:/dev --privileged archlinux:latest
2 changes: 1 addition & 1 deletion __frzr
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ write_tracker_file() {
local running_user=$(whoami)
if [ ! -f "${TRACKER_FILE_PATH}" ]; then
touch "${TRACKER_FILE_PATH}"
chown :frzr "${TRACKER_FILE_PATH}"
chown $UID:379 "${TRACKER_FILE_PATH}"
chmod g+w "${TRACKER_FILE_PATH}"
fi

Expand Down
9 changes: 4 additions & 5 deletions __frzr-bootloader
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ frzr_bootloader() {
continue
fi

MOUNT_PATH="/frzr_root"
# Make sure the frzr_root is mounted during the deployment procedure
# this code is based on the fact that when a btrfs filesystem is created
# the default subvolid that is created contextually has the ID set to 256
# also as a matter of fact in btrfs is impossible to change subvolumes IDs
if mount | grep -Fq "${MOUNT_PATH}"; then
if mount | grep -Fq "on ${MOUNT_PATH}"; then
local MOUNTED_MOUNT_PATH="no"
else
MOUNT_PATH="/tmp/frzr_root"
Expand All @@ -58,9 +57,9 @@ frzr_bootloader() {
fi

# Make sure the EFI partition is mounted during the deployment procedure
EFI_MOUNT_PATH="${MOUNT_PATH}/efi"

if mount | grep -Fq "${EFI_MOUNT_PATH}"; then
TASK_MSG="Checking for EFI partition"
send_data
if mount | grep -Fq "on ${EFI_MOUNT_PATH}"; then
local MOUNTED_EFI_MOUNT_PATH="no"
else
mkdir -p "${EFI_MOUNT_PATH}"
Expand Down
39 changes: 25 additions & 14 deletions __frzr-bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -264,29 +264,40 @@ frzr_bootstrap() {

echo "Checking for drives connected to the system"
MOUNT_PATH=/tmp/frzr_root
device_list=()
device_output=$(lsblk --list -n -o name,model,size,type | grep disk | tr -s ' ' '\t')
while read -r line; do
name=/dev/$(echo "$line" | cut -f 1)
model=$(echo "$line" | cut -f 2)
size=$(echo "$line" | cut -f 3)
device_list+=($name)
device_list+=("$model ($size)")
done <<<"$device_output"
DISK=$(whiptail --nocancel --menu "Choose a disk to install to:" 20 50 5 "${device_list[@]}" 3>&1 1>&2 2>&3)
if [ -z "${DISK}" ]; then
device_list=()
device_output=$(lsblk --list -n -o name,model,size,type | grep disk | tr -s ' ' '\t')
while read -r line; do
name=/dev/$(echo "$line" | cut -f 1)
model=$(echo "$line" | cut -f 2)
size=$(echo "$line" | cut -f 3)
device_list+=($name)
device_list+=("$model ($size)")
done <<<"$device_output"
DISK=$(whiptail --nocancel --menu "Choose a disk to install to:" 20 50 5 "${device_list[@]}" 3>&1 1>&2 2>&3)
else
echo "specified disk is '$DISK'"
fi
echo "Checking for existing FRZR deployments"
# Checking for existing installation

if (lsblk -o label ${DISK} | grep -q frzr_efi); then
echo "Existing installation found"

if (whiptail --yesno --yes-button "Repair" --no-button "Clean" "WARNING: $DISK appears to already have a system installed. Would you like to repair it or do a clean install?\n\nNOTE: A clean install will delete everything on the disk, but a repair install will preserve your user data." 13 70); then
echo "User chose to do a repair install"
if [ "$REPAIR_INSTALL" = "1"]; then
REPAIR_INSTALL=1
STATE="REPAIR"
else
echo "User chose to do a clean install"
elif [ "$REPAIR_INSTALL" = "0"]; then
STATE="FORMAT"
else
if (whiptail --yesno --yes-button "Repair" --no-button "Clean" "WARNING: $DISK appears to already have a system installed. Would you like to repair it or do a clean install?\n\nNOTE: A clean install will delete everything on the disk, but a repair install will preserve your user data." 13 70); then
echo "User chose to do a repair install"
REPAIR_INSTALL=1
STATE="REPAIR"
else
echo "User chose to do a clean install"
STATE="FORMAT"
fi
fi
else
echo "Existing installation not found"
Expand Down
39 changes: 19 additions & 20 deletions __frzr-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ frzr_deploy() {
continue
fi

TASK_MSG="Checking if the system has booted via UEFI"
send_data
check_uefi_result=$(check_uefi)
if echo "${check_uefi_result}" | grep -Fq 'ERROR'; then
TASK_ERROR=1
TASK_ERROR_MSG="UEFI boot check failed: ${check_uefi_result}"
STATE="FAIL"
send_data
continue
fi
# Since this code is tested in GitHub CI it is important to to disable the UEFI test in that scenario
if [ -z "${SKIP_UEFI_CHECK}" ]; then
TASK_MSG="Checking if the system has booted via UEFI"
send_data
check_uefi_result=$(check_uefi)
if echo "${check_uefi_result}" | grep -Fq 'ERROR'; then
TASK_ERROR=1
TASK_ERROR_MSG="UEFI boot check failed: ${check_uefi_result}"
STATE="FAIL"
send_data
continue
fi
fi

# Check if any updates are available and preserve FRZR parameters
while (("$#")); do
Expand Down Expand Up @@ -75,8 +78,8 @@ frzr_deploy() {

# keep only the first param as source
FRZR_SOURCE="${FRZR_PARAMS%% *}"
if frzr-release > /dev/null; then
CURRENT=`frzr-release`
if "${BASH_SOURCE%/*}/frzr-release" > /dev/null; then
CURRENT=$("${BASH_SOURCE%/*}/frzr-release")
fi

STATE="BEGIN"
Expand All @@ -85,7 +88,7 @@ frzr_deploy() {
TASK_STATE="BEGIN"
send_data

local version=$(frzr-version)
local version=$("${BASH_SOURCE%/*}/frzr-version")
if echo "${version}" | grep -Fq "ERROR"; then
TASK_ERROR=1
TASK_ERROR_MSG="Could not fetch frzr version: ${version}"
Expand All @@ -98,8 +101,7 @@ frzr_deploy() {
# this code is based on the fact that when a btrfs filesystem is created
# the default subvolid that is created contextually has the ID set to 256
# also as a matter of fact in btrfs is impossible to change subvolumes IDs
MOUNT_PATH="/frzr_root"
if mount | grep -Fq "${MOUNT_PATH}"; then
if mount | grep -Fq "on ${MOUNT_PATH}"; then
local MOUNTED_MOUNT_PATH="no"
else
MOUNT_PATH="/tmp/frzr_root"
Expand Down Expand Up @@ -135,12 +137,9 @@ frzr_deploy() {
fi

# Make sure the EFI partition is mounted during the deployment procedure
EFI_MOUNT_PATH="${MOUNT_PATH}/efi"

TASK_MSG="Preparing '${EFI_MOUNT_PATH}' to be used as the EFI System path"
send_data

if mount | grep -Fq "${EFI_MOUNT_PATH}"; then
if mount | grep -Fq "on ${EFI_MOUNT_PATH}"; then
local MOUNTED_EFI_MOUNT_PATH="no"
else
mkdir -p "${EFI_MOUNT_PATH}"
Expand Down Expand Up @@ -489,7 +488,7 @@ frzr_deploy() {
send_data

# This is used to update the EFI partition: setting up systemd-boot (or whatever else bootlader might be supported) to boot the new deployment
local efi_update_result=$(frzr-bootloader "${NAME}")
local efi_update_result=$("${BASH_SOURCE%/*}/frzr-bootloader" "${NAME}")
if echo "${efi_update_result}" | grep -Fq 'ERROR'; then
# bootloader configuration could not be updated
TASK_ERROR=1
Expand Down
19 changes: 15 additions & 4 deletions __frzr-envars
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@ if [ -z $TARGET ]; then
TARGET="" # Set to the target deployment channel. This should only be set by the installer script
fi

if [ -z $LOCAL_INSTALL ]; then
if [ -z "$LOCAL_INSTALL" ]; then
LOCAL_INSTALL=0 # Set to 1 to perform a local media install. This should be set by the installer script
fi

UPGRADE=0
REPAIR_INSTALL=0 # Set to 1 if you want to do a repair install. This should be set by frzr-bootstrap later if an existing install is found.

if [ -z "$REPAIR_INSTALL" ]; then
REPAIR_INSTALL=0 # Set to 1 if you want to do a repair install. This should be set by frzr-bootstrap later if an existing install is found.
fi

NAME="" # Name of the OS to be deployed
EFI_MOUNT_PATH="" # EFI mount path
MOUNT_PATH="" # This is set as /tmp/frzr_root/ in the installer and /frzr_root during upgrades

if [ -z "$MOUNT_PATH" ]; then
MOUNT_PATH="/frzr_root" # This is set as /tmp/frzr_root/ in the installer and /frzr_root during upgrades
fi

if [ -z "$EFI_MOUNT_PATH" ]; then
EFI_MOUNT_PATH="${MOUNT_PATH}/efi" # EFI mount path
fi

SUBVOL=""
DEPLOY_PATH="" # ${MOUNT_PATH}/deployments
FRZR_CHECK_UPDATE=0
Expand Down
10 changes: 3 additions & 7 deletions __frzr-kernel
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ frzr_kernel() {
while $RUNNING; do
case "$STATE" in
"BEGIN")
MOUNT_PATH="/frzr_root"

# Make sure the frzr_root is mounted during the deployment procedure
# this code is based on the fact that when a btrfs filesystem is created
# the default subvolid that is created contextually has the ID set to 256
# also as a matter of fact in btrfs is impossible to change subvolumes IDs
if mount | grep -Fq "${MOUNT_PATH}"; then
if mount | grep -Fq "on ${MOUNT_PATH}"; then
local MOUNTED_MOUNT_PATH="no"
else
MOUNT_PATH="/tmp/frzr_root"
Expand All @@ -37,9 +35,7 @@ frzr_kernel() {
fi

# Make sure the EFI partition is mounted during the deployment procedure
EFI_MOUNT_PATH="${MOUNT_PATH}/efi"

if mount | grep -Fq "${EFI_MOUNT_PATH}"; then
if mount | grep -Fq "on ${EFI_MOUNT_PATH}"; then
local MOUNTED_EFI_MOUNT_PATH="no"
else
sudo mkdir -p "${EFI_MOUNT_PATH}"
Expand Down Expand Up @@ -371,7 +367,7 @@ frzr_kernel() {
fi

# This is used to update the EFI partition: setting up systemd-boot (or whatever else bootlader might be supported) to boot the new deployment
local efi_update_result=$(frzr-bootloader)
local efi_update_result=$("${BASH_SOURCE%/*}/frzr-bootloader")
if echo "${efi_update_result}" | grep -Fq 'ERROR'; then
# bootloader configuration could not be updated
TASK_ERROR=1
Expand Down
10 changes: 4 additions & 6 deletions __frzr-unlock
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ frzr_unlock() {
done

# keep only the first param as source
FRZR_SOURCE="${FRZR_PARAMS%% *}"
if frzr-release > /dev/null; then
CURRENT=`frzr-release`
fi
if "${BASH_SOURCE%/*}/frzr-release" > /dev/null; then
CURRENT=$("${BASH_SOURCE%/*}/frzr-release")
fi

STATE="BEGIN"
;;
"BEGIN")
FRZR_VERSION=$(frzr-version)
FRZR_VERSION=$("${BASH_SOURCE%/*}/frzr-version")
if echo "${FRZR_VERSION}" | grep -Fq "ERROR"; then
TASK_ERROR=1
TASK_ERROR_MSG="Could not fetch frzr version: ${FRZR_VERSION}"
Expand All @@ -73,7 +72,6 @@ frzr_unlock() {
# this code is based on the fact that when a btrfs filesystem is created
# the default subvolid that is created contextually has the ID set to 256
# also as a matter of fact in btrfs is impossible to change subvolumes IDs
MOUNT_PATH="/frzr_root"
if ! mountpoint -q "${MOUNT_PATH}" && ls -1 /dev/disk/by-label | grep frzr_root > /dev/null; then
MOUNT_PATH="/tmp/frzr_root"
#TASK_MSG="Preparing '${MOUNT_PATH}' to be used as the main subvolume mount path"
Expand Down
Empty file added output/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#! /bin/bash

set -e
set -x

source ../__frzr

check() {
Expand Down
56 changes: 56 additions & 0 deletions test/test-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#! /bin/bash

set -e
set -x

# Prepare the image
pacman -Sy --noconfirm
pacman -S --noconfirm archlinux-keyring
pacman-key --init
pacman-key --populate archlinux
pacman -Syu --noconfirm

pacman -S --noconfirm parted btrfs-progs file libnewt dosfstools jq util-linux zstd xz curl wget arch-install-scripts

# Create the frzr group
groupadd -g 379 frzr
usermod -a -G frzr $(whoami)

export FILENAME=image.img
export BUILD_DIR="/workdir/output"
export BUILD_IMG="$BUILD_DIR/$FILENAME"

mkdir -p "$BUILD_DIR"
dd if=/dev/zero of=$BUILD_IMG bs=1M count=8192

# Associate the image file with a loop device
losetup -fP "$BUILD_IMG"

# Find the loop device associated with the image file
MOUNTED_DEVICE=$(losetup -a | grep "$FILENAME" | cut -d ' ' -f 1 | sed 's/://')

export DISK="$MOUNTED_DEVICE"
export SWAP_GIB=0
bash /workdir/frzr bootstrap

export SKIP_UEFI_CHECK="yes"
export MOUNT_PATH="/tmp/frzr_root"
export EFI_MOUNT_PATH="/tmp/frzr_root/efi"
export FRZR_SKIP_CHECK="yes"
export SYSTEMD_RELAX_ESP_CHECKS=1

# deploy chimeraos-45-1_9a95912
bash /workdir/frzr deploy chimeraos/chimeraos:45_1

# old releases used an older frzr
INSTALLED_RELEASE=$(cat "$MOUNT_PATH/deployments/chimeraos-45-1_9a95912/build_info" | head -n 1)

# Umount the loopback device
losetup -d "$MOUNTED_DEVICE"

# Remove the file
rm -f $BUILD_IMG

if ! echo "$INSTALLED_RELEASE" | grep -Fq "chimeraos-45"; then
exit 1
fi

0 comments on commit 5fb28a7

Please sign in to comment.