Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix tgz download failures not treated as errors #154

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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