Skip to content

Commit

Permalink
hack: add shellcheck
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed May 23, 2021
1 parent c1a3c1e commit bd29a15
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 151 deletions.
1 change: 1 addition & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ jobs:
name: Run
run: |
./hack/validate-shfmt
./hack/shellcheck
47 changes: 30 additions & 17 deletions base/xx-apk
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e

if [ -z "$XX_APK_NOLOCK" ]; then
lock="/var/lock/xx-apk"
exec 200>$lock
flock -x 200
exec 9>$lock
flock -x 9
export XX_APK_NOLOCK=1
fi

Expand All @@ -14,7 +14,7 @@ if [ -n "$XX_DEBUG_APK" ]; then
fi

for l in $(xx-info env); do
export $l
export "${l?}"
done

if [ "${TARGETOS}" != "linux" ]; then
Expand Down Expand Up @@ -44,15 +44,15 @@ setup() {
cp /etc/apk/repositories "$apk_dir/"
mkdir "$apk_dir/keys"
mkdir "$apk_dir/protected_paths.d"
echo $XX_PKG_ARCH >"$apk_dir/arch"
echo "$XX_PKG_ARCH" >"$apk_dir/arch"
apk add --no-cache --initdb -p "/${XX_TRIPLE}" --allow-untrusted alpine-keys

if [ -d "/etc/apk/cache" ]; then
mkdir -p /etc/apk/cache/_$XX_PKG_ARCH
ln -s /etc/apk/cache/_$XX_PKG_ARCH "$apk_dir/cache"
mkdir -p "/etc/apk/cache/_$XX_PKG_ARCH"
ln -s "/etc/apk/cache/_$XX_PKG_ARCH" "$apk_dir/cache"
fi

touch $done_file
touch "$done_file"
}

clean() {
Expand All @@ -64,25 +64,38 @@ clean() {
echo >&2 "invalid triple root $XX_TRIPLE"
exit 1
fi
rm -rf "/${XX_TRIPLE}"
rm -rf "/${XX_TRIPLE:?}"
}

cmd() {
setup
root="-p /"
root="/"
if xx-info is-cross; then
root="-p /${XX_TRIPLE}"
root="/${XX_TRIPLE}"
fi
args=$(echo "$@" | sed "s/xx-c-essentials/musl-dev gcc/" | sed "s/xx-cxx-essentials/g++/")
if [ "$#" = "0" ]; then
root=""
else
echo "+ apk $root" "$args"
n=$#
for a in "$@"; do
if [ $# = $n ]; then set --; fi
case "$a" in
"xx-c-essentials")
set -- "$@" musl-dev gcc
;;
"xx-cxx-essentials")
set -- "$@" g++
;;
*)
set -- "$@" "$a"
;;
esac
done
if [ "$#" != "0" ]; then
set -- "--root" "$root" "$@"
echo "+ apk " "$@"
fi
apk $root $args
apk "$@"
if xx-info is-cross; then
if [ -z "$XX_APK_KEEP_BINARIES" ]; then
rm -rf /${XX_TRIPLE}/usr/bin/*
rm -rf "/${XX_TRIPLE:?}/usr/bin/*"
fi
fi
}
Expand Down
31 changes: 11 additions & 20 deletions base/xx-apt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ -n "$XX_DEBUG_APT" ]; then
fi

for l in $(xx-info env); do
export $l
export "${l?}"
done

if [ "${TARGETOS}" != "linux" ]; then
Expand All @@ -34,9 +34,9 @@ esac

packages=
parsed=
args=

n=$#
for p in "$@"; do
if [ $# = $n ]; then set --; fi
arg=
case "$p" in
-*)
Expand All @@ -59,11 +59,7 @@ for p in "$@"; do
;;
esac
if [ -n "$arg" ]; then
if [ -z "$args" ]; then
args="$arg"
else
args="${args} ${arg}"
fi
set -- "$@" "$arg"
fi
done

Expand All @@ -90,13 +86,13 @@ packages2=
for p in ${packages}; do
if [ "${p}" = "xx-c-essentials" ]; then
p="libc6-dev"
if apt info libgcc-10-dev:${XX_PKG_ARCH}; then
if apt info "libgcc-10-dev:${XX_PKG_ARCH}"; then
p="$p libgcc-10-dev"
else
p="$p libgcc-8-dev"
fi
elif [ "${p}" = "xx-cxx-essentials" ]; then
if apt info libstdc++-10-dev:${XX_PKG_ARCH}; then
if apt info "libstdc++-10-dev:${XX_PKG_ARCH}"; then
p="libstdc++-10-dev"
else
p="libstdc++-8-dev"
Expand All @@ -109,24 +105,19 @@ for p in ${packages}; do
fi
done

new=
for p in ${packages2}; do
n=
if [ -n "$nocross" ]; then
n=${p}
elif apt info ${p}-${suffix} >/dev/null 2>/dev/null; then
elif apt info "${p}-${suffix}" >/dev/null 2>/dev/null; then
n="${p}-${suffix}"
elif [ -n "${XX_APT_PREFER_CROSS}" ] && apt info ${p}-${XX_PKG_ARCH}-cross >/dev/null 2>/dev/null; then
elif [ -n "${XX_APT_PREFER_CROSS}" ] && apt info "${p}-${XX_PKG_ARCH}-cross" >/dev/null 2>/dev/null; then
n="${p}-${XX_PKG_ARCH}-cross"
else
n="${p}:${XX_PKG_ARCH}"
fi
if [ -z "$new" ]; then
new="$n"
else
new="${new} ${n}"
fi
set -- "$@" "$n"
done

echo >&2 "+ apt ${args} ${new}"
exec apt ${args} ${new}
echo >&2 "+ apt " "$@"
exec apt "$@"
Loading

0 comments on commit bd29a15

Please sign in to comment.