Skip to content

Commit

Permalink
Fix shellcheck issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Salamandar committed Oct 24, 2024
1 parent 48d4b23 commit 14c1914
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 90 deletions.
7 changes: 4 additions & 3 deletions config/config
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/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"

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/"
54 changes: 27 additions & 27 deletions rebuild-unstable
Original file line number Diff line number Diff line change
@@ -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()
{
Expand All @@ -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 "-------------------------------------"
Expand All @@ -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
Expand Down Expand Up @@ -94,31 +94,31 @@ 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

}

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
47 changes: 26 additions & 21 deletions scripts/build_deb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/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
source "$THISDIR/../config/config"
source "$THISDIR/common.sh"

# ##### #
# Usage #
Expand All @@ -32,13 +33,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}')
Expand All @@ -47,10 +48,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
Expand All @@ -60,7 +61,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"
Expand All @@ -73,7 +74,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
Expand All @@ -87,25 +88,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
5 changes: 4 additions & 1 deletion scripts/common.sh
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -23,7 +26,7 @@ function info()
}

function boxed()
{
{
local msg=${1}
echo "$msg" | boxes -d stone
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/make-chroots
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ 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"
32 changes: 19 additions & 13 deletions scripts/ynh-custom-builds
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/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
source "$THISDIR/../config/config"
source "$THISDIR/common.sh"

# ##### #
# Usage #
Expand All @@ -31,8 +32,8 @@ EOF
function main()
{
validate_arguments
cd $GIT_REPOS/$PACKAGE
tweak_$PACKAGE
cd "$GIT_REPOS/$PACKAGE" || exit 1
"tweak_$PACKAGE"
build
}

Expand Down Expand Up @@ -79,9 +80,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}"
Expand All @@ -101,21 +102,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
Loading

0 comments on commit 14c1914

Please sign in to comment.