Skip to content

Commit

Permalink
Merge pull request #154 from killjoy1221/fix/install-4xx
Browse files Browse the repository at this point in the history
Fix tgz download failures not treated as errors
  • Loading branch information
josegonzalez committed May 19, 2024
2 parents b3e7e14 + 419795a commit 40ffaac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
21 changes: 11 additions & 10 deletions bashenv/plugn.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version() {
install() {
declare desc="Install a new plugin from a Git URL"
declare url="$1" name="$2"
local basefilename downloader args contents_dirs contents_files cwd
local basefilename downloader contents_dirs contents_files cwd

basefilename="${url##*/}"
if [[ -z "$name" ]]; then
Expand All @@ -17,22 +17,23 @@ install() {

pushd "$PLUGIN_PATH/available" &>/dev/null
if [[ "$basefilename" == *.tar.gz ]] || [[ "$basefilename" == *.tgz ]]; then
which curl > /dev/null 2>&1 && downloader="curl" && args=(-sL)
which wget > /dev/null 2>&1 && downloader="wget" && args=(-q --max-redirect=1 -O-)

if [[ -z "$downloader" ]]; then
if [[ -n "$(type -p curl)" ]]; then
downloader=(curl -sfL)
elif [[ -n "$(type -p wget)" ]]; then
downloader=(wget -q --max-redirect=1 -O-)
else
echo "Please install either curl or wget to install via tar.gz" 1>&2
exit 1
fi
mkdir -p "$name" && \
"$downloader" "${args[@]}" "$url" | tar xz -C "$name" && \
pushd "$name" &>/dev/null
mkdir -p "$name"
command "${downloader[@]}" "$url" | tar xz -C "$name"
pushd "$name" &>/dev/null
# make sure we untarred a single dir into our target
mapfile -t contents_dirs < <(find . -maxdepth 1 -not -path '.' -type d)
mapfile -t contents_files < <(find . -maxdepth 1 -type f)
if [[ "${#contents_dirs[@]}" -eq 1 ]] && [[ "${#contents_files[@]}" -eq 0 ]]; then
pushd ./* &>/dev/null && \
find . -maxdepth 1 -not -path '.' -exec mv -f {} ../ \;
pushd ./* &>/dev/null
find . -maxdepth 1 -not -path '.' -exec mv -f {} ../ \;
cwd="$PWD"
popd &>/dev/null
rmdir "$cwd"
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ T_plugn-install-enable-disable-targz() {
plugn list | grep disabled | grep smoke-test-plugin"
}

T_plugn-install-enable-disable-targz-404() {
plugn-test-fail "test-install-targz-404" "
plugn init && \
plugn install https://github.com/dokku/smoke-test-plugin/archive/notfound.tar.gz smoke-test-plugin"
}

T_plugn-install-twice() {
url="https://github.com/dokku/smoke-test-plugin"
plugn-test-pass "test-install-twice" "
Expand Down

0 comments on commit 40ffaac

Please sign in to comment.