From 0d620afb717804bb2e6f07bcc84a471f51e84d19 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Sat, 6 Apr 2019 23:16:46 +0000 Subject: scripts: use only a single copy --- files/usr/local/bin/build.sh | 122 +++++++++++++++++++++++++++++++++++++++++++ files/usr/local/bin/setup.sh | 18 +++++++ 2 files changed, 140 insertions(+) create mode 100755 files/usr/local/bin/build.sh create mode 100755 files/usr/local/bin/setup.sh (limited to 'files/usr/local') diff --git a/files/usr/local/bin/build.sh b/files/usr/local/bin/build.sh new file mode 100755 index 0000000..8b5ad67 --- /dev/null +++ b/files/usr/local/bin/build.sh @@ -0,0 +1,122 @@ +#!/bin/sh + +set -eu + +readonly APORTSDIR=$HOME/aports +readonly REPODEST=$HOME/packages +readonly REPOS="main community testing" +readonly MIRROR=http://dl-cdn.alpinelinux.org/alpine +readonly REPOURL=https://github.com/alpinelinux/aports + +msg() { + local color=${2:-green} + case "$color" in + red) color="31";; + green) color="32";; + yellow) color="33";; + blue) color="34";; + *) color="32";; + esac + printf "\033[1;%sm>>>\033[1;0m %s\n" "$color" "$1" | xargs >&2 +} + +die() { + msg "$1" red + exit 1 +} + +get_release() { + local branch=$DRONE_COMMIT_BRANCH + case $branch in + *-stable) echo v${branch%-*};; + master) echo edge;; + *) die "Branch \"$branch\" not supported!" + esac +} + +build_aport() { + local repo="$1" aport="$2" + cd "$APORTSDIR/$repo/$aport" + abuild -r +} + +changed_repos() { + cd "$APORTSDIR" + for repo in $REPOS; do + git diff --exit-code remotes/origin/$DRONE_COMMIT_BRANCH -- $repo >/dev/null \ + || echo "$repo" + done +} + +set_repositories_for() { + local target_repo="$1" repos= repo= + local release=$(get_release) + for repo in $REPOS; do + repos="$repos $MIRROR/$release/$repo" + [ "$repo" = "$target_repo" ] && break + done + sudo sh -c "printf '%s\n' $repos > /etc/apk/repositories" + sudo apk update +} + +changed_aports() { + cd "$APORTSDIR" + local repo="$1" + local aports=$(git diff --name-only --diff-filter=ACMR --relative="$repo" \ + remotes/origin/$DRONE_COMMIT_BRANCH -- "*/APKBUILD" | xargs -I% dirname %) + ap builddirs -d "$APORTSDIR/$repo" $aports 2>/dev/null | xargs -I% basename % | xargs +} + +setup_system() { + sudo sh -c "echo $MIRROR/$(get_release)/main > /etc/apk/repositories" + sudo apk -U upgrade -a || apk fix || die "Failed to up/downgrade system" + abuild-keygen -ain + sudo sed -i 's/JOBS=[0-9]*/JOBS=$(nproc)/' /etc/abuild.conf + mkdir -p "$REPODEST" +} + +create_workspace() { + msg "Cloning aports and applying PR$DRONE_PULL_REQUEST" + git clone --depth=1 --branch $DRONE_COMMIT_BRANCH $REPOURL $APORTSDIR + wget -qO- $REPOURL/pull/$DRONE_PULL_REQUEST.patch | git -C $APORTSDIR am +} + + +sysinfo() { + printf ">>> Host system information (arch: %s, release: %s) <<<\n" "$(apk --print-arch)" "$(get_release)" + printf "- Number of Cores: %s\n" $(nproc) + printf "- Memory: %s Gb\n" $(awk '/^MemTotal/ {print ($2/1024/1024)}' /proc/meminfo) + printf "- Free space: %s\n" $(df -hP / | awk '/\/$/ {print $4}') +} + +aport_ok= +aport_ng= + +sysinfo || true +setup_system || die "Failed to setup system" +create_workspace || die "Failed to create workspace" + +for repo in $(changed_repos); do + set_repositories_for "$repo" + for pkgname in $(changed_aports "$repo"); do + if build_aport "$repo" "$pkgname"; then + checkapk || true + aport_ok="$aport_ok $repo/$pkgname" + else + aport_ng="$aport_ng $repo/$pkgname" + fi + done +done + +echo "### Build summary ###" + +for ok in $aport_ok; do + msg "$ok: build succesfully" +done + +if [ -n "$aport_ng" ]; then + die "Failed to build packages:$aport_ng" +elif [ -z "$aport_ok" ]; then + msg "No packages found to be built." yellow +fi + diff --git a/files/usr/local/bin/setup.sh b/files/usr/local/bin/setup.sh new file mode 100755 index 0000000..9e80a82 --- /dev/null +++ b/files/usr/local/bin/setup.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -eu + +release=${1:-edge} +echo "http://dl-cdn.alpinelinux.org/alpine/$release/main" > /etc/apk/repositories + +apk -U upgrade -a +apk add alpine-sdk lua-aports pigz +rm -rf /var/cache/apk/* + +# use buildozer for building +adduser -D buildozer +adduser buildozer abuild +adduser buildozer wheel + +# default distfiles location +install -d -g abuild -m 775 /var/cache/distfiles -- cgit v1.2.3