2022-04-18 15:37:35 +08:00
#!/usr/bin/env python3
import os
2022-10-21 17:24:07 +08:00
import pathlib
2022-04-18 15:37:35 +08:00
import platform
2022-05-28 18:42:38 +08:00
import zipfile
import urllib . request
import shutil
2022-04-18 15:37:35 +08:00
import hashlib
2022-05-28 18:42:38 +08:00
import argparse
2022-12-02 11:41:22 +08:00
import sys
2022-04-18 15:37:35 +08:00
windows = platform . platform ( ) . startswith ( ' Windows ' )
2022-11-20 16:54:54 +08:00
osx = platform . platform ( ) . startswith (
' Darwin ' ) or platform . platform ( ) . startswith ( " macOS " )
2022-04-18 15:37:35 +08:00
hbb_name = ' rustdesk ' + ( ' .exe ' if windows else ' ' )
exe_path = ' target/release/ ' + hbb_name
2022-10-21 17:24:07 +08:00
flutter_win_target_dir = ' flutter/build/windows/runner/Release/ '
2022-11-21 17:10:38 +08:00
skip_cargo = False
2022-04-18 15:37:35 +08:00
2022-12-02 11:41:22 +08:00
def custom_os_system ( cmd ) :
err = os . _system ( cmd )
if err != 0 :
2022-12-26 01:21:13 +08:00
print ( f " Error occurred when executing: { cmd } . Exiting. " )
2022-12-02 11:41:22 +08:00
sys . exit ( - 1 )
# replace prebuilt os.system
os . _system = os . system
os . system = custom_os_system
2022-10-22 12:41:37 +08:00
2022-04-18 15:37:35 +08:00
def get_version ( ) :
2022-11-01 21:03:47 +08:00
with open ( " Cargo.toml " , encoding = " utf-8 " ) as fh :
2022-04-18 15:37:35 +08:00
for line in fh :
if line . startswith ( " version " ) :
return line . replace ( " version " , " " ) . replace ( " = " , " " ) . replace ( ' " ' , ' ' ) . strip ( )
return ' '
2022-07-22 12:41:49 +08:00
def parse_rc_features ( feature ) :
2022-05-28 18:42:38 +08:00
available_features = {
' IddDriver ' : {
2022-12-04 21:59:26 +08:00
' zip_url ' : ' https://github.com/fufesou/RustDeskIddDriver/releases/download/v0.1/RustDeskIddDriver_x64.zip ' ,
' checksum_url ' : ' https://github.com/fufesou/RustDeskIddDriver/releases/download/v0.1/checksum_md5 ' ,
' exclude ' : [ ' README.md ' ] ,
2022-05-28 18:42:38 +08:00
} ,
' PrivacyMode ' : {
' zip_url ' : ' https://github.com/fufesou/RustDeskTempTopMostWindow/releases/download/v0.1 '
2022-10-21 13:38:44 +08:00
' /TempTopMostWindow_x64_pic_en.zip ' ,
' checksum_url ' : ' https://github.com/fufesou/RustDeskTempTopMostWindow/releases/download/v0.1/checksum_md5 ' ,
2022-12-04 21:59:26 +08:00
' include ' : [ ' WindowInjection.dll ' ] ,
2022-05-28 18:42:38 +08:00
}
}
apply_features = { }
if not feature :
2022-10-21 13:38:44 +08:00
feature = [ ]
if isinstance ( feature , str ) and feature . upper ( ) == ' ALL ' :
2022-05-28 18:42:38 +08:00
return available_features
elif isinstance ( feature , list ) :
2022-10-21 13:38:44 +08:00
# force add PrivacyMode
feature . append ( ' PrivacyMode ' )
2022-05-28 18:42:38 +08:00
for feat in feature :
if isinstance ( feat , str ) and feat . upper ( ) == ' ALL ' :
return available_features
if feat in available_features :
apply_features [ feat ] = available_features [ feat ]
else :
print ( f ' Unrecognized feature { feat } ' )
return apply_features
else :
raise Exception ( f ' Unsupported features param { feature } ' )
def make_parser ( ) :
parser = argparse . ArgumentParser ( description = ' Build script. ' )
parser . add_argument (
' -f ' ,
' --feature ' ,
dest = ' feature ' ,
metavar = ' N ' ,
type = str ,
nargs = ' + ' ,
default = ' ' ,
help = ' Integrate features, windows only. '
' Available: IddDriver, PrivacyMode. Special value is " ALL " and empty " " . Default is empty. ' )
2022-08-25 17:35:45 +08:00
parser . add_argument ( ' --flutter ' , action = ' store_true ' ,
help = ' Build flutter package ' , default = False )
2022-06-14 15:01:07 +08:00
parser . add_argument (
' --hwcodec ' ,
action = ' store_true ' ,
2022-10-22 12:41:37 +08:00
help = ' Enable feature hwcodec ' + (
' ' if windows or osx else ' , need libva-dev, libvdpau-dev. ' )
2022-06-14 15:01:07 +08:00
)
2022-09-21 11:28:28 +08:00
parser . add_argument (
' --portable ' ,
action = ' store_true ' ,
help = ' Build windows portable '
)
2022-11-08 16:52:45 +08:00
parser . add_argument (
' --flatpak ' ,
action = ' store_true ' ,
help = ' Build rustdesk libs with the flatpak feature enabled '
)
2022-11-21 17:10:38 +08:00
parser . add_argument (
' --skip-cargo ' ,
action = ' store_true ' ,
help = ' Skip cargo build process, only flutter version + Linux supported currently '
)
2022-05-28 18:42:38 +08:00
return parser
2022-10-22 12:41:37 +08:00
# Generate build script for docker
#
# it assumes all build dependencies are installed in environments
# Note: do not use it in bare metal, or may break build environments
def generate_build_script_for_docker ( ) :
with open ( " /tmp/build.sh " , " w " ) as f :
f . write ( '''
#!/bin/bash
# environment
export CPATH = " $(clang -v 2>&1 | grep " Selected GCC installation : " | cut -d ' ' -f4-)/include "
# flutter
pushd / opt
wget https : / / storage . googleapis . com / flutter_infra_release / releases / stable / linux / flutter_linux_3 .0 .5 - stable . tar . xz
tar - xvf flutter_linux_3 .0 .5 - stable . tar . xz
export PATH = ` pwd ` / flutter / bin : $ PATH
popd
# flutter_rust_bridge
dart pub global activate ffigen - - version 5.0 .1
pushd / tmp & & git clone https : / / github . com / SoLongAndThanksForAllThePizza / flutter_rust_bridge - - depth = 1 & & popd
pushd / tmp / flutter_rust_bridge / frb_codegen & & cargo install - - path . & & popd
pushd flutter & & flutter pub get & & popd
~ / . cargo / bin / flutter_rust_bridge_codegen - - rust - input . / src / flutter_ffi . rs - - dart - output . / flutter / lib / generated_bridge . dart
# install vcpkg
pushd / opt
export VCPKG_ROOT = ` pwd ` / vcpkg
git clone https : / / github . com / microsoft / vcpkg
vcpkg / bootstrap - vcpkg . sh
vcpkg / vcpkg install libvpx libyuv opus
popd
# build rustdesk
. / build . py - - flutter - - hwcodec
''' )
os . system ( " chmod +x /tmp/build.sh " )
os . system ( " bash /tmp/build.sh " )
2022-11-20 16:54:54 +08:00
2022-05-28 18:42:38 +08:00
def download_extract_features ( features , res_dir ) :
2022-12-04 21:59:26 +08:00
import re
2022-10-22 12:41:37 +08:00
2022-12-04 21:59:26 +08:00
proxy = ' '
2022-10-21 13:38:44 +08:00
def req ( url ) :
if not proxy :
return url
else :
r = urllib . request . Request ( url )
r . set_proxy ( proxy , ' http ' )
r . set_proxy ( proxy , ' https ' )
return r
2022-05-28 18:42:38 +08:00
for ( feat , feat_info ) in features . items ( ) :
2022-12-04 21:59:26 +08:00
includes = feat_info [ ' include ' ] if ' include ' in feat_info and feat_info [ ' include ' ] else [ ]
includes = [ re . compile ( p ) for p in includes ]
excludes = feat_info [ ' exclude ' ] if ' exclude ' in feat_info and feat_info [ ' exclude ' ] else [ ]
excludes = [ re . compile ( p ) for p in excludes ]
2022-05-28 18:42:38 +08:00
print ( f ' { feat } download begin ' )
download_filename = feat_info [ ' zip_url ' ] . split ( ' / ' ) [ - 1 ]
2022-11-20 16:54:54 +08:00
checksum_md5_response = urllib . request . urlopen (
req ( feat_info [ ' checksum_url ' ] ) )
2022-10-21 13:38:44 +08:00
for line in checksum_md5_response . read ( ) . decode ( ' utf-8 ' ) . splitlines ( ) :
if line . split ( ) [ 1 ] == download_filename :
checksum_md5 = line . split ( ) [ 0 ]
2022-10-22 12:41:37 +08:00
filename , _headers = urllib . request . urlretrieve ( feat_info [ ' zip_url ' ] ,
download_filename )
2022-10-21 13:38:44 +08:00
md5 = hashlib . md5 ( open ( filename , ' rb ' ) . read ( ) ) . hexdigest ( )
if checksum_md5 != md5 :
raise Exception ( f ' { feat } download failed ' )
print ( f ' { feat } download end. extract bein ' )
zip_file = zipfile . ZipFile ( filename )
zip_list = zip_file . namelist ( )
for f in zip_list :
2022-12-04 21:59:26 +08:00
file_exclude = False
for p in excludes :
if p . match ( f ) is not None :
file_exclude = True
break
if file_exclude :
continue
file_include = False if includes else True
for p in includes :
if p . match ( f ) is not None :
file_include = True
break
if file_include :
print ( f ' extract file { f } ' )
zip_file . extract ( f , res_dir )
2022-10-21 13:38:44 +08:00
zip_file . close ( )
os . remove ( download_filename )
print ( f ' { feat } extract end ' )
2022-05-28 18:42:38 +08:00
2022-07-22 09:14:18 +08:00
def get_rc_features ( args ) :
2022-10-21 17:24:07 +08:00
flutter = args . flutter
2022-07-22 12:41:49 +08:00
features = parse_rc_features ( args . feature )
2022-10-21 17:24:07 +08:00
if not features :
return [ ]
print ( f ' Build with features { list ( features . keys ( ) ) } ' )
res_dir = ' resources '
if os . path . isdir ( res_dir ) and not os . path . islink ( res_dir ) :
shutil . rmtree ( res_dir )
elif os . path . exists ( res_dir ) :
raise Exception ( f ' Find file { res_dir } , not a directory ' )
os . makedirs ( res_dir , exist_ok = True )
download_extract_features ( features , res_dir )
if flutter :
os . makedirs ( flutter_win_target_dir , exist_ok = True )
for f in pathlib . Path ( res_dir ) . iterdir ( ) :
print ( f ' { f } ' )
if f . is_file ( ) :
shutil . copy2 ( f , flutter_win_target_dir )
else :
shutil . copytree ( f , f ' { flutter_win_target_dir } { f . stem } ' )
return [ ]
else :
return [ ' with_rc ' ]
2022-10-22 12:41:37 +08:00
2022-05-28 18:42:38 +08:00
2022-07-22 09:14:18 +08:00
def get_features ( args ) :
2022-11-20 16:54:54 +08:00
features = [ ' inline ' ] if not args . flutter else [ ]
2022-07-22 09:14:18 +08:00
if windows :
features . extend ( get_rc_features ( args ) )
if args . hwcodec :
features . append ( ' hwcodec ' )
2022-08-25 17:35:45 +08:00
if args . flutter :
features . append ( ' flutter ' )
2022-11-08 16:52:45 +08:00
if args . flatpak :
features . append ( ' flatpak ' )
2022-07-22 09:14:18 +08:00
print ( " features: " , features )
return features
2022-05-28 18:42:38 +08:00
2022-10-22 12:41:37 +08:00
2022-09-13 14:27:07 +08:00
def generate_control_file ( version ) :
2022-09-18 11:50:23 +08:00
control_file_path = " ../res/DEBIAN/control "
2022-09-13 14:27:07 +08:00
os . system ( ' /bin/rm -rf %s ' % control_file_path )
content = """ Package: rustdesk
Version : % s
Architecture : amd64
Maintainer : open - trade < info @rustdesk.com >
Homepage : https : / / rustdesk . com
2022-12-01 21:48:19 +08:00
Depends : libgtk - 3 - 0 , libxcb - randr0 , libxdo3 , libxfixes3 , libxcb - shape0 , libxcb - xfixes0 , libasound2 , libsystemd0 , curl , libva - drm2 , libva - x11 - 2 , libvdpau1 , libgstreamer - plugins - base1 .0 - 0
2022-09-13 14:27:07 +08:00
Description : A remote control software .
""" % version
file = open ( control_file_path , " w " )
file . write ( content )
file . close ( )
2022-08-25 18:36:44 +08:00
2022-10-22 12:41:37 +08:00
def ffi_bindgen_function_refactor ( ) :
2022-10-12 11:34:58 +08:00
# workaround ffigen
2022-10-22 12:41:37 +08:00
os . system (
' sed -i " s/ffi.NativeFunction<ffi.Bool Function(DartPort/ffi.NativeFunction<ffi.Uint8 Function(DartPort/g " flutter/lib/generated_bridge.dart ' )
def build_flutter_deb ( version , features ) :
2022-11-21 17:10:38 +08:00
if not skip_cargo :
os . system ( f ' cargo build --features { features } --lib --release ' )
ffi_bindgen_function_refactor ( )
2022-08-25 18:36:44 +08:00
os . chdir ( ' flutter ' )
2022-09-13 14:27:07 +08:00
os . system ( ' flutter build linux --release ' )
os . system ( ' mkdir -p tmpdeb/usr/bin/ ' )
2022-08-25 18:36:44 +08:00
os . system ( ' mkdir -p tmpdeb/usr/lib/rustdesk ' )
os . system ( ' mkdir -p tmpdeb/usr/share/rustdesk/files/systemd/ ' )
2022-09-13 14:27:07 +08:00
os . system ( ' mkdir -p tmpdeb/usr/share/applications/ ' )
2022-09-14 10:30:57 +08:00
os . system ( ' mkdir -p tmpdeb/usr/share/polkit-1/actions ' )
2022-12-02 14:59:54 +08:00
os . system ( ' rm tmpdeb/usr/bin/rustdesk || true ' )
2022-08-25 18:36:44 +08:00
os . system (
' cp -r build/linux/x64/release/bundle/* tmpdeb/usr/lib/rustdesk/ ' )
os . system (
2022-09-18 11:50:23 +08:00
' cp ../res/rustdesk.service tmpdeb/usr/share/rustdesk/files/systemd/ ' )
2022-08-25 18:36:44 +08:00
os . system (
2022-09-18 11:32:15 +08:00
' cp ../res/128x128@2x.png tmpdeb/usr/share/rustdesk/files/rustdesk.png ' )
2022-08-25 18:36:44 +08:00
os . system (
2022-09-18 11:50:23 +08:00
' cp ../res/rustdesk.desktop tmpdeb/usr/share/applications/rustdesk.desktop ' )
2022-10-11 19:52:03 +08:00
os . system (
' cp ../res/rustdesk-link.desktop tmpdeb/usr/share/applications/rustdesk-link.desktop ' )
2022-09-14 10:30:57 +08:00
os . system (
2022-09-18 11:32:15 +08:00
' cp ../res/com.rustdesk.RustDesk.policy tmpdeb/usr/share/polkit-1/actions/ ' )
2022-10-22 12:41:37 +08:00
os . system (
" echo \" #!/bin/sh \" >> tmpdeb/usr/share/rustdesk/files/polkit && chmod a+x tmpdeb/usr/share/rustdesk/files/polkit " )
2022-09-14 10:30:57 +08:00
2022-08-25 18:36:44 +08:00
os . system ( ' mkdir -p tmpdeb/DEBIAN ' )
2022-09-13 14:27:07 +08:00
generate_control_file ( version )
2022-09-18 11:50:23 +08:00
os . system ( ' cp -a ../res/DEBIAN/* tmpdeb/DEBIAN/ ' )
2022-08-25 18:36:44 +08:00
md5_file ( ' usr/share/rustdesk/files/systemd/rustdesk.service ' )
2022-09-13 14:27:07 +08:00
os . system ( ' dpkg-deb -b tmpdeb rustdesk.deb; ' )
os . system ( ' /bin/rm -rf tmpdeb/ ' )
2022-09-18 11:50:23 +08:00
os . system ( ' /bin/rm -rf ../res/DEBIAN/control ' )
2022-08-25 18:36:44 +08:00
os . rename ( ' rustdesk.deb ' , ' ../rustdesk- %s .deb ' % version )
os . chdir ( " .. " )
2022-11-20 16:40:59 +08:00
def build_flutter_dmg ( version , features ) :
2022-11-21 17:10:38 +08:00
if not skip_cargo :
os . system ( f ' cargo build --features { features } --lib --release ' )
2022-11-20 16:54:54 +08:00
# copy dylib
os . system (
" cp target/release/liblibrustdesk.dylib target/release/librustdesk.dylib " )
# ffi_bindgen_function_refactor()
# limitations from flutter rust bridge
os . system ( ' sed -i " " " s/char \ * \ *rustdesk_core_main(int \ *args_len);// " flutter/macos/Runner/bridge_generated.h ' )
2022-11-20 16:40:59 +08:00
os . chdir ( ' flutter ' )
os . system ( ' flutter build macos --release ' )
2022-11-20 16:54:54 +08:00
os . system (
" create-dmg rustdesk.dmg ./build/macos/Build/Products/Release/rustdesk.app " )
os . rename ( " rustdesk.dmg " , f " ../rustdesk- { version } .dmg " )
os . chdir ( " .. " )
2022-11-20 16:40:59 +08:00
2022-10-22 12:41:37 +08:00
def build_flutter_arch_manjaro ( version , features ) :
2022-11-21 17:10:38 +08:00
if not skip_cargo :
os . system ( f ' cargo build --features { features } --lib --release ' )
2022-10-22 12:41:37 +08:00
ffi_bindgen_function_refactor ( )
2022-08-25 18:36:44 +08:00
os . chdir ( ' flutter ' )
os . system ( ' flutter build linux --release ' )
2022-10-22 12:41:37 +08:00
os . system ( ' strip build/linux/x64/release/bundle/lib/librustdesk.so ' )
os . chdir ( ' ../res ' )
os . system ( ' HBB=`pwd`/.. FLUTTER=1 makepkg -f ' )
2022-08-25 18:36:44 +08:00
2022-10-22 12:41:37 +08:00
def build_flutter_windows ( version , features ) :
2022-11-21 17:10:38 +08:00
if not skip_cargo :
os . system ( f ' cargo build --features { features } --lib --release ' )
if not os . path . exists ( " target/release/librustdesk.dll " ) :
print ( " cargo build failed, please check rust source code. " )
exit ( - 1 )
2022-09-21 11:28:28 +08:00
os . chdir ( ' flutter ' )
2022-10-21 17:24:07 +08:00
os . system ( ' flutter build windows --release ' )
2022-09-21 11:28:28 +08:00
os . chdir ( ' .. ' )
2022-11-20 16:54:54 +08:00
shutil . copy2 ( ' target/release/deps/dylib_virtual_display.dll ' ,
flutter_win_target_dir )
2022-10-21 17:24:07 +08:00
os . chdir ( ' libs/portable ' )
os . system ( ' pip3 install -r requirements.txt ' )
2022-10-22 12:41:37 +08:00
os . system (
f ' python3 ./generate.py -f ../../ { flutter_win_target_dir } -o . -e ../../ { flutter_win_target_dir } /rustdesk.exe ' )
2022-10-21 17:24:07 +08:00
os . chdir ( ' ../.. ' )
if os . path . exists ( ' ./rustdesk_portable.exe ' ) :
2022-11-20 16:54:54 +08:00
os . replace ( ' ./target/release/rustdesk-portable-packer.exe ' ,
' ./rustdesk_portable.exe ' )
2022-09-21 11:28:28 +08:00
else :
2022-11-20 16:54:54 +08:00
os . rename ( ' ./target/release/rustdesk-portable-packer.exe ' ,
' ./rustdesk_portable.exe ' )
print (
f ' output location: { os . path . abspath ( os . curdir ) } /rustdesk_portable.exe ' )
2022-10-21 17:24:07 +08:00
os . rename ( ' ./rustdesk_portable.exe ' , f ' ./rustdesk- { version } -install.exe ' )
2022-11-20 16:54:54 +08:00
print (
f ' output location: { os . path . abspath ( os . curdir ) } /rustdesk- { version } -install.exe ' )
2022-08-25 18:36:44 +08:00
2022-10-22 12:41:37 +08:00
2022-04-18 15:37:35 +08:00
def main ( ) :
2022-11-21 17:10:38 +08:00
global skip_cargo
2022-05-28 18:42:38 +08:00
parser = make_parser ( )
args = parser . parse_args ( )
2022-10-21 17:24:07 +08:00
shutil . copy2 ( ' Cargo.toml ' , ' Cargo.toml.bk ' )
shutil . copy2 ( ' src/main.rs ' , ' src/main.rs.bk ' )
2022-04-18 15:37:35 +08:00
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 )
if os . path . isfile ( ' /usr/bin/pacman ' ) :
os . system ( ' git checkout src/ui/common.tis ' )
version = get_version ( )
2022-10-21 17:24:07 +08:00
features = ' , ' . join ( get_features ( args ) )
2022-08-25 17:35:45 +08:00
flutter = args . flutter
2022-11-20 16:54:54 +08:00
if not flutter :
os . system ( ' python3 res/inline-sciter.py ' )
2022-11-21 17:10:38 +08:00
print ( args . skip_cargo )
if args . skip_cargo :
skip_cargo = True
2022-09-21 11:28:28 +08:00
portable = args . portable
2022-04-18 15:37:35 +08:00
if windows :
2022-11-18 17:09:52 +08:00
# build virtual display dynamic library
os . chdir ( ' libs/virtual_display/dylib ' )
os . system ( ' cargo build --release ' )
os . chdir ( ' ../../.. ' )
2022-10-11 14:52:46 +08:00
if flutter :
2022-10-22 12:41:37 +08:00
build_flutter_windows ( version , features )
2022-09-21 11:28:28 +08:00
return
2022-07-22 09:14:18 +08:00
os . system ( ' cargo build --release --features ' + features )
2022-04-18 15:37:35 +08:00
# os.system('upx.exe target/release/rustdesk.exe')
os . system ( ' mv target/release/rustdesk.exe target/release/RustDesk.exe ' )
2022-05-01 23:39:03 +08:00
pa = os . environ . get ( ' P ' )
if pa :
2022-10-22 12:41:37 +08:00
os . system (
f ' signtool sign /a /v /p { pa } /debug /f . \\ cert.pfx /t http://timestamp.digicert.com '
' target \\ release \\ rustdesk.exe ' )
2022-05-01 23:39:03 +08:00
else :
2022-05-28 18:42:38 +08:00
print ( ' Not signed ' )
2022-11-20 16:54:54 +08:00
os . system (
f ' cp -rf target/release/RustDesk.exe rustdesk- { version } -win7-install.exe ' )
2022-10-05 18:32:20 +08:00
elif os . path . isfile ( ' /usr/bin/pacman ' ) :
2022-09-12 19:17:46 +08:00
# pacman -S -needed base-devel
2022-10-22 12:41:37 +08:00
os . system ( " sed -i ' s/pkgver=.*/pkgver= %s /g ' res/PKGBUILD " % version )
2022-08-25 17:35:45 +08:00
if flutter :
2022-10-22 12:41:37 +08:00
build_flutter_arch_manjaro ( version , features )
2022-08-25 17:35:45 +08:00
else :
2022-09-12 19:17:46 +08:00
os . system ( ' cargo build --release --features ' + features )
2022-08-25 17:35:45 +08:00
os . system ( ' git checkout src/ui/common.tis ' )
os . system ( ' strip target/release/rustdesk ' )
2022-09-18 12:07:22 +08:00
os . system ( ' ln -s res/pacman_install && ln -s res/PKGBUILD ' )
2022-08-25 17:35:45 +08:00
os . system ( ' HBB=`pwd` makepkg -f ' )
2022-10-22 12:41:37 +08:00
os . system ( ' mv rustdesk- %s -0-x86_64.pkg.tar.zst rustdesk- %s -manjaro-arch.pkg.tar.zst ' % (
2022-11-20 16:54:54 +08:00
version , version ) )
2022-09-12 19:17:46 +08:00
# pacman -U ./rustdesk.pkg.tar.zst
2022-05-23 11:59:56 +08:00
elif os . path . isfile ( ' /usr/bin/yum ' ) :
2022-07-22 09:14:18 +08:00
os . system ( ' cargo build --release --features ' + features )
2022-05-23 11:59:56 +08:00
os . system ( ' strip target/release/rustdesk ' )
2022-11-20 16:54:54 +08:00
os . system (
" sed -i ' s/Version: .*/Version: %s /g ' res/rpm.spec " % version )
2022-09-18 12:07:22 +08:00
os . system ( ' HBB=`pwd` rpmbuild -ba res/rpm.spec ' )
2022-10-22 12:41:37 +08:00
os . system (
' mv $HOME/rpmbuild/RPMS/x86_64/rustdesk- %s -0.x86_64.rpm ./rustdesk- %s -fedora28-centos8.rpm ' % (
version , version ) )
2022-05-23 11:59:56 +08:00
# yum localinstall rustdesk.rpm
elif os . path . isfile ( ' /usr/bin/zypper ' ) :
2022-07-22 09:14:18 +08:00
os . system ( ' cargo build --release --features ' + features )
2022-05-23 11:59:56 +08:00
os . system ( ' strip target/release/rustdesk ' )
2022-11-20 16:54:54 +08:00
os . system (
" sed -i ' s/Version: .*/Version: %s /g ' res/rpm-suse.spec " % version )
2022-09-18 12:07:22 +08:00
os . system ( ' HBB=`pwd` rpmbuild -ba res/rpm-suse.spec ' )
2022-10-22 12:41:37 +08:00
os . system (
' mv $HOME/rpmbuild/RPMS/x86_64/rustdesk- %s -0.x86_64.rpm ./rustdesk- %s -suse.rpm ' % (
2022-11-20 16:54:54 +08:00
version , version ) )
2022-05-23 11:59:56 +08:00
# yum localinstall rustdesk.rpm
2022-04-18 15:37:35 +08:00
else :
2022-08-25 18:36:44 +08:00
if flutter :
if osx :
2022-11-20 16:40:59 +08:00
build_flutter_dmg ( version , features )
2022-08-25 18:36:44 +08:00
pass
2022-05-01 23:39:03 +08:00
else :
2022-11-21 17:10:38 +08:00
# os.system(
# 'mv target/release/bundle/deb/rustdesk*.deb ./flutter/rustdesk.deb')
2022-10-22 12:41:37 +08:00
build_flutter_deb ( version , features )
2022-04-18 15:37:35 +08:00
else :
2022-11-20 16:54:54 +08:00
os . system ( ' cargo bundle --release --features ' + features )
2022-08-25 18:36:44 +08:00
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 ' )
plist = " target/release/bundle/osx/RustDesk.app/Contents/Info.plist "
txt = open ( plist ) . read ( )
with open ( plist , " wt " ) as fh :
fh . write ( txt . replace ( " </dict> " , """
< key > LSUIElement < / key >
< string > 1 < / string >
< / dict > """ ))
pa = os . environ . get ( ' P ' )
if pa :
os . system ( '''
# buggy: rcodesign sign ... path/*, have to sign one by one
#rcodesign sign --p12-file ~/.p12/rustdesk-developer-id.p12 --p12-password-file ~/.p12/.cert-pass --code-signature-flags runtime ./target/release/bundle/osx/RustDesk.app/Contents/MacOS/rustdesk
#rcodesign sign --p12-file ~/.p12/rustdesk-developer-id.p12 --p12-password-file ~/.p12/.cert-pass --code-signature-flags runtime ./target/release/bundle/osx/RustDesk.app/Contents/MacOS/libsciter.dylib
#rcodesign sign --p12-file ~/.p12/rustdesk-developer-id.p12 --p12-password-file ~/.p12/.cert-pass --code-signature-flags runtime ./target/release/bundle/osx/RustDesk.app
# goto "Keychain Access" -> "My Certificates" for below id which starts with "Developer ID Application:"
codesign - s " Developer ID Application: {0} " - - force - - options runtime . / target / release / bundle / osx / RustDesk . app / Contents / MacOS / *
codesign - s " Developer ID Application: {0} " - - force - - options runtime . / target / release / bundle / osx / RustDesk . app
''' .format(pa))
os . system ( ' create-dmg target/release/bundle/osx/RustDesk.app ' )
os . rename ( ' RustDesk %s .dmg ' %
version , ' rustdesk- %s .dmg ' % version )
if pa :
os . system ( '''
2023-01-05 17:45:41 +08:00
# https://pyoxidizer.readthedocs.io/en/apple-codesign-0.14.0/apple_codesign.html
# https://pyoxidizer.readthedocs.io/en/stable/tugger_code_signing.html
# https://developer.apple.com/developer-id/
# goto xcode and login with apple id, manager certificates (Developer ID Application and/or Developer ID Installer) online there (only download and double click (install) cer file can not export p12 because no private key)
2022-08-25 18:36:44 +08:00
#rcodesign sign --p12-file ~/.p12/rustdesk-developer-id.p12 --p12-password-file ~/.p12/.cert-pass --code-signature-flags runtime ./rustdesk-{1}.dmg
codesign - s " Developer ID Application: {0} " - - force - - options runtime . / rustdesk - { 1 } . dmg
2023-01-05 17:45:41 +08:00
# https://appstoreconnect.apple.com/access/api
# https://gregoryszorc.com/docs/apple-codesign/0.16.0/apple_codesign_rcodesign.html#notarizing-and-stapling
2023-01-05 21:03:54 +08:00
# p8 file is generated when you generate api key, download and put it under ~/.private_keys/
2022-12-04 17:10:26 +08:00
rcodesign notarize - - api - issuer { 2 } - - api - key { 3 } - - staple . / rustdesk - { 1 } . dmg
2022-08-25 18:36:44 +08:00
# verify: spctl -a -t exec -v /Applications/RustDesk.app
2022-12-04 17:10:26 +08:00
''' .format(pa, version, os.environ.get( ' api-issuer ' ), os.environ.get( ' api-key ' )))
2022-08-25 18:36:44 +08:00
else :
print ( ' Not signed ' )
else :
# buid deb package
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 (
2022-09-18 11:50:23 +08:00
' cp res/rustdesk.service tmpdeb/usr/share/rustdesk/files/systemd/ ' )
os . system (
' cp res/128x128@2x.png tmpdeb/usr/share/rustdesk/files/rustdesk.png ' )
os . system (
' cp res/rustdesk.desktop tmpdeb/usr/share/applications/rustdesk.desktop ' )
2022-10-11 19:52:03 +08:00
os . system (
' cp res/rustdesk-link.desktop tmpdeb/usr/share/applications/rustdesk-link.desktop ' )
2022-09-18 11:50:23 +08:00
os . system ( ' cp -a res/DEBIAN/* tmpdeb/DEBIAN/ ' )
2022-08-25 18:36:44 +08:00
os . system ( ' strip tmpdeb/usr/bin/rustdesk ' )
os . system ( ' mkdir -p tmpdeb/usr/lib/rustdesk ' )
2022-10-13 21:34:50 +08:00
os . system ( ' mv tmpdeb/usr/bin/rustdesk tmpdeb/usr/lib/rustdesk/ ' )
2022-08-25 18:36:44 +08:00
os . system ( ' cp libsciter-gtk.so tmpdeb/usr/lib/rustdesk/ ' )
md5_file ( ' usr/share/rustdesk/files/systemd/rustdesk.service ' )
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 )
2022-04-18 15:37:35 +08:00
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 ( )