diff --git a/bin/up2k.py b/bin/up2k.py index 1cf94be7..80f5979e 100755 --- a/bin/up2k.py +++ b/bin/up2k.py @@ -1,9 +1,12 @@ #!/usr/bin/env python3 from __future__ import print_function, unicode_literals +S_VERSION = "1.3" +S_BUILD_DT = "2023-03-05" + """ up2k.py: upload to copyparty -2023-03-05, v1.3, ed , MIT-Licensed +2021, ed , MIT-Licensed https://github.com/9001/copyparty/blob/hovudstraum/bin/up2k.py - dependencies: requests @@ -24,6 +27,8 @@ import platform import threading import datetime +EXE = sys.executable.endswith("exe") + try: import argparse except: @@ -34,7 +39,9 @@ except: try: import requests except ImportError: - if sys.version_info > (2, 7): + if EXE: + raise + elif sys.version_info > (2, 7): m = "\nERROR: need 'requests'; please run this command:\n {0} -m pip install --user requests\n" else: m = "requests/2.18.4 urllib3/1.23 chardet/3.0.4 certifi/2020.4.5.1 idna/2.7" @@ -993,8 +1000,13 @@ def main(): cores = (os.cpu_count() if hasattr(os, "cpu_count") else 0) or 2 hcores = min(cores, 3) # 4% faster than 4+ on py3.9 @ r5-4500U + ver = "{}, v{}".format(S_BUILD_DT, S_VERSION) + if "--version" in sys.argv: + print(ver) + return + # fmt: off - ap = app = argparse.ArgumentParser(formatter_class=APF, epilog=""" + ap = app = argparse.ArgumentParser(formatter_class=APF, description="up2k uploader / filesearch tool, " + ver, epilog=""" NOTE: source file/folder selection uses rsync syntax, meaning that: "foo" uploads the entire folder to URL/foo/ @@ -1007,6 +1019,7 @@ source file/folder selection uses rsync syntax, meaning that: ap.add_argument("-a", metavar="PASSWORD", help="password or $filepath") ap.add_argument("-s", action="store_true", help="file-search (disables upload)") ap.add_argument("--ok", action="store_true", help="continue even if some local files are inaccessible") + ap.add_argument("--version", action="store_true", help="show version and exit") ap = app.add_argument_group("compatibility") ap.add_argument("--cls", action="store_true", help="clear screen before start") @@ -1030,7 +1043,16 @@ source file/folder selection uses rsync syntax, meaning that: ap.add_argument("-td", action="store_true", help="disable certificate check") # fmt: on - ar = app.parse_args() + try: + ar = app.parse_args() + finally: + if EXE and not sys.argv[1:]: + print("*** hit enter to exit ***") + try: + input() + except: + pass + if ar.drd: ar.dr = True diff --git a/scripts/pyinstaller/README.md b/scripts/pyinstaller/README.md index af8eb618..019cf751 100644 --- a/scripts/pyinstaller/README.md +++ b/scripts/pyinstaller/README.md @@ -1,7 +1,9 @@ -builds a fully standalone copyparty.exe compatible with 32bit win7-sp1 and later +builds copyparty32.exe, fully standalone, compatible with 32bit win7-sp1 and later requires a win7 vm which has never been connected to the internet and a host-only network with the linux host at 192.168.123.1 +copyparty.exe is built by a win10-ltsc-2021 vm with similar setup + first-time setup steps in notes.txt run build.sh in the vm to fetch src + compile + push a new exe to the linux host for manual publishing diff --git a/scripts/pyinstaller/build.sh b/scripts/pyinstaller/build.sh index 0f7cd029..2f5d9e5c 100644 --- a/scripts/pyinstaller/build.sh +++ b/scripts/pyinstaller/build.sh @@ -9,6 +9,8 @@ tee build2.sh | cmp build.sh && rm build2.sh || { [[ $r =~ [yY] ]] && mv build{2,}.sh && exec ./build.sh } +./up2k.sh + uname -s | grep WOW64 && m= || m=32 uname -s | grep NT-10 && w10=1 || w7=1 [ $w7 ] && pyv=37 || pyv=311 diff --git a/scripts/pyinstaller/deps.sha512 b/scripts/pyinstaller/deps.sha512 index 11248a60..fd153a08 100644 --- a/scripts/pyinstaller/deps.sha512 +++ b/scripts/pyinstaller/deps.sha512 @@ -7,6 +7,12 @@ adf0d23a98da38056de25e07e68921739173efc70fb9bf3f68d8c7c3d0d092e09efa69d35c0c9ecc 132a5380f33a245f2e744413a0e1090bc42b7356376de5121397cec5976b04b79f7c9ebe28af222c9c7b01461f7d7920810d220e337694727e0d7cd9e91fa667 pywin32_ctypes-0.2.0-py2.py3-none-any.whl 3c5adf0a36516d284a2ede363051edc1bcc9df925c5a8a9fa2e03cab579dd8d847fdad42f7fd5ba35992e08234c97d2dbfec40a9d12eec61c8dc03758f2bd88e typing_extensions-4.4.0-py3-none-any.whl 4b6e9ae967a769fe32be8cf0bc0d5a213b138d1e0344e97656d08a3d15578d81c06c45b334c872009db2db8f39db0c77c94ff6c35168d5e13801917667c08678 upx-4.0.2-win32.zip +# up2k (win7) +a7d259277af4948bf960682bc9fb45a44b9ae9a19763c8a7c313cef4aa9ec2d447d843e4a7c409e9312c8c8f863a24487a8ee4ffa6891e9b1c4e111bb4723861 certifi-2022.12.7-py3-none-any.whl +2822c0dae180b1c8cfb7a70c8c00bad62af9afdbb18b656236680def9d3f1fcdcb8ef5eb64fc3b4c934385cd175ad5992a2284bcba78a243130de75b2d1650db charset_normalizer-3.1.0-cp37-cp37m-win32.whl +ffdd45326f4e91c02714f7a944cbcc2fdd09299f709cfa8aec0892053eef0134fb80d9ba3790afd319538a86feb619037cbf533e2f5939cb56b35bb17f56c858 idna-3.4-py3-none-any.whl +220e0e122d5851aaccf633224dd7fbd3ba8c8d2720944d8019d6a276ed818d83e3426fe21807f22d673b5428f19fcf9a6b4e645f69bbecd967c568bb6aeb7c8d requests-2.28.2-py3-none-any.whl +8770011f4ad1fe40a3062e6cdf1fda431530c59ee7de3fc5f8c57db54bfdb71c3aa220ca0e0bb1874fc6700e9ebb57defbae54ac84938bc9ad8f074910106681 urllib3-1.26.14-py2.py3-none-any.whl # win7 91c025f7d94bcdf93df838fab67053165a414fc84e8496f92ecbb910dd55f6b6af5e360bbd051444066880c5a6877e75157bd95e150ead46e5c605930dfc50f2 future-0.18.2.tar.gz c06b3295d1d0b0f0a6f9a6cd0be861b9b643b4a5ea37857f0bd41c45deaf27bb927b71922dab74e633e43d75d04a9bd0d1c4ad875569740b0f2a98dd2bfa5113 importlib_metadata-5.0.0-py3-none-any.whl diff --git a/scripts/pyinstaller/deps.txt b/scripts/pyinstaller/deps.txt index b7200279..b33280b7 100644 --- a/scripts/pyinstaller/deps.txt +++ b/scripts/pyinstaller/deps.txt @@ -13,6 +13,13 @@ https://pypi.org/project/MarkupSafe/#files https://pypi.org/project/mutagen/#files https://pypi.org/project/Pillow/#files +# up2k (win7) additionals +https://pypi.org/project/certifi/#files +https://pypi.org/project/charset-normalizer/#files # cp37-cp37m-win32.whl +https://pypi.org/project/idna/#files +https://pypi.org/project/requests/#files +https://pypi.org/project/urllib3/#files + # win7 additionals https://pypi.org/project/future/#files https://pypi.org/project/importlib-metadata/#files diff --git a/scripts/pyinstaller/icon.sh b/scripts/pyinstaller/icon.sh index 8877e143..27858e7e 100755 --- a/scripts/pyinstaller/icon.sh +++ b/scripts/pyinstaller/icon.sh @@ -1,8 +1,10 @@ #!/bin/bash set -e +genico() { + # imagemagick png compression is broken, use pillow instead -convert ~/AndroidStudioProjects/PartyUP/metadata/en-US/images/icon.png a.bmp +convert $1 a.bmp #convert a.bmp -trim -resize '48x48!' -strip a.png python3 <<'EOF' @@ -17,11 +19,15 @@ EOF pngquant --strip --quality 30 a.png mv a-*.png a.png -python3 <<'EOF' +python3 < $APPDATA/python/python37/site-packages/requests/certs.py + sed -ri 's/^(DEFAULT_CA_BUNDLE_PATH = ).*/\1""/' $APPDATA/python/python37/site-packages/requests/utils.py + sed -ri '/^import zipfile$/d' $APPDATA/python/python37/site-packages/requests/utils.py + sed -ri 's/"idna"//' $APPDATA/python/python37/site-packages/requests/packages.py + sed -ri 's/import charset_normalizer.*/pass/' $APPDATA/python/python37/site-packages/requests/compat.py + sed -ri 's/raise.*charset_normalizer.*/pass/' $APPDATA/python/python37/site-packages/requests/__init__.py + sed -ri 's/import charset_normalizer.*//' $APPDATA/python/python37/site-packages/requests/packages.py + sed -ri 's/chardet.__name__/"\\roll\\tide"/' $APPDATA/python/python37/site-packages/requests/packages.py + sed -ri 's/chardet,//' $APPDATA/python/python37/site-packages/requests/models.py + for n in util/__init__.py connection.py; do awk -i inplace '/^from (\.util)?\.ssl_ /{s=1} !s; /^\)/{s=0}' $APPDATA/python/python37/site-packages/urllib3/$n; done + sed -ri 's/^from .ssl_ import .*//' $APPDATA/python/python37/site-packages/urllib3/util/proxy.py + echo golfed +} + +read a b _ < <(awk -F\" '/^S_VERSION =/{$0=$2;sub(/\./," ");print}' < up2k.py) +sed -r 's/1,2,3,0/'$a,$b,0,0'/;s/1\.2\.3/'$a.$b.0/ up2k.rc2 + +#python uncomment.py up2k.py +$APPDATA/python/python37/scripts/pyinstaller -y --clean --upx-dir=. up2k.spec + +./dist/up2k.exe --version + +curl -fkT dist/up2k.exe -HPW:wark https://192.168.123.1:3923/ diff --git a/scripts/pyinstaller/up2k.spec b/scripts/pyinstaller/up2k.spec new file mode 100644 index 00000000..1b88e35d --- /dev/null +++ b/scripts/pyinstaller/up2k.spec @@ -0,0 +1,78 @@ +# -*- mode: python ; coding: utf-8 -*- + + +block_cipher = None + + +a = Analysis( + ['up2k.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[ + 'ftplib', + 'lzma', + 'pickle', + 'ssl', + 'tarfile', + 'bz2', + 'zipfile', + 'tracemalloc', + 'zlib', + 'urllib3.util.ssl_', + 'urllib3.contrib.pyopenssl', + 'urllib3.contrib.socks', + 'certifi', + 'idna', + 'chardet', + 'charset_normalizer', + 'email.contentmanager', + 'email.policy', + 'encodings.zlib_codec', + 'encodings.base64_codec', + 'encodings.bz2_codec', + 'encodings.charmap', + 'encodings.hex_codec', + 'encodings.palmos', + 'encodings.punycode', + 'encodings.rot_13', + ], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False, +) + +# this is the only change to the autogenerated specfile: +xdll = ["libcrypto-1_1.dll"] +a.binaries = TOC([x for x in a.binaries if x[0] not in xdll]) + +pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='up2k', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, + version='up2k.rc2', + icon=['up2k.ico'], +) diff --git a/scripts/pyinstaller/up2k.spec.sh b/scripts/pyinstaller/up2k.spec.sh new file mode 100644 index 00000000..838dadc2 --- /dev/null +++ b/scripts/pyinstaller/up2k.spec.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +# grep '">encodings.cp' C:/Users/ed/dev/copyparty/bin/dist/xref-up2k.html | sed -r 's/.*encodings.cp//;s/<.*//' | sort -n | uniq | tr '\n' , +# grep -i encodings -A1 build/up2k/xref-up2k.html | sed -r 's/.*(Missing|Excluded)Module.*//' | grep moduletype -B1 | grep -v moduletype + +ex=( + ftplib lzma pickle ssl tarfile bz2 zipfile tracemalloc zlib + urllib3.util.ssl_ urllib3.contrib.pyopenssl urllib3.contrib.socks certifi idna chardet charset_normalizer + email.contentmanager email.policy + encodings.{zlib_codec,base64_codec,bz2_codec,charmap,hex_codec,palmos,punycode,rot_13} +); +cex=(); for a in "${ex[@]}"; do cex+=(--exclude "$a"); done +$APPDATA/python/python37/scripts/pyi-makespec --version-file up2k.rc2 -i up2k.ico -n up2k -c -F up2k.py "${cex[@]}"