Skip to content

Commit 612d3a8

Browse files
committed
add tar.xz & handle multi program
1 parent 318ab29 commit 612d3a8

File tree

4 files changed

+75
-101
lines changed

4 files changed

+75
-101
lines changed

handler/handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
150150
return
151151
}
152152

153+
// multi program, such: mp=ss_server,ss_client
154+
if len(r.URL.Query().Get("mp")) != 0 {
155+
result.Program = r.URL.Query().Get("mp")
156+
}
153157
switch qtype {
154158
case "json":
155159
w.Header().Set("Content-Type", "application/json")

handler/handler_execute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (h *Handler) getAssetsNoCache(q Query) (string, Assets, error) {
125125
fext = ".bin" // +1MB binary
126126
}
127127
switch fext {
128-
case ".bin", ".zip", ".tar.bz", ".tar.bz2", ".bz2", ".gz", ".tar.gz", ".tgz":
128+
case ".bin", ".zip", ".tar.bz", ".tar.bz2", ".tar.xz", ".bz2", ".gz", ".tar.gz", ".tgz":
129129
// valid
130130
default:
131131
log.Printf("fetched asset has unsupported file type: %s (ext '%s')", ga.Name, fext)

handler/install.sh.qtpl

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function fail {
1717
function 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
}
173166
install

handler/install.sh.qtpl.go

Lines changed: 42 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)