@@ -17,7 +17,7 @@ function fail {
1717function install {
1818 #settings
1919 USER="{%s r.User %}"
20- PROG= "{%s r.Program %}"
20+ IFS=',' read -r -a PROG_LIST <<< "{%s r.Program %}"
2121 ASPROG="{% if len(r.AsProgram)>0 %} {%s r.AsProgram %} {% endif %}"
2222 MOVE="{%v r.MoveToPath %}"
2323 RELEASE="{%s r.Release %}" # {%s r.ResolvedRelease %}
@@ -93,7 +93,7 @@ function install {
9393 esac
9494 #got URL! download it...
9595 echo -n "{% if r.MoveToPath %}Installing{% else %}Downloading{% endif %}"
96- echo -n " $USER/$PROG "
96+ echo -n " $USER/${PROG_LIST[*]} "
9797 if [ ! -z "$RELEASE" ]; then
9898 echo -n " $RELEASE"
9999 fi
@@ -116,10 +116,10 @@ function install {
116116 cd $TMP_DIR
117117 if [[ $FTYPE = ".gz" ]]; then
118118 which gzip > /dev/null || fail "gzip is not installed"
119- bash -c "$GET $URL" | gzip -d - > $PROG || fail "download failed"
119+ bash -c "$GET $URL" | gzip -d - > "${PROG_LIST[0]}" || fail "download failed"
120120 elif [[ $FTYPE = ".bz2" ]]; then
121121 which bzip2 > /dev/null || fail "bzip2 is not installed"
122- bash -c "$GET $URL" | bzip2 -d - > $PROG || fail "download failed"
122+ bash -c "$GET $URL" | bzip2 -d - > "${PROG_LIST[0]}" || fail "download failed"
123123 elif [[ $FTYPE = ".tar.bz" ]] || [[ $FTYPE = ".tar.bz2" ]]; then
124124 which tar > /dev/null || fail "tar is not installed"
125125 which bzip2 > /dev/null || fail "bzip2 is not installed"
@@ -128,46 +128,39 @@ function install {
128128 which tar > /dev/null || fail "tar is not installed"
129129 which gzip > /dev/null || fail "gzip is not installed"
130130 bash -c "$GET $URL" | tar zxf - || fail "download failed"
131+ elif [[ $FTYPE = ".tar.xz" ]] || [[ $FTYPE = ".tgz" ]]; then
132+ which tar > /dev/null || fail "tar is not installed"
133+ which xz > /dev/null || fail "xz is not installed"
134+ bash -c "$GET $URL" | tar Jxf - || fail "download failed"
131135 elif [[ $FTYPE = ".zip" ]]; then
132136 which unzip > /dev/null || fail "unzip is not installed"
133137 bash -c "$GET $URL" > tmp.zip || fail "download failed"
134138 unzip -o -qq tmp.zip || fail "unzip failed"
135139 rm tmp.zip || fail "cleanup failed"
136140 elif [[ $FTYPE = ".bin" ]]; then
137- bash -c "$GET $URL" > "{%s r.Program % }_${OS}_${ARCH}" || fail "download failed"
141+ bash -c "$GET $URL" > "${PROG_LIST[0] }_${OS}_${ARCH}" || fail "download failed"
138142 else
139143 fail "unknown file type: $FTYPE"
140144 fi
141- #search subtree largest file (bin)
142- TMP_BIN=$(find . -type f | xargs du | sort -n | tail -n 1 | cut -f 2)
143- if [ ! -f "$TMP_BIN" ]; then
144- fail "could not find find binary (largest file)"
145- fi
146- #ensure its larger than 1MB
147- #TODO linux=elf/darwin=macho file detection?
148- if [[ $(du -m $TMP_BIN | cut -f1) -lt 1 ]]; then
149- fail "no binary found ($TMP_BIN is not larger than 1MB)"
150- fi
151- #move into PATH or cwd
152- chmod +x $TMP_BIN || fail "chmod +x failed"
153- DEST="$OUT_DIR/$PROG"
154- if [ ! -z "$ASPROG" ]; then
155- DEST="$OUT_DIR/$ASPROG"
156- fi
157- #move without sudo
158- OUT=$(mv $TMP_BIN $DEST 2>&1)
159- STATUS=$?
160- # failed and string contains "Permission denied"
161- if [ $STATUS -ne 0 ]; then
162- if [[ $OUT =~ "Permission denied" ]]; then
163- echo "mv with sudo..."
164- sudo mv $TMP_BIN $DEST || fail "sudo mv failed"
165- else
166- fail "mv failed ($OUT)"
167- fi
168- fi
169- echo "{% if r.MoveToPath %}Installed at{% else %}Downloaded to{% endif %} $DEST"
170- #done
145+ for PROG in "${PROG_LIST[@]}"; do
146+ BIN_PATH=$(find . -type f | grep -i "$PROG" | head -n 1)
147+ [[ -z "$BIN_PATH" ]] && fail "Binary $PROG not found"
148+
149+ chmod +x "$BIN_PATH" || fail "chmod +x failed on $BIN_PATH"
150+ DEST="$OUT_DIR/$PROG"
151+
152+ OUT=$(mv "$BIN_PATH" "$DEST" 2>&1)
153+ STATUS=$?
154+ if [ $STATUS -ne 0 ]; then
155+ if [[ $OUT =~ "Permission denied" ]]; then
156+ echo "mv with sudo..."
157+ sudo mv "$BIN_PATH" "$DEST" || fail "sudo mv failed for $BIN_PATH"
158+ else
159+ fail "mv failed for $BIN_PATH ($OUT)"
160+ fi
161+ fi
162+ echo "Moved $PROG to $DEST"
163+ done
171164 cleanup
172165}
173166install
0 commit comments