This commit is contained in:
hl committed 2024-11-18 06:09:15 +08:00
1 parent def1388ca2
commit 6232d9e331
1 file changed
+42 -21
+42 -21
View File
@@ -6,6 +6,7 @@ DEFAULT_MATCH_STAGE_1="browser_download_url"
main(){ main(){
echo
if [ -z "$REPO" ] && [ -z "$DD_URL" ]; then if [ -z "$REPO" ] && [ -z "$DD_URL" ]; then
usage usage
exit 1 exit 1
@@ -13,17 +14,19 @@ main(){
if [ -z "$DD_URL" ]; then if [ -z "$DD_URL" ]; then
echo "Query for $REPO" echo "Query for $REPO"
echo echo
api_url="https://api.github.com/repos/$REPO/releases/$TAG" if $VERBOSE; then
echo "API: $api_url" api_url="https://api.github.com/repos/$REPO/releases/$TAG"
echo echo "API: $api_url"
candidates=$(curl $SET_AUTH $SET_PROXY -sSfL "$api_url" | grep -P "$MATCH_STAGE_1") echo
echo "Candidates:" candidates=$(curl $SET_AUTH $SET_PROXY -sSfL "$api_url" | grep -P "$MATCH_STAGE_1")
echo "$candidates" echo "Candidates:"
echo echo "$candidates"
dl_url=$(echo "$candidates" | grep -P "$MATCH_STAGE_2" | cut -d '"' -f 4) echo
echo "From:" dl_url=$(echo "$candidates" | grep -P "$MATCH_STAGE_2" | cut -d '"' -f 4)
echo "$dl_url" echo "From:"
echo echo "$dl_url"
echo
fi
else else
dl_url="$DD_URL" dl_url="$DD_URL"
fi fi
@@ -52,15 +55,15 @@ main(){
else else
if (echo $ext | grep -i zip) &>/dev/null; then if (echo $ext | grep -i zip) &>/dev/null; then
curl $SET_AUTH $SET_PROXY -SfLo source_pkg.zip "$dl_url" curl $SET_AUTH $SET_PROXY -SfLo source_pkg.zip "$dl_url"
unzip -o source_pkg.zip unzip -o source_pkg.zip >/dev/null
dirname=$(rev <<< "$pkgname" | cut -d '.' -f 2- | rev) dirname=$(rev <<< "$pkgname" | cut -d '.' -f 2- | rev)
elif (echo $ext | grep -i tar) || (echo $ext | grep -i tgz) &>/dev/null; then elif (echo $ext | grep -i tar) || (echo $ext | grep -i tgz) &>/dev/null; then
curl $SET_AUTH $SET_PROXY -SfLo source_pkg.$ext "$dl_url" curl $SET_AUTH $SET_PROXY -SfLo source_pkg.$ext "$dl_url"
tar -xvf source_pkg.$ext tar -xvf source_pkg.$ext >/dev/null
dirname=$(rev <<< "$pkgname" | cut -d '.' -f 2- | rev) dirname=$(rev <<< "$pkgname" | cut -d '.' -f 2- | rev)
elif (echo $ext_tar | grep -i tar) &>/dev/null; then elif (echo $ext_tar | grep -i tar) &>/dev/null; then
curl $SET_AUTH $SET_PROXY -SfLo source_pkg.tar.$ext "$dl_url" curl $SET_AUTH $SET_PROXY -SfLo source_pkg.tar.$ext "$dl_url"
tar -xvf source_pkg.tar.$ext tar -xvf source_pkg.tar.$ext >/dev/null
dirname=$(rev <<< "$pkgname" | cut -d '.' -f 3- | rev) dirname=$(rev <<< "$pkgname" | cut -d '.' -f 3- | rev)
else else
echo "Unknown format: $pkgname" echo "Unknown format: $pkgname"
@@ -72,16 +75,27 @@ main(){
rm source_pkg.* rm source_pkg.*
fi fi
if [ ! -z "$PKG_DIR" ]; then if [ ! -z "$PKG_DIR" ]; then
echo if $VERBOSE; then
echo "Source dir:" echo
echo "Source dir:"
fi
if [ "$PKG_DIR" = "-" ]; then if [ "$PKG_DIR" = "-" ]; then
if [ -z $SED_EXP ]; then if [ -z $SED_EXP ]; then
echo "$dirname" current_dir=$dirname
cd "$dirname"
else else
current_dir=$(echo $dirname | sed -E $SED_EXP) current_dir=$(echo $dirname | sed -E $SED_EXP)
echo "$current_dir" fi
if [ -d "$current_dir" ]; then
if $VERBOSE; then
echo "$current_dir"
fi
cd "$current_dir" cd "$current_dir"
else
else
echo "Wrong dir inside package!"
popd >/dev/null
rm -rf "$tmp_dir"
exit 1
fi fi
else else
indices=($PKG_DIR) indices=($PKG_DIR)
@@ -94,7 +108,9 @@ main(){
current_dir=$index current_dir=$index
fi fi
if [ -d "$current_dir" ]; then if [ -d "$current_dir" ]; then
echo "$current_dir" if $VERBOSE; then
echo "$current_dir"
fi
cd "$current_dir" cd "$current_dir"
else else
echo "Wrong dir inside package!" echo "Wrong dir inside package!"
@@ -179,6 +195,7 @@ usage(){
echo " string as name"; echo " string as name";
echo " -e <EXP> Expression for sed (only for '-d -')"; echo " -e <EXP> Expression for sed (only for '-d -')";
echo " -c <COMMAND> Command for reload"; echo " -c <COMMAND> Command for reload";
echo " -q Quite";
echo " -a <USER:PASS> Auth user[:pass]"; echo " -a <USER:PASS> Auth user[:pass]";
echo " -x <PROXY> Proxy [protocol://]host[:port]"; echo " -x <PROXY> Proxy [protocol://]host[:port]";
} }
@@ -196,9 +213,10 @@ PKG_NAME=
PKG_DIR= PKG_DIR=
SED_EXP= SED_EXP=
CMD_RELOAD= CMD_RELOAD=
VERBOSE=true
SET_AUTH= SET_AUTH=
SET_PROXY= SET_PROXY=
while getopts ":r:t:k:m:u:bp:n:fo:d:e:c:a:x:" OPT; do while getopts ":r:t:k:m:u:bp:n:fo:d:e:c:qa:x:" OPT; do
case $OPT in case $OPT in
r) r)
REPO=$OPTARG; REPO=$OPTARG;
@@ -239,6 +257,9 @@ while getopts ":r:t:k:m:u:bp:n:fo:d:e:c:a:x:" OPT; do
c) c)
CMD_RELOAD=$OPTARG; CMD_RELOAD=$OPTARG;
;; ;;
q)
VERBOSE=false;
;;
a) a)
SET_AUTH="-u $OPTARG"; SET_AUTH="-u $OPTARG";
;; ;;