Skip to content

Commit

Permalink
fixup! wip: add support for xx-dnf
Browse files Browse the repository at this point in the history
  • Loading branch information
panekj committed Jun 17, 2024
1 parent 22a8b4c commit 5cc79a6
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 47 deletions.
3 changes: 3 additions & 0 deletions src/test-cargo.bats
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ testHelloCargoRustup() {
debian | ubuntu)
add cargo
;;
fedora)
add cargo
;;
esac
}

Expand Down
91 changes: 63 additions & 28 deletions src/test_helper.bash
Original file line number Diff line number Diff line change
@@ -1,43 +1,78 @@
#!/usr/bin/env bash

. /etc/os-release

pkg() {
case "${op}" in
add|install)
alpine_op="add"
op="install"
apt_opts="--no-install-recommends"
opts=""
;;
del|remove)
alpine_op="del"
op="remove"
apt_opts="--autoremove"
opts="2>/dev/null || true"
;;
*)
printf "Unknown op"
exit 1
;;
esac

case "${xx}" in
true) xx="xx-" ;;
*) xx="" ;;
esac

case "${ID}" in
alpine|chimera|adelie)
if [ "${op}" = "install" ]; then
${xx}apk ${alpine_op} "$@"
else
${xx}apk ${alpine_op} "$@" 2>/dev/null || true
fi
return
;;
esac
case "${ID_LIKE}" in
debian)
if [ "${op}" = "install" ]; then
xxrun ${xx}apt ${op} -y ${apt_opts} "$@"
else
xxrun ${xx}apt ${op} -y ${apt_opts} "$@" 2>/dev/null || true
fi
;;
fedora)
if [ "${op}" = "install" ]; then
xxrun ${xx}dnf ${op} "$@"
else
xxrun ${xx}dnf ${op} "$@" 2>/dev/null || true
fi
;;
*)
printf "Unknown OS:\n\t%s\n\t%s" "${ID}" "${ID_LIKE}"
exit 1
;;
esac
}

add() {
if [ -f /etc/alpine-release ]; then
apk add "$@"
elif [ -f /etc/fedora-release ]; then
xxrun dnf install "$@"
else
xxrun apt install -y --no-install-recommends "$@"
fi
op="add" pkg "$@"
}

del() {
if [ -f /etc/alpine-release ]; then
apk del "$@" 2>/dev/null || true
elif [ -f /etc/fedora-release ]; then
xxrun dnf remove "$@"
else
xxrun apt remove --autoremove -y "$@" 2>/dev/null || true
fi
op="del" pkg "$@"
}

xxadd() {
if [ -f /etc/alpine-release ]; then
xx-apk add "$@"
elif [ -f /etc/fedora-release ]; then
xxrun xx-dnf install "$@"
else
xxrun xx-apt install -y --no-install-recommends "$@"
fi
op="add" xx="true" pkg "$@"
}

xxdel() {
if [ -f /etc/alpine-release ]; then
xx-apk del "$@" 2>/dev/null || true
elif [ -f /etc/fedora-release ]; then
xxrun xx-dnf remove "$@"
else
xxrun xx-apt remove -y --autoremove "$@" 2>/dev/null || true
fi
op="del" xx="true" pkg "$@"
}

xxrun() {
Expand Down
4 changes: 4 additions & 0 deletions src/xx-apk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

set -e

# shellcheck source=./xx-common
. "$(command -v xx-common)"

flock_setup
if [ -z "$XX_APK_NOLOCK" ]; then
lock="/var/lock/xx-apk"
exec 9>$lock
Expand Down
4 changes: 4 additions & 0 deletions src/xx-apt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

set -e

# shellcheck source=./xx-common
. "$(command -v xx-common)"

flock_setup
if [ -z "$XX_APT_NOLOCK" ]; then
lock="/var/lock/xx-apt"
exec 9>$lock
Expand Down
41 changes: 33 additions & 8 deletions src/xx-cargo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ execSilent() {
fi
}

# shellcheck source=./xx-common
. "$(command -v xx-common)"

flock_setup
if [ -z "$XX_CARGO_NOLOCK" ]; then
lock="/var/lock/xx-cargo"
exec 9>$lock
Expand Down Expand Up @@ -62,15 +66,36 @@ if [ ! -f "$done_file" ]; then
if [ ! -d "$(rustc --print sysroot)/lib/rustlib/$(xx-info)" ]; then
if [ -n "$rustup" ]; then
execSilent rustup target add "$(xx-info)"
elif [ -f /etc/alpine-release ]; then
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-apk add rust-stdlib
elif [ -f /etc/fedora-release ]; then
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-dnf install --assumeyes rust-std-static
else
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-apt-get install -y libstd-rust-dev
. /etc/os-release

if [ -z "${ID_LIKE}" ]; then
case "${ID}" in
alpine)
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-apk add rust-stdlib
;;
*)
echo "unknown OS"
exit 1
;;
esac
else
case "${ID_LIKE}" in
fedora)
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-dnf install --assumeyes rust-std-static
;;
debian)
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-apt-get install -y libstd-rust-dev
;;
*)
echo "unknown OS"
exit 1
;;
esac
fi
fi
fi
touch "$done_file"
Expand Down
4 changes: 4 additions & 0 deletions src/xx-cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ if [ -f /.xx-cc-autowrap ]; then
fi

setup() {
# shellcheck source=./xx-common
. "$(command -v xx-common)"

flock_setup
if [ -z "$XX_CC_NOLOCK" ]; then
lock="/var/lock/xx-cc"
exec 9>$lock
Expand Down
17 changes: 10 additions & 7 deletions src/xx-common
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

cmd_exists() {
if command -v $1 >/dev/null 2>/dev/null; then
if command -v "$1" >/dev/null 2>/dev/null; then
return 0
else
return 1
Expand Down Expand Up @@ -31,25 +31,28 @@ get_dnf() {

add_package() {
if cmd_exists apk; then
apk add --no-cache $1 >"$2"
apk add --no-cache "$1" >"$2"
elif cmd_exists apt; then
apt update && apt install -y $1
apt update && apt install -y "$1"
elif cmd_exists dnf; then
$(get_dnf) install --assumeyes $1
$(get_dnf) install -y "$1" >"$2"
else
echo >&2 "$1 not installed and no package manager not found"
exit 1
fi
}

flock_setup() {
if ! test -d /var/run/lock ; then
mkdir -p /var/run/lock
fi

if ! command -v flock >/dev/null 2>/dev/null; then
case "${ID}" in
fedora)
fedora)
add_package util-linux-core
mkdir -p /var/lock /var/run/lock
;;
*) ;;
*) ;;
esac
fi
}
5 changes: 3 additions & 2 deletions src/xx-dnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

set -e

. $(command -v xx-common)
# shellcheck source=./xx-common
. "$(command -v xx-common)"

flock_setup
if [ -z "$XX_DNF_NOLOCK" ]; then
Expand Down Expand Up @@ -50,7 +51,7 @@ if [ "$XX_OS" = "windows" ]; then
esac
fi

packages=
packages2=
for p in ${packages}; do
if [ "${p}" = "xx-c-essentials" ]; then
p="glibc-devel"
Expand Down
5 changes: 3 additions & 2 deletions src/xx-verify
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

set -e

. $(command -v xx-common)
# shellcheck source=./xx-common
. "$(command -v xx-common)"

flock_setup
if [ -z "$XX_VERIFY_NOLOCK" ]; then
Expand All @@ -22,7 +23,7 @@ done

setup() {
if ! command -v file >/dev/null 2>/dev/null; then
add_package file $1
add_package file "$1"
fi
}

Expand Down

0 comments on commit 5cc79a6

Please sign in to comment.