Merge pull request #1839 from nextcloud/feature/armbian-next-support

Feature/armbian next support
This commit is contained in:
Tobias Knöppler 2023-10-18 23:23:06 +02:00 committed by GitHub
commit 50c09041dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 122 additions and 46 deletions

View File

@ -64,7 +64,6 @@ jobs:
continue-on-error: true
run: |
set -ex
export LIB_TAG=master
export IMG="NextCloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
[[ "${{ github.ref_protected }}" == true ]] || export DBG=x
@ -83,7 +82,6 @@ jobs:
echo -e "${LOG_CICD} Cleanup armbian build leftovers..."
sudo rm -rf armbian/ tmp/ output/
export LIB_TAG=master
export IMG="NextCloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
[[ "${{ github.ref_protected }}" == true ]] || export DBG=x
@ -179,6 +177,9 @@ jobs:
sudo rm -rf raspbian_root
. ./build/buildlib.sh
mount_raspbian "ncp.img"
[[ -f raspbian_root/etc/machine-id ]] || sudo systemd-id128 new > ./raspbian_root/etc/machine-id
sudo cat raspbian_root/etc/machine-id
sudo systemd-id128 new | sudo tee ./raspbian_root/etc/machine-id
sudo wget -nv https://github.com/multiarch/qemu-user-static/releases/latest/download/qemu-aarch64-static -O raspbian_root/usr/bin/qemu-aarch64-static
sudo wget -nv https://github.com/multiarch/qemu-user-static/releases/latest/download/qemu-arm-static -O raspbian_root/usr/bin/qemu-arm-static
sudo chmod +x raspbian_root/usr/bin/qemu-{arm,aarch64}-static

View File

@ -100,7 +100,7 @@ jobs:
# TODO: Fix 32bit armbian images
odroidxu4:
# if: ${{ inputs.sd-images || github.event_name != 'workflow_dispatch' }}
# if: ${{ inputs.sd-images || ( github.event_name != 'workflow_dispatch' && !startsWith(github.ref_name, 'docker-') ) }}
if: ${{ false }}
uses: ./.github/workflows/build-sd-images.yml
with:
@ -126,7 +126,7 @@ jobs:
secrets: inherit
# TODO: Fix 32bit armbian images
bananapi:
#if: ${{ inputs.sd-images || github.event_name != 'workflow_dispatch' }}
# if: ${{ inputs.sd-images || ( github.event_name != 'workflow_dispatch' && !startsWith(github.ref_name, 'docker-') ) }}
if: ${{ false }}
uses: ./.github/workflows/build-sd-images.yml
with:

View File

@ -2,18 +2,18 @@
# update latest available version in /var/run/.ncp-latest-version
TMPDIR="$( mktemp -d /tmp/ncp-check.XXXXXX || ( echo "Failed to create temp dir. Exiting" >&2; exit 1 ) )"
trap "rm -rf \"${TMPDIR}\"; exit 0" 0 1 2 3 15
TEMPDIR="$( mktemp -d /tmp/ncp-check.XXXXXX || ( echo "Failed to create temp dir. Exiting" >&2; exit 1 ) )"
trap "rm -rf \"${TEMPDIR}\"; exit 0" 0 1 2 3 15
BRANCH="master"
{ [[ -f /.dockerenv ]] || [[ -f /.docker-image ]] || [[ "$DOCKERBUILD" == 1 ]]; } && BRANCH="docker-stable"
git clone -b "$BRANCH" --depth 20 -q --bare https://github.com/nextcloud/nextcloudpi.git "$TMPDIR" || {
git clone -b "$BRANCH" --depth 20 -q --bare https://github.com/nextcloud/nextcloudpi.git "$TEMPDIR" || {
echo "The git clone command failed: No connectivity to https://github.com ?" >&2
exit 1
}
cd "$TMPDIR" || exit 1
cd "$TEMPDIR" || exit 1
VER=$( git describe --always --tags | grep -oP "v\d+\.\d+\.\d+" )
[[ -f "/usr/local/etc/instance.cfg" ]] && {

View File

@ -16,32 +16,32 @@ DIR="$( cd "$( dirname "$BACKUPFILE" )" &>/dev/null && pwd )" #abspath
[[ -f "$BACKUPFILE" ]] || { echo "$BACKUPFILE not found" ; exit 1; }
[[ "$DIR" =~ "$NCDIR".* ]] && { echo "Refusing to restore from $NCDIR"; exit 1; }
TMPDIR="$( mktemp -d "$( dirname "$BACKUPFILE" )"/ncp-restore.XXXXXX )" || { echo "Failed to create temp dir" >&2; exit 1; }
[[ "$(stat -fc%T "${TMPDIR}")" =~ ext|btrfs|zfs ]] || { echo "Can only restore from ext/btrfs/zfs filesystems (found '$(stat -fc%T "${TMPDIR}")" >&2; exit 1; }
TEMPDIR="$( mktemp -d "$( dirname "$BACKUPFILE" )"/ncp-restore.XXXXXX )" || { echo "Failed to create temp dir" >&2; exit 1; }
[[ "$(stat -fc%T "${TEMPDIR}")" =~ ext|btrfs|zfs ]] || { echo "Can only restore from ext/btrfs/zfs filesystems (found '$(stat -fc%T "${TEMPDIR}")" >&2; exit 1; }
TMPDIR="$( cd "$TMPDIR" &>/dev/null && pwd )" || { echo "$TMPDIR not found"; exit 1; } #abspath
cleanup(){ local RET=$?; echo "Cleanup..."; rm -rf "${TMPDIR}"; trap "" EXIT; exit $RET; }
TEMPDIR="$( cd "$TEMPDIR" &>/dev/null && pwd )" || { echo "$TEMPDIR not found"; exit 1; } #abspath
cleanup(){ local RET=$?; echo "Cleanup..."; rm -rf "${TEMPDIR}"; trap "" EXIT; exit $RET; }
trap cleanup INT TERM HUP ERR EXIT
rm -rf "$TMPDIR" && mkdir -p "$TMPDIR"
rm -rf "$TEMPDIR" && mkdir -p "$TEMPDIR"
[[ "$BACKUPFILE" =~ .*".tar.gz" ]] && compress_arg="-I pigz"
# CHECK FREE SPACE IN $TMPDIR
# CHECK FREE SPACE IN $TEMPDIR
echo "check free space..." # allow at least ~100 extra MiB
extractedsize=$(tar $compress_arg -tvf "$BACKUPFILE" | awk '{s+=$3} END{printf "%.0f", (s/1024)}') # Size of extracted files in "KB"
size=$(($extractedsize + 100*1024))
free=$( df "$TMPDIR" | tail -1 | awk '{ print $4 }' )
free=$( df "$TEMPDIR" | tail -1 | awk '{ print $4 }' )
[ $size -ge $free ] && {
echo "free space check failed. Need $size KB in $TMPDIR";
echo "free space check failed. Need $size KB in $TEMPDIR";
exit 1;
}
# EXTRACT FILES
echo "extracting backup file $BACKUPFILE..."
tar $compress_arg -xf "$BACKUPFILE" -C "$TMPDIR" || exit 1
tar $compress_arg -xf "$BACKUPFILE" -C "$TEMPDIR" || exit 1
## SANITY CHECKS
[[ -d "$TMPDIR"/nextcloud ]] && [[ -f "$( ls "$TMPDIR"/nextcloud-sqlbkp_*.bak 2>/dev/null )" ]] || {
[[ -d "$TEMPDIR"/nextcloud ]] && [[ -f "$( ls "$TEMPDIR"/nextcloud-sqlbkp_*.bak 2>/dev/null )" ]] || {
echo "invalid backup file. Abort"
exit 1
}
@ -54,7 +54,7 @@ echo "restore files..."
mv -T "$NCDIR/data" "$DATA_BKP_DIR/"
}
rm -rf "$NCDIR"
mv -T "$TMPDIR"/nextcloud "$NCDIR" || { echo "Error restoring base files"; exit 1; }
mv -T "$TEMPDIR"/nextcloud "$NCDIR" || { echo "Error restoring base files"; exit 1; }
if [[ -n "$DATA_BKP_DIR" ]]
then
@ -91,7 +91,7 @@ EOFMYSQL
# shellcheck disable=SC2181
[ $? -ne 0 ] && { echo "Error configuring nextcloud database"; exit 1; }
mysql -u root nextcloud < "$TMPDIR"/nextcloud-sqlbkp_*.bak || { echo "Error restoring nextcloud database"; exit 1; }
mysql -u root nextcloud < "$TEMPDIR"/nextcloud-sqlbkp_*.bak || { echo "Error restoring nextcloud database"; exit 1; }
## RESTORE DATADIR
@ -105,7 +105,7 @@ cd "$NCDIR"
### INCLUDEDATA=yes situation
NUMFILES=2
if [[ $( ls "$TMPDIR" | wc -l ) -eq $NUMFILES ]]; then
if [[ $( ls "$TEMPDIR" | wc -l ) -eq $NUMFILES ]]; then
[[ -e "$DATADIR" ]] && {
bk_target="$DATADIR-$( date '+%FT%s' )"
@ -121,7 +121,7 @@ if [[ $( ls "$TMPDIR" | wc -l ) -eq $NUMFILES ]]; then
btrfs subvolume create "$DATADIR" || exit 1
}
chown www-data: "$DATADIR"
TMPDATA="$TMPDIR/$( basename "$DATADIR" )"
TMPDATA="$TEMPDIR/$( basename "$DATADIR" )"
mv "$TMPDATA"/* "$TMPDATA"/.[!.]* "$DATADIR" || exit 1
rmdir "$TMPDATA" || exit 1

View File

@ -19,18 +19,18 @@ fi
BRANCH="${1:-master}"
[[ "$BRANCH" != "master" ]] && echo "INFO: updating to development branch '$BRANCH'"
TMPDIR="$( mktemp -d /tmp/ncp-update.XXXXXX || ( echo "Failed to create temp dir. Exiting" >&2; exit 1 ) )"
trap 'cd /; rm -rf "${TMPDIR}"' EXIT
TEMPDIR="$( mktemp -d /tmp/ncp-update.XXXXXX || ( echo "Failed to create temp dir. Exiting" >&2; exit 1 ) )"
trap 'cd /; rm -rf "${TEMPDIR}"' EXIT
echo -e "Downloading updates"
git clone --depth 20 -b "$BRANCH" -q https://github.com/nextcloud/nextcloudpi.git "$TMPDIR" || {
git clone --depth 20 -b "$BRANCH" -q https://github.com/nextcloud/nextcloudpi.git "$TEMPDIR" || {
echo "No internet connectivity"
exit 1
}
# shellcheck disable=SC2164
[[ -f /.ncp-image ]] || {
cd "$TMPDIR" # update locally during build
cd "$TEMPDIR" # update locally during build
[[ -z "$2" ]] || {
git fetch origin "$2" || {
@ -44,7 +44,7 @@ fi
echo -e "Performing updates"
./update.sh || exit $?
cd "$TMPDIR" || exit 1
cd "$TEMPDIR" || exit 1
git describe --always --tags --abbrev=0 2>/dev/null | grep -qoP "v\d+\.\d+\.\d+" || git fetch --unshallow --tags -q
VER=$( git describe --always --tags --abbrev=0 | grep -oP "v\d+\.\d+\.\d+" )

View File

@ -14,8 +14,8 @@ install()
apt-get update
apt-get install --no-install-recommends -y make gcc libc-dev
local TMPDIR="$( mktemp -d /tmp/noip.XXXXXX )"
cd "$TMPDIR"
local TEMPDIR="$( mktemp -d /tmp/noip.XXXXXX )"
cd "$TEMPDIR"
wget -O- --content-disposition https://github.com/nachoparker/noip-DDNS/archive/master/latest.tar.gz \
| tar -xz \
|| return 1
@ -41,7 +41,7 @@ EOF
chmod +x /etc/init.d/noip2
cd -
rm -r "$TMPDIR"
rm -r "$TEMPDIR"
update-rc.d noip2 defaults
update-rc.d noip2 disable

43
build/armbian/Vagrantfile vendored Normal file
View File

@ -0,0 +1,43 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Vagrantfile for the NCP Debian VM
#
# Instructions: vagrant up; vagrant ssh
#
# Notes: User/Pass is ubnt/ubnt.
# $HOME is accessible as /external. CWD is accessible as /cwd
#
Vagrant.configure("2") do |config|
vmname = "NCP Ubuntu VM"
config.vm.box = "generic/ubuntu2204"
config.vm.box_check_update = true
config.vm.hostname = "ncp-vm"
config.vm.define "ncp-vm"
config.vm.provider :libvirt do |libvirt|
libvirt.default_prefix = ""
libvirt.cpus = 6
libvirt.memory = 4096
end
config.vm.synced_folder '.', '/vagrant', disabled: true
$script = <<-SHELL
sudo su
set -ex
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git ca-certificates
cd /tmp/nextcloudpi
./build/build-SD-armbian.sh "${BOARD_ID?}" "${BOARD_NAME?}"
mv /tmp/nextcloudpi/armbian/output/*.img /tmp/ncp-out/
SHELL
# Provision the VM
config.vm.provision "shell", inline: $script, env: {"BOARD_ID" => ENV['BOARD_ID'], "BOARD_NAME" => ENV['BOARD_NAME']}
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.synced_folder "../..", "/tmp/nextcloudpi", type: "rsync", rsync__exclude: ["/armbian/", ".venv/", "/cache/", "/raspbian_root/", "/output/", "/tmp/", "/.idea/"]
config.vm.synced_folder "../../output", "/tmp/ncp-out", type: "sshfs"
end

View File

@ -12,6 +12,8 @@
set -e
echo 'Running user script...'
ARMBIAN_RELEASE=$1
LINUXFAMILY=$2
BOARD=$3
@ -29,7 +31,9 @@ echo -e "\nInstalling NextCloudPi"
hostname -F /etc/hostname # fix 'sudo resolve host' errors
CODE_DIR="$(pwd)" bash install.sh
CODE_DIR="$(pwd)" DBG=x bash install.sh
echo -e "\nPostinstall..."
run_app_unsafe post-inst.sh
# disable SSH by default, it can be enabled through ncp-web

View File

@ -0,0 +1,30 @@
#!/bin/bash
# Batch creation of NextCloudPi Armbian based images
#
# Copyleft 2023 by Tobias Knöppler
# GPL licensed (see end of file) * Use at your own risk!
#
# Usage: sudo ./build-SD-armbian-vagrant.sh <board_code> [<board_name>]
#
[[ "$UID" == 0 ]] || {
echo "This script needs to be run as root. Try sudo"
exit 1
}
set -ex
export BOARD_ID="${1?}"
export BOARD_NAME="${2:-$1}"
vagrant plugin list | grep vagrant-libvirt || vagrant plugin install vagrant-libvirt
vagrant plugin list | grep vagrant-sshfs || vagrant plugin install vagrant-sshfs
export VAGRANT_DEFAULT_PROVIDER=libvirt
vagrant box list | grep generic/ubuntu2204 || vagrant box add --provider libvirt generic/ubuntu2204
cd "$(dirname "$0")/armbian"
mkdir -p "../../output"
trap 'echo "Cleaning up vagrant..."; vagrant halt; vagrant destroy -f' EXIT
BOARD_ID="$BOARD_ID" BOARD_NAME="$BOARD_NAME" vagrant up --provider=libvirt
exit 0

View File

@ -30,12 +30,11 @@ source etc/library.sh # sets RELEASE
prepare_dirs # tmp cache output
# get latest armbian
[[ -d armbian ]] || git clone --depth 1 --branch v23.02 https://github.com/armbian/build armbian
( cd armbian && git checkout v23.02 )
sed -i -e '/export rootfs_size=/s/du -sm/du --apparent-size -sm/' armbian/lib/functions/image/partitioning.sh
sed -i -e '/export rootfs_size_mib=/s/du -sm/du --apparent-size -sm/' armbian/lib/functions/main/rootfs-image.sh
sed -i -e 's/du /du --apparent-size /' armbian/lib/functions/image/rootfs-to-image.sh
[[ -d armbian ]] || git clone --depth 1 https://github.com/armbian/build armbian
#( cd armbian && git pull --ff-only --tags && git checkout v23.02 )
#sed -i -e '/export rootfs_size=/s/du -sm/du --apparent-size -sm/' armbian/lib/functions/image/partitioning.sh
#sed -i -e '/export rootfs_size_mib=/s/du -sm/du --apparent-size -sm/' armbian/lib/functions/main/rootfs-image.sh
#sed -i -e 's/du /du --apparent-size /' armbian/lib/functions/image/rootfs-to-image.sh
# add NCP modifications
mkdir -p armbian/userpatches armbian/userpatches/overlay
@ -52,7 +51,6 @@ cat > "$CONF" <<EOF
BOARD="$BOARD"
BRANCH=current
RELEASE=${RELEASE%%-security}
KERNEL_ONLY=no
KERNEL_CONFIGURE=prebuilt
BUILD_DESKTOP=no
BUILD_MINIMAL=yes
@ -72,10 +70,10 @@ EXTRA_CONF=build/armbian/"config-$BOARD".conf
# build
rm -rf armbian/output/images
mkdir -p armbian/userpatches
sed -e '/docker.*run/s/-it//' armbian/config/templates/config-docker.conf > armbian/userpatches/config-docker.conf
docker pull "ghcr.io/armbian/build:$(cut -d"." -f1-2 < armbian/VERSION)-$(dpkg --print-architecture)" \
|| docker pull "ghcr.io/armbian/build:latest-$(dpkg --print-architecture)"
sudo armbian/compile.sh docker ncp
#sed -e '/docker.*run/s/-it//' armbian/config/templates/config-docker.conf > armbian/userpatches/config-docker.conf
#docker pull "ghcr.io/armbian/build:$(cut -d"." -f1-2 < armbian/VERSION)-$(dpkg --print-architecture)" \
# || docker pull "ghcr.io/armbian/build:latest-$(dpkg --print-architecture)"
armbian/compile.sh ncp
rm "$CONF"
# pack image

View File

@ -14,8 +14,8 @@ BRANCH="${BRANCH:-master}"
set -e$DBG
TMPDIR="$(mktemp -d /tmp/nextcloudpi.XXXXXX || (echo "Failed to create temp dir. Exiting" >&2 ; exit 1) )"
trap "rm -rf \"${TMPDIR}\"" 0 1 2 3 15
TEMPDIR="$(mktemp -d /tmp/nextcloudpi.XXXXXX || (echo "Failed to create temp dir. Exiting" >&2 ; exit 1) )"
trap "rm -rf \"${TEMPDIR}\"" 0 1 2 3 15
[[ ${EUID} -ne 0 ]] && {
printf "Must be run as root. Try 'sudo $0'\n"
@ -35,7 +35,7 @@ apt-get install --no-install-recommends -y git ca-certificates sudo lsb-release
# get install code
if [[ "${CODE_DIR}" == "" ]]; then
echo "Getting build code..."
CODE_DIR="${TMPDIR}"/nextcloudpi
CODE_DIR="${TEMPDIR}"/nextcloudpi
git clone -b "${BRANCH}" https://github.com/nextcloud/nextcloudpi.git "${CODE_DIR}"
fi
cd "${CODE_DIR}"
@ -82,7 +82,7 @@ rm /.ncp-image
[[ "${CODE_DIR}" != "" ]] || bash /usr/local/bin/ncp-provisioning.sh
cd -
rm -rf "${TMPDIR}"
rm -rf "${TEMPDIR}"
cohorte_id=$((RANDOM % 100))
cat <<EOF > /usr/local/etc/instance.cfg