-
-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
227 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#!/bin/bash | ||
# Created by MichaIng / [email protected] / dietpi.com | ||
{ | ||
########################################## | ||
# Load DietPi-Globals | ||
########################################## | ||
Error_Exit(){ G_DIETPI-NOTIFY 1 "$1"; exit 1; } | ||
if [[ -f '/boot/dietpi/func/dietpi-globals' ]] | ||
then | ||
. /boot/dietpi/func/dietpi-globals | ||
else | ||
curl -sSf "https://raw.githubusercontent.com/${G_GITOWNER:=MichaIng}/DietPi/${G_GITBRANCH:=master}/dietpi/func/dietpi-globals" -o /tmp/dietpi-globals || exit 1 | ||
# shellcheck disable=SC1091 | ||
. /tmp/dietpi-globals | ||
G_EXEC_NOHALT=1 G_EXEC rm /tmp/dietpi-globals | ||
export G_GITOWNER G_GITBRANCH G_HW_ARCH_NAME=$(uname -m) | ||
fi | ||
case $G_HW_ARCH_NAME in | ||
'armv6l') export G_HW_ARCH=1;; | ||
'armv7l') export G_HW_ARCH=2;; | ||
'aarch64') export G_HW_ARCH=3;; | ||
'x86_64') export G_HW_ARCH=10;; | ||
'riscv64') export G_HW_ARCH=11;; | ||
*) Error_Exit "Unsupported host system architecture \"$G_HW_ARCH_NAME\" detected, aborting ...";; | ||
esac | ||
readonly G_PROGRAM_NAME='DietPi-Software build' | ||
G_CHECK_ROOT_USER | ||
G_CHECK_ROOTFS_RW | ||
readonly FP_ORIGIN=$PWD # Store origin dir | ||
G_INIT | ||
G_EXEC cd "$FP_ORIGIN" # Process everything in origin dir instead of /tmp/$G_PROGRAM_NAME | ||
|
||
########################################## | ||
# Process inputs | ||
########################################## | ||
NAME= | ||
DISTRO= | ||
ARCH= | ||
while (( $# )) | ||
do | ||
case $1 in | ||
'-n') shift; NAME=$1;; | ||
'-d') shift; DISTRO=$1;; | ||
'-a') shift; ARCH=$1;; | ||
*) Error_Exit "Invalid input \"$1\", aborting ...";; | ||
esac | ||
shift | ||
done | ||
[[ $NAME =~ ^('gmediarender'|'gogs'|'shairport-sync'|'squeezelite'|'vaultwarden'|'ympd')$ ]] || Error_Exit "Invalid software title \"$NAME\" passed, aborting ..." | ||
[[ $DISTRO =~ ^('buster'|'bullseye'|'bookworm'|'trixie')$ ]] || Error_Exit "Invalid distro \"$DISTRO\" passed, aborting ..." | ||
case $ARCH in | ||
'armv6l') image="ARMv6-${DISTRO^}" arch=1;; | ||
'armv7l') image="ARMv7-${DISTRO^}" arch=2;; | ||
'aarch64') image="ARMv8-${DISTRO^}" arch=3;; | ||
'x86_64') image="x86_64-${DISTRO^}" arch=10;; | ||
'riscv64') image='RISC-V-Sid' arch=11; [[ $DISTRO == 'trixie' ]] || Error_Exit "Invalid distro \"$DISTRO\" for arch \"$ARCH\" passed, only \"trixie\" is supported, aborting ...";; | ||
*) Error_Exit "Invalid architecture \"$ARCH\" passed, aborting ...";; | ||
esac | ||
image="DietPi_Container-$image.img" | ||
|
||
########################################## | ||
# Dependencies | ||
########################################## | ||
apackages=('xz-utils' 'parted' 'fdisk' 'systemd-container') | ||
(( $G_HW_ARCH == $arch || ( $G_HW_ARCH < 10 && $G_HW_ARCH > $arch ) )) || apackages+=('qemu-user-static' 'binfmt-support') | ||
G_AG_CHECK_INSTALL_PREREQ "${apackages[@]}" | ||
|
||
########################################## | ||
# Prepare container | ||
########################################## | ||
# Download | ||
G_EXEC curl -sSfO "https://dietpi.com/downloads/images/$image.xz" | ||
G_EXEC xz -d "$image.xz" | ||
G_EXEC truncate -s 8G "$image" | ||
|
||
# Mount as loop device | ||
FP_LOOP=$(losetup -f) | ||
G_EXEC losetup "$FP_LOOP" "$image" | ||
G_EXEC partprobe "$FP_LOOP" | ||
G_EXEC partx -u "$FP_LOOP" | ||
G_EXEC_OUTPUT=1 G_EXEC e2fsck -fp "${FP_LOOP}p1" | ||
G_EXEC_OUTPUT=1 G_EXEC eval "sfdisk -fN1 '$FP_LOOP' <<< ',+'" | ||
G_EXEC partprobe "$FP_LOOP" | ||
G_EXEC partx -u "$FP_LOOP" | ||
G_EXEC_OUTPUT=1 G_EXEC resize2fs "${FP_LOOP}p1" | ||
G_EXEC_OUTPUT=1 G_EXEC e2fsck -fp "${FP_LOOP}p1" | ||
G_EXEC mkdir rootfs | ||
G_EXEC mount "${FP_LOOP}p1" rootfs | ||
|
||
# Enforce ARMv6 arch on Raspbian | ||
(( $arch > 1 )) || echo 'sed -i -e '\''/^G_HW_ARCH=/c\G_HW_ARCH=1'\'' -e '\''/^G_HW_ARCH_NAME=/c\G_HW_ARCH_NAME=armv6l'\'' /boot/dietpi/.hw_model' > rootfs/boot/Automation_Custom_PreScript.sh || Error_Exit 'Failed to generate Automation_Custom_PreScript.sh' | ||
|
||
# Enable automated setup | ||
G_CONFIG_INJECT 'AUTO_SETUP_AUTOMATED=' 'AUTO_SETUP_AUTOMATED=1' rootfs/boot/dietpi.txt | ||
|
||
# Workaround invalid TERM on login | ||
# shellcheck disable=SC2016 | ||
G_EXEC eval 'echo '\''infocmp "$TERM" > /dev/null 2>&1 || { echo "[ WARN ] Unsupported TERM=\"$TERM\", switching to TERM=\"dumb\""; export TERM=dumb; }'\'' > rootfs/etc/bashrc.d/00-dietpi-build.sh' | ||
|
||
# Workaround for failing IPv4 network connectivity check as GitHub Actions runners do not receive external ICMP echo replies | ||
G_CONFIG_INJECT 'CONFIG_CHECK_CONNECTION_IP=' 'CONFIG_CHECK_CONNECTION_IP=127.0.0.1' rootfs/boot/dietpi.txt | ||
|
||
# Avoid DietPi-Survey uploads to not mess with the statistics | ||
G_EXEC rm rootfs/root/.ssh/known_hosts | ||
|
||
# Automated build | ||
cat << _EOF_ > rootfs/boot/Automation_Custom_Script.sh || Error_Exit 'Failed to generate Automation_Custom_Script.sh' | ||
#!/bin/dash | ||
echo '[ INFO ] Running $NAME build script ...' | ||
bash -c "\$(curl -sSf 'https://raw.githubusercontent.com/$G_GITOWNER/DietPi/$G_GITBRANCH/.build/software/$NAME/build.bash')" | ||
mv -v /tmp/*.deb / | ||
poweroff | ||
_EOF_ | ||
|
||
########################################## | ||
# Boot container | ||
########################################## | ||
systemd-nspawn -bD rootfs | ||
[[ -f rootfs/$NAME_$ARCH.deb ]] || Error_Exit "Failed to build package: $NAME_$ARCH.deb" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
name: DietPi-Software build | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
name: | ||
description: 'Software title' | ||
type: choice | ||
options: [gmediarender, gogs, shairport-sync, squeezelite, vaultwarden, ympd, all] | ||
default: all | ||
required: true | ||
arch: | ||
description: 'Target architecture' | ||
type: choice | ||
options: [armv6l, armv7l, aarch64, x86_64, riscv64, all] | ||
default: all | ||
required: true | ||
dist: | ||
description: 'Target Debian version' | ||
type: choice | ||
options: [buster, bullseye, bookworm, trixie, all] | ||
default: all | ||
required: true | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.inputs.name }}-${{ github.event.inputs.arch }}-${{ github.event.inputs.dist }} | ||
cancel-in-progress: true | ||
permissions: {} | ||
defaults: | ||
run: | ||
shell: sh | ||
working-directory: /dev/shm | ||
jobs: | ||
prep: | ||
outputs: | ||
name: ${{ steps.name.outputs.name }} | ||
arch: ${{ steps.arch.outputs.arch }} | ||
dist: ${{ steps.dist.outputs.dist }} | ||
# https://github.com/actions/runner-images | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- id: name | ||
run: | | ||
if [ '${{ github.event.inputs.name }}' = 'all' ] | ||
then | ||
echo 'name=["gmediarender", "gogs", "shairport-sync", squeezelite", "vaultwarden", "ympd"]' >> "$GITHUB_OUTPUT" | ||
else | ||
echo 'name=["${{ github.event.inputs.name }}"]' >> "$GITHUB_OUTPUT" | ||
fi | ||
- id: arch | ||
run: | | ||
if [ '${{ github.event.inputs.arch }}' = 'all' ] | ||
then | ||
echo 'arch=["armv6l", "armv7l", "aarch64", "x86_64"]' >> "$GITHUB_OUTPUT" | ||
else | ||
echo 'arch=["${{ github.event.inputs.arch }}"]' >> "$GITHUB_OUTPUT" | ||
fi | ||
- id: dist | ||
run: | | ||
if [ '${{ github.event.inputs.dist }}' = 'all' ] | ||
then | ||
echo 'dist=["buster", "bullseye", "bookworm", "trixie"]' >> "$GITHUB_OUTPUT" | ||
else | ||
echo 'dist=["${{ github.event.inputs.dist }}"]' >> "$GITHUB_OUTPUT" | ||
fi | ||
build: | ||
needs: prep | ||
strategy: | ||
matrix: | ||
name: ${{ fromJson(needs.prep.outputs.name) }} | ||
arch: ${{ fromJson(needs.prep.outputs.arch) }} | ||
dist: ${{ fromJson(needs.prep.outputs.dist) }} | ||
exclude: | ||
- { arch: riscv64, dist: buster } | ||
- { arch: riscv64, dist: bullseye } | ||
- { arch: riscv64, dist: bookworm } | ||
fail-fast: false | ||
name: "${{ matrix.name }} - ${{ matrix.arch }} - ${{ matrix.dist }}" | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Build | ||
run: sudo bash -c "G_GITOWNER=$GITHUB_REPOSITORY_OWNER G_GITBRANCH=$GITHUB_REF_NAME; $(curl -sSf "https://raw.githubusercontent.com/$GITHUB_REPOSITORY_OWNER/DietPi/$GITHUB_REF_NAME/.build/software/dietpi-software-build.bash")" -- -n '${{ matrix.name }}' -a '${{ matrix.arch }}' -d '${{ matrix.dist }}' | ||
- name: Upload | ||
run: | | ||
# SSH server and client keys | ||
mkdir ~/.ssh | ||
umask 377 | ||
echo '${{ secrets.KNOWN_HOSTS }}' > ~/.ssh/known_hosts | ||
echo '${{ secrets.SSH_KEY }}' > ~/.ssh/id_ed25519 | ||
# Generate file lists | ||
files= | ||
urls='"https://dietpi.com/downloads/binaries/${{ matrix.dist }}/testing/"' | ||
cd rootfs | ||
for i in *.deb | ||
do | ||
files="$files,$i" | ||
urls="$urls,\"https://dietpi.com/downloads/binaries/${{ matrix.dist }}/testing/$i\"" | ||
done | ||
files=${files#,} | ||
echo "Uploading file(s) $files to URL(s) $urls ..." | ||
# Upload | ||
curl -T "{$files}" --key ~/.ssh/id_ed25519 '${{ secrets.UPLOAD_URL }}${{ matrix.dist }}/' | ||
curl 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE }}/purge_cache' -H 'Authorization: Bearer ${{ secrets.CF_TOKEN }}' -H 'Content-Type: application/json' --data "{\"files\":[$urls]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters