-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupx.sh
executable file
·109 lines (88 loc) · 2.18 KB
/
upx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# a wrapper for "post-run" build scripts
# see also https://github.com/rust-lang/cargo/issues/545
tmp=$(mktemp || exit)
trap "rm $tmp" EXIT
cat > $tmp <<"EOF"
prepare() {
local upxdir="${TMPDIR:-/tmp}/.upx.d3dee1232d4324c2"
mkdir -p "$upxdir"
local upx_found=no
for p in $( find "${upxdir}" \( -name upx -or -name upx.exe \) -exec dirname '{}' \; )
do
export PATH="${p}:$PATH"
upx_found=yes
done
if test "$upx_found" != 'yes'
then
if ! test -z "$UPX_GNUTAR_DOWNLOAD_URL"
then
cd $upxdir
curl "$UPX_GNUTAR_DOWNLOAD_URL" -v -L -o upx.tar.xx || return
tar vvxf upx.tar.xx || return
for p in $( find "${upxdir}" \( -name upx \) -exec dirname '{}' \; )
do
export PATH="${p}:$PATH"
done
hash -r
return
elif ! test -z "$UPX_ZIP_DOWNLOAD_URL"
then
cd $upxdir
curl "$UPX_ZIP_DOWNLOAD_URL" -v -L -o upx.zip || return
unzip upx.zip || return
for p in $( find "${upxdir}" \( -name upx.exe \) -exec dirname '{}' \; )
do
export PATH="${p}:$PATH"
done
hash -r
return
fi
else
return
fi
if type sudo
then
if type apt
then
sudo apt install -y upx && return
fi
# disable in macos
return 1
if type brew
then
brew install upx && return
fi
if type port
then
sudo port install upx && return
fi
fi
if type choco
then
choco install -y upx && return
fi
if type winget
then
winget install upx && return
fi
}
if test -z "$UPX_DISABLE"
then
prepare
echo $PATH
if type upx
then
upx --best --lzma $1 && exit
fi
fi
echo failed to compress binary size by upx, fallback to strip if binary too large...
if test "$(cat $1 | wc -c)" -gt 20971520 # 20M
then
strip $1
fi
EOF
command $@
status_code="$?"
find "$(realpath ./target/)" \( -name hitdns -or -name hitdns.exe \) -exec bash --norc -x $tmp '{}' \;
exit "$status_code"