Skip to content

Commit

Permalink
setup-util: fix .deb urls failing in apt, fix .deb files/urls failing…
Browse files Browse the repository at this point in the history
… uninstall in dpkg
  • Loading branch information
balupton committed Sep 6, 2023
1 parent 778561e commit 6a2f1a2
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions commands/setup-util
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,8 @@ function setup_util() (
# Debian

# apt / Ubuntu / Debian / Linux Mint / elementary OS / etc
# installs remote .deb packages
# supports installing/uninstalling aplitude deb packages
# supports installing/uninstalling downloaded .deb files
# sucessor to aptitude
# https://wiki.debian.org/Apt
function do_apt_key_fetch {
Expand All @@ -1121,7 +1122,7 @@ function setup_util() (
fi
}
function do_apt {
local args=() packages=() repo="$APT_REPO" key="$APT_KEY" id="$APT_ID" keyring=''
local args=() packages=() repo="$APT_REPO" key="$APT_KEY" id="$APT_ID" keyring='' download_index download_url download_filepath
if test "${#APT[@]}" -ne 0; then
packages+=("${APT[@]}")
elif test "${#DEB[@]}" -ne 0; then
Expand Down Expand Up @@ -1312,17 +1313,30 @@ function setup_util() (
)
fi

# convert urls to local
for download_index in "${!packages[@]}"; do
download_url="${packages[download_index]}"
if [[ $download_url == 'http'* ]]; then
# fetch temp path
download_filepath="$(fs-temp --touch --directory='setup-util' --file="$name.deb")"
# download to temp path
down --filepath="$download_filepath" "$download_url"
# apt supports .deb packages for install and uninstall
packages[download_index]="$download_filepath"
fi
done

# packages
# use `apt-get`, as `apt` produces this warning on Ubuntu 20.04.3 LTS
# WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
sudo-helper -- "${args[@]}" "${packages[@]}"
}

# dpkg / Debian / Ubuntu / Linux Mint / elementary OS / etc
# installs local .deb files, and with our helper, remote .deb files
# supports installing/uninstalling downloaded .deb files
# https://man7.org/linux/man-pages/man1/dpkg.1.html
function do_dpkg {
local args=() packages=() i=0 download_filepath='' url=''
local args=() packages=() download_index download_filepath download_url
if test "${#DPKG[@]}" -ne 0; then
packages+=("${DPKG[@]}")
elif test "${#DEB[@]}" -ne 0; then
Expand Down Expand Up @@ -1351,16 +1365,29 @@ function setup_util() (
)
fi

# dependencies
if test "$action" = 'uninstall'; then
source "$DOROTHY/sources/ripgrep.bash"
fi

# convert urls to local
for i in "${!packages[@]}"; do
url="${packages[i]}"
if [[ $url == 'http'* ]]; then
for download_index in "${!packages[@]}"; do
download_url="${packages[download_index]}"
if [[ $download_url == 'http'* ]]; then
# fetch temp path
download_filepath="$(fs-temp --touch --directory='setup-util' --file="$name.deb")"
# download to temp path
down --filepath="$download_filepath" "$url"
# update packge with its download path
packages[i]="$download_filepath"
down --filepath="$download_filepath" "$download_url"
# adjust the cmd
if test "$action" = 'uninstall'; then
# if uninstalling, use the package name
packages[download_index]="$(
dpkg -I "$download_filepath" | rg -o --regexp='Package:\s+(.+)' --replace='$1'
)"
else
# update packge with its download path if installing
packages[download_index]="$download_filepath"
fi
fi
done

Expand Down

0 comments on commit 6a2f1a2

Please sign in to comment.