From 4e2a44e392305752a1e62d5dc0b60b3efcfb5ac6 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Mon, 18 Apr 2022 15:37:35 +0800 Subject: [PATCH] package script --- DEBIAN/postinst | 19 +++++++++++ DEBIAN/postrm | 11 +++++++ DEBIAN/preinst | 16 +++++++++ DEBIAN/prerm | 16 +++++++++ build.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ rustdesk.service | 16 +++++++++ 6 files changed, 164 insertions(+) create mode 100644 DEBIAN/postinst create mode 100644 DEBIAN/postrm create mode 100644 DEBIAN/preinst create mode 100644 DEBIAN/prerm create mode 100644 build.py create mode 100644 rustdesk.service diff --git a/DEBIAN/postinst b/DEBIAN/postinst new file mode 100644 index 000000000..f9f5e9d9a --- /dev/null +++ b/DEBIAN/postinst @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +if [ "$1" = configure ]; then + + INITSYS=$(ls -al /proc/1/exe | awk -F' ' '{print $NF}' | awk -F'/' '{print $NF}') + + if [ "systemd" == "$INITSYS" ]; then + if [ -e /etc/systemd/system/rustdesk.service ]; then + rm /etc/systemd/system/rustdesk.service + fi + sudo -H pip3 install pynput + cp /usr/share/rustdesk/files/systemd/rustdesk.service /etc/systemd/system/rustdesk.service + systemctl daemon-reload + systemctl enable rustdesk + systemctl start rustdesk + fi +fi diff --git a/DEBIAN/postrm b/DEBIAN/postrm new file mode 100644 index 000000000..003a1529a --- /dev/null +++ b/DEBIAN/postrm @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +case $1 in + purge) + rm -rf /root/.config/rustdesk || true + ;; +esac + +exit 0 diff --git a/DEBIAN/preinst b/DEBIAN/preinst new file mode 100644 index 000000000..8b73e9962 --- /dev/null +++ b/DEBIAN/preinst @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +case $1 in + install|upgrade) + INITSYS=$(ls -al /proc/1/exe | awk -F' ' '{print $NF}' | awk -F'/' '{print $NF}') + if [ "systemd" == "${INITSYS}" ]; then + service rustdesk stop || true + sleep 1 + rm -rf /usr/bin/libsciter-gtk.so + fi + ;; +esac + +exit 0 diff --git a/DEBIAN/prerm b/DEBIAN/prerm new file mode 100644 index 000000000..865b689ab --- /dev/null +++ b/DEBIAN/prerm @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +case $1 in + remove|upgrade) + INITSYS=$(ls -al /proc/1/exe | awk -F' ' '{print $NF}' | awk -F'/' '{print $NF}') + if [ "systemd" == "${INITSYS}" ]; then + systemctl stop rustdesk || true + systemctl disable rustdesk || true + rm /etc/systemd/system/rustdesk.service || true + fi + ;; +esac + +exit 0 diff --git a/build.py b/build.py new file mode 100644 index 000000000..cf19b1d72 --- /dev/null +++ b/build.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 + +import os +import platform +import zlib +from shutil import copy2 +import hashlib + +windows = platform.platform().startswith('Windows') +osx = platform.platform().startswith('Darwin') or platform.platform().startswith("macOS") +hbb_name = 'rustdesk' + ('.exe' if windows else '') +exe_path = 'target/release/' + hbb_name + + +def get_version(): + with open("Cargo.toml") as fh: + for line in fh: + if line.startswith("version"): + return line.replace("version", "").replace("=", "").replace('"', '').strip() + return '' + + +def main(): + os.system("cp Cargo.toml Cargo.toml.bk") + os.system("cp src/main.rs src/main.rs.bk") + if windows: + txt = open('src/main.rs', encoding='utf8').read() + with open('src/main.rs', 'wt', encoding='utf8') as fh: + fh.write(txt.replace( + '//#![windows_subsystem', '#![windows_subsystem')) + if os.path.exists(exe_path): + os.unlink(exe_path) + os.system('python3 inline-sciter.py') + if os.path.isfile('/usr/bin/pacman'): + os.system('git checkout src/ui/common.tis') + txt = open('Cargo.toml').read() + with open('Cargo.toml', 'wt') as fh: + fh.write(txt.replace('#lto', 'lto') + .replace('#codegen', 'codegen') + .replace('#panic', 'panic')) + version = get_version() + if windows: + os.system('cargo build --release --features inline') + # os.system('upx.exe target/release/rustdesk.exe') + os.system('mv target/release/rustdesk.exe target/release/RustDesk.exe') + pa = os.environ['P'] + os.system('signtool sign /a /v /p %s /debug /f .\\cert.pfx /t http://timestamp.digicert.com target\\release\\rustdesk.exe'%pa) + os.system('cp -rf target/release/RustDesk.exe rustdesk-%s-putes.exe'%version) + else: + os.system('cargo bundle --release --features inline') + if osx: + os.system( + 'strip target/release/bundle/osx/RustDesk.app/Contents/MacOS/rustdesk') + os.system( + 'cp libsciter.dylib target/release/bundle/osx/RustDesk.app/Contents/MacOS/') + # https://github.com/sindresorhus/create-dmg + os.system('/bin/rm -rf *.dmg') + os.system('create-dmg target/release/bundle/osx/RustDesk.app') + os.rename('RustDesk %s.dmg'%version, 'rustdesk-%s.dmg'%version) + else: + os.system('mv target/release/bundle/deb/rustdesk*.deb ./rustdesk.deb') + os.system('dpkg-deb -R rustdesk.deb tmpdeb') + os.system('mkdir -p tmpdeb/usr/share/rustdesk/files/systemd/') + os.system( + 'cp rustdesk.service tmpdeb/usr/share/rustdesk/files/systemd/') + os.system('cp pynput_service.py tmpdeb/usr/share/rustdesk/files/') + os.system('cp DEBIAN/* tmpdeb/DEBIAN/') + os.system('strip tmpdeb/usr/bin/rustdesk') + os.system('mkdir -p tmpdeb/usr/lib/rustdesk') + os.system('cp libsciter-gtk.so tmpdeb/usr/lib/rustdesk/') + md5_file('usr/share/rustdesk/files/systemd/rustdesk.service') + md5_file('usr/share/rustdesk/files/pynput_service.py') + md5_file('usr/lib/rustdesk/libsciter-gtk.so') + os.system('dpkg-deb -b tmpdeb rustdesk.deb; /bin/rm -rf tmpdeb/') + os.rename('rustdesk.deb', 'rustdesk-%s.deb'%version) + os.system("mv Cargo.toml.bk Cargo.toml") + os.system("mv src/main.rs.bk src/main.rs") + + +def md5_file(fn): + md5 = hashlib.md5(open('tmpdeb/' + fn, 'rb').read()).hexdigest() + os.system('echo "%s %s" >> tmpdeb/DEBIAN/md5sums' % (md5, fn)) + + +if __name__ == "__main__": + main() diff --git a/rustdesk.service b/rustdesk.service new file mode 100644 index 000000000..af4a3c411 --- /dev/null +++ b/rustdesk.service @@ -0,0 +1,16 @@ +[Unit] +Description=RustDesk +Requires=network.target +After=systemd-user-sessions.service + +[Service] +Type=simple +ExecStart=/usr/bin/rustdesk --service +PIDFile=/var/run/rustdesk.pid +KillMode=mixed +TimeoutStopSec=30 +User=root +LimitNOFILE=100000 + +[Install] +WantedBy=multi-user.target