diff --git a/config/config b/config/config index 2639579..4358620 100644 --- a/config/config +++ b/config/config @@ -1,6 +1,7 @@ #!/bin/bash +# shellcheck disable=SC2155,SC2034 -readonly HOME_VINAIGRETTE=$(dirname $(dirname $(realpath ${BASH_SOURCE[0]}))) +readonly HOME_VINAIGRETTE=$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")") readonly GIT_REPOS="$HOME_VINAIGRETTE/gitrepos/" readonly BUILD_DEB="$HOME_VINAIGRETTE/scripts/build_deb" @@ -8,8 +9,8 @@ readonly BUILD_DEB="$HOME_VINAIGRETTE/scripts/build_deb" readonly REPO_URL="forge.yunohost.org" readonly REPO_DIR="$HOME_VINAIGRETTE/../www/debian" readonly REPO_CONFIG=$HOME_VINAIGRETTE/config/distributions -readonly REPO_ARCHS="$(grep "Architectures" $REPO_CONFIG | head -n 1 | awk -F: '{print $2}' | sed 's/source//g')" -readonly REPO_DISTS="$(grep "^Codename" $REPO_CONFIG | awk '{print $2}')" +readonly REPO_ARCHS="$(grep "Architectures" "$REPO_CONFIG" | head -n 1 | awk -F: '{print $2}' | sed 's/source//g')" +readonly REPO_DISTS="$(grep "^Codename" "$REPO_CONFIG" | awk '{print $2}')" readonly LAST_BUILDS_CACHE="$HOME_VINAIGRETTE/.last_builds/" readonly CHROOTS="$HOME_VINAIGRETTE/.chroots/" diff --git a/rebuild-unstable b/rebuild-unstable index dd1a645..6cdc2e0 100755 --- a/rebuild-unstable +++ b/rebuild-unstable @@ -1,13 +1,13 @@ #!/bin/bash +# shellcheck disable=SC2155 -readonly THISSCRIPT=$0 -readonly THISDIR=$(dirname $0) +readonly THISDIR=$(dirname "$0") readonly TIMETAG="$(date +%Y%m%d%H%M)" readonly PACKAGES="moulinette SSOwat yunohost yunohost-admin yunohost-portal" readonly FORCE="false" -source $(dirname $THISSCRIPT)/config/config -mkdir -p $LAST_BUILDS_CACHE +source "$THISDIR/config/config" +mkdir -p "$LAST_BUILDS_CACHE" function main() { @@ -19,7 +19,7 @@ function main() echo "-------------------------------------" echo "Looking for update in ${PACKAGE} for ${DISTRIB}... " - build_if_needed $PACKAGE $DISTRIB + build_if_needed "$PACKAGE" "$DISTRIB" done done echo "-------------------------------------" @@ -45,25 +45,25 @@ function build_if_needed() fi fi - cd $GIT_REPOS/$PACKAGE + cd "$GIT_REPOS/$PACKAGE" || exit 1 git fetch origin >/dev/null 2>/dev/null - git checkout $BRANCH_NIGHTLY >/dev/null 2>/dev/null - git pull origin $BRANCH_NIGHTLY >/dev/null 2>/dev/null - git reset --hard origin/$BRANCH_NIGHTLY + git checkout "$BRANCH_NIGHTLY" >/dev/null 2>/dev/null + git pull origin "$BRANCH_NIGHTLY" >/dev/null 2>/dev/null + git reset --hard "origin/$BRANCH_NIGHTLY" # Check if build is needed - if [ -e $LAST_BUILD_FOR_THIS_PACKAGE ] + if [ -e "$LAST_BUILD_FOR_THIS_PACKAGE" ] then - TIMESTAMP_LASTBUILD=$(stat -c %Y $LAST_BUILD_FOR_THIS_PACKAGE) + TIMESTAMP_LASTBUILD=$(stat -c %Y "$LAST_BUILD_FOR_THIS_PACKAGE") else TIMESTAMP_LASTBUILD=0 fi TIMESTAMP_HEAD=$(git show -s --format=%ct HEAD) - if [ $TIMESTAMP_HEAD -lt $TIMESTAMP_LASTBUILD ] + if [ "$TIMESTAMP_HEAD" -lt "$TIMESTAMP_LASTBUILD" ] then if ! "$FORCE"; then @@ -94,11 +94,11 @@ function build_if_needed() # Launch the build using build_deb script build - touch $LAST_BUILD_FOR_THIS_PACKAGE + touch "$LAST_BUILD_FOR_THIS_PACKAGE" # Restore changelog echo "> Restoring previous changelog" - cd $GIT_REPOS/$PACKAGE + cd "$GIT_REPOS/$PACKAGE" || exit 1 cp debian/changelog.old debian/changelog rm debian/changelog.old @@ -106,19 +106,19 @@ function build_if_needed() function build() { - # Create temporary folder - TMP_FOLDER=$(mktemp -d) - - # Move files to a tmp folder - echo "> Exporting in $TMP_FOLDER ... " - git ls-files | xargs tar -czf archive.tar.gz - cat archive.tar.gz | tar -xz -C $TMP_FOLDER - rm archive.tar.gz - - # Build Debian package - echo "> Starting build ..." - cd $TMP_FOLDER - $BUILD_DEB $DISTRIB "unstable" . + # Create temporary folder + TMP_FOLDER=$(mktemp -d) + + # Move files to a tmp folder + echo "> Exporting in $TMP_FOLDER ... " + git ls-files | xargs tar -czf archive.tar.gz + tar xzf archive.tar.gz -C "$TMP_FOLDER" + rm archive.tar.gz + + # Build Debian package + echo "> Starting build ..." + cd "$TMP_FOLDER" || exit 1 + $BUILD_DEB "$DISTRIB" "unstable" . } main diff --git a/scripts/build_deb b/scripts/build_deb index 7427c52..d67bbfd 100755 --- a/scripts/build_deb +++ b/scripts/build_deb @@ -1,14 +1,17 @@ #!/bin/bash +# shellcheck disable=SC2155 readonly THISSCRIPT=$0 -readonly THISDIR=$(dirname $0) +readonly THISDIR=$(dirname "$0") readonly DISTRIB=$1 readonly BRANCH=$2 readonly FOLDER=$3 readonly ARCHS=$4 -source $THISDIR/../config/config -source $THISDIR/common.sh +# shellcheck source=config/config +source "$THISDIR/../config/config" +# shellcheck source=scripts/common.sh +source "$THISDIR/common.sh" # ##### # # Usage # @@ -32,13 +35,13 @@ EOF function main() { - grep -q "^Codename: $DISTRIB$" $REPO_CONFIG || critical "Invalid distribution $DISTRIB" - grep -q "^Components: .*$BRANCH.*$" $REPO_CONFIG || critical "Invalid branch $BRANCH" + grep -q "^Codename: $DISTRIB$" "$REPO_CONFIG" || critical "Invalid distribution $DISTRIB" + grep -q "^Components: .*$BRANCH.*$" "$REPO_CONFIG" || critical "Invalid branch $BRANCH" [[ -n "$FOLDER" ]] || critical "Need a folder in which to build" - readonly PKG_DIR=$(readlink -fn $FOLDER) - readonly ROOT_DIR=$(readlink -fn ${PKG_DIR}/../) - cd $PKG_DIR + readonly PKG_DIR=$(readlink -fn "$FOLDER") + readonly ROOT_DIR=$(readlink -fn "$PKG_DIR/../") + cd "$PKG_DIR" || exit 1 readonly PACKAGE=$(dpkg-parsechangelog | awk '/^Source: / {print $2}') readonly VERSION=$(dpkg-parsechangelog | awk '/^Version: / {print $2}') @@ -47,10 +50,10 @@ function main() if [[ -n "$ARCHS" ]] then - archs="$(echo $ARCHS | tr ',' ' ')" + archs="$(echo "$ARCHS" | tr ',' ' ')" # Architecture-agnostic packages have 'architecture: all' in their control files # others have 'architecture: any' - elif grep -q "Architecture: all" $PKG_DIR/debian/control + elif grep -q "Architecture: all" "$PKG_DIR/debian/control" then archs="all" else @@ -60,7 +63,7 @@ function main() for arch in $archs do sendxmpppy "🏗️ Starting build for ${PACKAGE}/${VERSION} for $DISTRIB/$BRANCH/$arch ..." - if ! build $arch + if ! build "$arch" then sendxmpppy "❌ Failed build for ${PACKAGE}/${VERSION} for $DISTRIB/$BRANCH/$arch ?!" critical "Failed to build ${PACKAGE}/${VERSION} for $DISTRIB/$BRANCH/$arch" @@ -73,7 +76,7 @@ function main() changearch=$arch fi - if reprepro --waitforlock 6 -b $REPO_DIR -C $BRANCH include $DISTRIB ${ROOT_DIR}/${PACKAGE}_${VERSION}_$changearch.changes + if reprepro --waitforlock 6 -b "$REPO_DIR" -C "$BRANCH" include "$DISTRIB" "${ROOT_DIR}/${PACKAGE}_${VERSION}_$changearch.changes" then sendxmpppy "✔️ Completed build for ${PACKAGE}/${VERSION} for $DISTRIB/$BRANCH/$arch." else @@ -87,25 +90,29 @@ function build() { local arch=$1 - local opts="" + local opts=() - opts+=" -d $DISTRIB" - opts+=" --no-run-lintian" - opts+=" --no-run-piuparts" - opts+=" --no-run-autopkgtest" + opts+=(-d "$DISTRIB") + opts+=(--no-run-lintian) + opts+=(--no-run-piuparts) + opts+=(--no-run-autopkgtest) if [[ "$arch" != "all" ]] then - opts+=" --host=$arch" + opts+=( --host="$arch" ) fi if [[ -n "$DEBUG" ]] then - opts+=" --anything-failed-commands='%s'" + opts+=(--anything-failed-commands='%s') fi - sbuild $opts + sbuild "${opts[@]}" } +if [[ "$1" =~ ^-h|--help$ ]]; then + usage + exit +fi -[[ "$1" =~ ^-h|--help$ ]] && (usage; exit 0) || main +main diff --git a/scripts/common.sh b/scripts/common.sh index 8692064..2d0085a 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -1,3 +1,6 @@ +#!/bin/bash +# shellcheck disable=SC2155,SC2034 + readonly NORMAL=$(printf '\033[0m') readonly BOLD=$(printf '\033[1m') readonly faint=$(printf '\033[2m') @@ -23,7 +26,7 @@ function info() } function boxed() -{ +{ local msg=${1} echo "$msg" | boxes -d stone } diff --git a/scripts/make-chroots b/scripts/make-chroots index 4b1f055..f174f5a 100755 --- a/scripts/make-chroots +++ b/scripts/make-chroots @@ -1,10 +1,11 @@ #!/bin/bash +# shellcheck source=config/config source ../config/config DIST=$1 PREINSTALL="eatmydata,ccache,build-essential,perl-openssl-defaults,debhelper,cmake,wget,devscripts,git,aptitude,debhelper,dh-python,python3-all,python3-yaml,python3-jinja2,python3-setuptools,python3-psutil,lua5.1,liblua5.1-0-dev,libidn11-dev,libssl-dev,txt2man,quilt" -mkdir -p $CHROOTS +mkdir -p "$CHROOTS" -sbuild-createchroot --include=$PREINSTALL $DIST $CHROOTS/$DIST-all +sbuild-createchroot --include=$PREINSTALL "$DIST" "$CHROOTS/$DIST-all" diff --git a/scripts/ynh-custom-builds b/scripts/ynh-custom-builds index 1491c5c..fb77fe9 100755 --- a/scripts/ynh-custom-builds +++ b/scripts/ynh-custom-builds @@ -1,14 +1,17 @@ #!/bin/bash +# shellcheck disable=SC2155,SC2034 readonly THISSCRIPT=$0 -readonly THISDIR=$(dirname $0) +readonly THISDIR=$(dirname "$0") readonly PACKAGE=$1 readonly BRANCH=$2 readonly DISTRIB="bookworm" readonly DISTRIB_N="12" -source $THISDIR/../config/config -source $THISDIR/common.sh +# shellcheck source=config/config +source "$THISDIR/../config/config" +# shellcheck source=scripts/common.sh +source "$THISDIR/common.sh" # ##### # # Usage # @@ -31,8 +34,8 @@ EOF function main() { validate_arguments - cd $GIT_REPOS/$PACKAGE - tweak_$PACKAGE + cd "$GIT_REPOS/$PACKAGE" || exit 1 + "tweak_$PACKAGE" build } @@ -79,9 +82,9 @@ function tweak_metronome() function build() { # SVERSION is VERSION without the -1 at the end ... - local SVERSION=$(echo $VERSION | tr '-' ' ' | awk '{print $1}') + local SVERSION=$(echo "$VERSION" | tr '-' ' ' | awk '{print $1}') - cd $GIT_REPOS/$PACKAGE + cd "$GIT_REPOS/$PACKAGE" || exit 1 # Tweak the changelog temporarily info "Setting version in changelog to ${VERSION}" @@ -101,21 +104,26 @@ function build() # Extract git archive a desired tag info "Exporting in $TMP_FOLDER ... " git ls-files | xargs tar -czf archive.tar.gz - cat archive.tar.gz | tar -xz -C $TMP_FOLDER + tar xzf archive.tar.gz -C "$TMP_FOLDER" # For some reason, these wants archive named # e.g. metronome_x.y.z+stuff.orig.tar.gz # in the parent folder... - mv archive.tar.gz $TMP_FOLDER/../${PACKAGE}_${SVERSION}.orig.tar.gz + mv archive.tar.gz "$TMP_FOLDER/../${PACKAGE}_${SVERSION}.orig.tar.gz" # Build Debian package - cd $TMP_FOLDER - $BUILD_DEB $DISTRIB $BRANCH . + cd "$TMP_FOLDER" || exit 1 + $BUILD_DEB $DISTRIB "$BRANCH" . # Restore changelog info "Restoring previous changelog" - cd $GIT_REPOS/$PACKAGE + cd "$GIT_REPOS/$PACKAGE" || exit 1 cp debian/changelog.old debian/changelog rm debian/changelog.old } -[[ "$1" =~ ^-h|--help$ ]] && (usage; exit 0) || main +if [[ "$1" =~ ^-h|--help$ ]]; then + usage + exit +fi + +main diff --git a/ynh-build b/ynh-build index 09c12ba..500d79c 100755 --- a/ynh-build +++ b/ynh-build @@ -1,25 +1,24 @@ #!/bin/bash +# shellcheck disable=SC2155 readonly THISSCRIPT=$0 -readonly THISDIR=$(dirname $0) +readonly THISDIR=$(dirname "$0") readonly PROJECT=$1 readonly BRANCH=$2 readonly VERSION=$3 readonly TAG=$(echo "debian/$VERSION" | tr '~' '-') -if [[ "$(echo $VERSION | awk -F'.' '{print $1}')" == "11" ]] -then - readonly DISTRIB="bullseye" -elif [[ "$(echo $VERSION | awk -F'.' '{print $1}')" == "12" ]] -then - readonly DISTRIB="bookworm" +if [[ "$(echo "$VERSION" | awk -F'.' '{print $1}')" == "11" ]]; then + readonly DISTRIB="bullseye" +elif [[ "$(echo "$VERSION" | awk -F'.' '{print $1}')" == "12" ]]; then + readonly DISTRIB="bookworm" else - readonly DISTRIB="fixyoversionnumberbruh" + readonly DISTRIB="fixyoversionnumberbruh" fi -source $THISDIR/config/config -source $THISDIR/scripts/common.sh +source "$THISDIR/config/config" +source "$THISDIR/scripts/common.sh" # ##### # # Usage # @@ -30,12 +29,12 @@ function usage() cat << EOF Usage: - $THISSCRIPT + $THISSCRIPT Arguments: - moulinette, yunohost, yunohost-admin, yunohost-portal or SSOwat - testing or stable - x.y.z (ex: 2.6.1) + moulinette, yunohost, yunohost-admin, yunohost-portal or SSOwat + testing or stable + x.y.z (ex: 2.6.1) EOF } @@ -47,8 +46,8 @@ EOF function validate_arguments() { [[ $PROJECT =~ ^yunohost|yunohost-admin|yunohost-portal|moulinette|SSOwat$ ]] || critical "Invalid project $PROJECT" - grep -q "^Codename: $DISTRIB$" $REPO_CONFIG || critical "Invalid distribution $DISTRIB" - grep -q "^Components: .*$BRANCH.*$" $REPO_CONFIG || critical "Invalid branch $BRANCH" + grep -q "^Codename: $DISTRIB$" "$REPO_CONFIG" || critical "Invalid distribution $DISTRIB" + grep -q "^Components: .*$BRANCH.*$" "$REPO_CONFIG" || critical "Invalid branch $BRANCH" [[ -n "$VERSION" ]] || critical "Invalid version $VERSION" [[ "$(tty)" != "not a tty" ]] || critical "You aint in a tty (are you in a 'lxc exec' ?) The script can't run because pbuilder won't be happy :|" } @@ -58,11 +57,11 @@ function checkout_tag() # Update project's repository boxed "> Updating $GIT_REPOS/$PROJECT repository ... " - cd $GIT_REPOS/$PROJECT + cd "$GIT_REPOS/$PROJECT" || exit 1 git fetch --quiet git fetch --tags --quiet - git checkout $TAG --quiet - git reset --hard $TAG --quiet + git checkout "$TAG" --quiet + git reset --hard "$TAG" --quiet # Validate constrains for the version number given (is in changelog + has corresponding tag) @@ -91,12 +90,12 @@ function build() # Extract git archive a desired tag info "Exporting in $TMP_FOLDER ... " - git archive $TAG --format=tar | tar -x -C $TMP_FOLDER + git archive "$TAG" --format=tar | tar -x -C "$TMP_FOLDER" # Build Debian package boxed "Building Debian package ... " - cd $TMP_FOLDER - $BUILD_DEB $DISTRIB $BRANCH . + cd "$TMP_FOLDER" || exit 1 + $BUILD_DEB $DISTRIB "$BRANCH" . } @@ -110,4 +109,9 @@ function main() build } -[[ "$1" =~ ^-h|--help$ ]] && usage || main +if [[ "$1" =~ ^-h|--help$ ]]; then + usage + exit +fi + +main