add cursed sfx packer

This commit is contained in:
ed 2020-04-26 23:31:55 +02:00
parent 836463bab2
commit fc5c815824
3 changed files with 123 additions and 10 deletions

1
.gitignore vendored
View file

@ -8,6 +8,7 @@ copyparty.egg-info/
buildenv/ buildenv/
build/ build/
dist/ dist/
sfx/
.venv/ .venv/
# sublime # sublime

View file

@ -2,6 +2,7 @@
set -e set -e
echo echo
tar=$( which gtar 2>/dev/null || which tar)
sed=$( which gsed 2>/dev/null || which sed) sed=$( which gsed 2>/dev/null || which sed)
find=$(which gfind 2>/dev/null || which find) find=$(which gfind 2>/dev/null || which find)
sort=$(which gsort 2>/dev/null || which sort) sort=$(which gsort 2>/dev/null || which sort)
@ -22,14 +23,14 @@ ver="$1"
[[ -e copyparty/__main__.py ]] || cd .. [[ -e copyparty/__main__.py ]] || cd ..
[[ -e copyparty/__main__.py ]] || [[ -e copyparty/__main__.py ]] ||
{ {
echo "run me from within the copyparty folder" echo "run me from within the project root folder"
echo echo
exit 1 exit 1
} }
out_dir="$(pwd | $sed -r 's@/[^/]+$@@')" mkdir -p dist
zip_path="$out_dir/copyparty-$ver.zip" zip_path="dist/copyparty-$ver.zip"
tgz_path="$out_dir/copyparty-$ver.tar.gz" tgz_path="dist/copyparty-$ver.tar.gz"
[[ -e "$zip_path" ]] || [[ -e "$zip_path" ]] ||
[[ -e "$tgz_path" ]] && [[ -e "$tgz_path" ]] &&
@ -50,9 +51,11 @@ tmp="$(mktemp -d)"
rls_dir="$tmp/copyparty-$ver" rls_dir="$tmp/copyparty-$ver"
mkdir "$rls_dir" mkdir "$rls_dir"
echo ">>> export" echo ">>> export from git"
git archive master | git archive master | $tar -xC "$rls_dir"
tar -x -C "$rls_dir"
echo ">>> export untracked deps"
$tar -c copyparty/web/deps | $tar -xC "$rls_dir"
cd "$rls_dir" cd "$rls_dir"
$find -type d -exec chmod 755 '{}' \+ $find -type d -exec chmod 755 '{}' \+
@ -60,7 +63,7 @@ $find -type f -exec chmod 644 '{}' \+
commaver="$( commaver="$(
printf '%s\n' "$ver" | printf '%s\n' "$ver" |
sed -r 's/\./,/g' sed -r 's/\./, /g'
)" )"
grep -qE "^VERSION *= \(${commaver}\)$" copyparty/__version__.py || grep -qE "^VERSION *= \(${commaver}\)$" copyparty/__version__.py ||
@ -93,7 +96,7 @@ $sed -r 's/^(.{32}) \./\1 ./' > ../.sums.md5
mv ../.sums.md5 . mv ../.sums.md5 .
cd .. cd ..
echo ">>> tar"; tar -czf "$tgz_path" "copyparty-$ver" echo ">>> tar"; $tar -czf "$tgz_path" "copyparty-$ver"
echo ">>> zip"; zip -qr "$zip_path" "copyparty-$ver" echo ">>> zip"; zip -qr "$zip_path" "copyparty-$ver"
rm -rf "$tmp" rm -rf "$tmp"

109
scripts/make-unix-sfx.sh Normal file
View file

@ -0,0 +1,109 @@
#!/bin/bash
set -e
echo
# clean=1 to export clean files from git;
# will use current working tree otherwise
clean=1
clean=
tar=$( which gtar 2>/dev/null || which tar)
sed=$( which gsed 2>/dev/null || which sed)
find=$(which gfind 2>/dev/null || which find)
sort=$(which gsort 2>/dev/null || which sort)
which md5sum 2>/dev/null >/dev/null &&
md5sum=md5sum ||
md5sum="md5 -r"
[[ -e copyparty/__main__.py ]] || cd ..
[[ -e copyparty/__main__.py ]] ||
{
echo "run me from within the project root folder"
echo
exit 1
}
rm -rf sfx
mkdir sfx
cd sfx
f=~/Downloads/Jinja2-2.6.tar.gz
[ -e "$f" ] ||
(cd ~/Downloads && wget https://files.pythonhosted.org/packages/25/c8/212b1c2fd6df9eaf536384b6c6619c4e70a3afd2dffdd00e5296ffbae940/Jinja2-2.6.tar.gz)
tar -xf $f
mv Jinja2-*/jinja2 .
rm -rf Jinja2-*
[ $clean ] && {
(cd .. && git archive master) | tar -x copyparty
(cd .. && tar -c copyparty/web/deps) | tar -x
}
[ $clean ] ||
(cd .. && tar -c copyparty) | tar -x
ver="$(awk '/^VERSION *= \(/ {
gsub(/[^0-9,]/,""); gsub(/,/,"."); print; exit}' < ../copyparty/__version__.py)"
ts=$(date -u +%s)
hts=$(date -u +%Y-%m%d-%H%M%S) # --date=@$ts (thx osx)
echo h > v$ts
mkdir -p ../dist
sfx_out=../dist/copyparty-$ver.sfx
sed "s/PACK_TS/$ts/; s/PACK_HTS/$hts/; s/CPP_VER/$ver/" >$sfx_out <<'EOF'
#!/bin/bash
set -e
dir="$(
printf '%s\n' "$TMPDIR" /tmp |
awk '/./ {print; exit}'
)/pe-copyparty"
py="$(command -v python3)" ||
py="$(command -v python)" ||
py="$(command -v python2)" || {
printf '\033[1;31mpls install python\033[0m\n' >&2
exit 1
}
[ -e "$dir/vPACK_TS" ] || (
printf '\033[36munpacking copyparty vCPP_VER (sfx-PACK_HTS)\033[1;30m\n\n'
mkdir -p "$dir.$$"
ofs=$(awk '$0=="sfx_eof" {print NR+1; exit}' < "$0")
[ -z "$ofs" ] && {
printf '\033[31mabort: could not find SFX boundary\033[0m\n'
exit 1
}
tail -n +$ofs "$0" | tar -JxC "$dir.$$"
ln -nsf "$dir.$$" "$dir"
printf '\033[0m'
now=$(date -u +%s)
for d in "$dir".*; do
ts=$(stat -c%Y -- "$d")
[ $((now-ts)) -gt 300 ] &&
rm -rf "$d"
done
# delete the bundled jinja2 if we have a better one
python3 -c 'import jinja2' 2>/dev/null &&
rm -rf $dir/jinja2
true
) >&2 || exit 1
PYTHONPATH=$dir exec "$py" -m copyparty "$@"
sfx_eof
EOF
echo "compressing..."
tar -c copyparty jinja2 v$ts | xz -cze9T0 >> $sfx_out
chmod 755 $sfx_out
printf "done:\n %s\n" "$(realpath $sfx_out)"
cd ..
rm -rf sfx