# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

CRATES="
	addr2line@0.24.2
	adler2@2.0.0
	ahash@0.7.6
	aho-corasick@1.1.3
	android-tzdata@0.1.1
	android_system_properties@0.1.5
	ansi_term@0.12.1
	anyhow@1.0.57
	arrayvec@0.5.2
	async-compression@0.4.18
	async-trait@0.1.53
	atoi@1.0.0
	atty@0.2.14
	autocfg@1.1.0
	axum@0.5.5
	axum-core@0.2.4
	backtrace@0.3.74
	base64@0.13.0
	base64@0.21.7
	base64@0.22.1
	bcrypt@0.13.0
	bindgen@0.59.2
	bitflags@1.3.2
	bitflags@2.7.0
	block-buffer@0.10.2
	blowfish@0.9.1
	bumpalo@3.9.1
	byteorder@1.4.3
	bytes@1.9.0
	cc@1.2.9
	cesu8@1.1.0
	cexpr@0.6.0
	cfg-if@1.0.0
	chrono@0.4.39
	cipher@0.4.3
	clang-sys@1.8.1
	clap@2.34.0
	combine@4.6.7
	config@0.11.0
	confy@0.4.0
	core-foundation@0.9.4
	core-foundation-sys@0.8.7
	cpufeatures@0.2.2
	crc@3.0.0
	crc-catalog@2.1.0
	crc32fast@1.4.2
	crossbeam@0.8.1
	crossbeam-channel@0.5.4
	crossbeam-deque@0.8.1
	crossbeam-epoch@0.9.8
	crossbeam-queue@0.3.5
	crossbeam-utils@0.8.8
	crypto-common@0.1.3
	deadpool@0.8.2
	default-net@0.1.0
	digest@0.10.3
	directories-next@2.0.0
	dirs-next@2.0.0
	dirs-sys-next@0.1.2
	dlopen@0.1.8
	dlopen_derive@0.1.4
	dlv-list@0.3.0
	dns-lookup@1.0.8
	dotenv@0.15.0
	ed25519@1.5.0
	either@1.13.0
	encoding_rs@0.8.35
	env_logger@0.9.0
	env_logger@0.10.2
	equivalent@1.0.1
	event-listener@2.5.2
	fastrand@1.7.0
	filetime@0.2.16
	flate2@1.0.35
	flexi_logger@0.22.3
	flexi_logger@0.27.4
	flume@0.10.12
	fnv@1.0.7
	foreign-types@0.3.2
	foreign-types-shared@0.1.1
	form_urlencoded@1.0.1
	futures@0.3.21
	futures-channel@0.3.21
	futures-core@0.3.21
	futures-executor@0.3.21
	futures-intrusive@0.4.0
	futures-io@0.3.21
	futures-macro@0.3.21
	futures-sink@0.3.21
	futures-task@0.3.21
	futures-timer@3.0.2
	futures-util@0.3.21
	generic-array@0.14.5
	getrandom@0.2.15
	gimli@0.31.1
	glob@0.3.0
	h2@0.3.26
	hashbrown@0.11.2
	hashbrown@0.12.1
	hashbrown@0.15.2
	hashlink@0.8.0
	headers@0.3.7
	headers-core@0.2.0
	heck@0.4.0
	hermit-abi@0.1.19
	hermit-abi@0.4.0
	hex@0.4.3
	http@0.2.7
	http-body@0.4.4
	http-range-header@0.3.0
	httparse@1.9.5
	httpdate@1.0.2
	humantime@2.1.0
	hyper@0.14.32
	hyper-rustls@0.24.2
	hyper-tls@0.5.0
	iana-time-zone@0.1.61
	iana-time-zone-haiku@0.1.2
	idna@0.2.3
	indexmap@1.8.1
	indexmap@2.7.0
	inout@0.1.3
	instant@0.1.12
	ipnet@2.10.1
	ipnetwork@0.20.0
	is-terminal@0.4.13
	itertools@0.10.3
	itoa@1.0.1
	jni@0.19.0
	jni-sys@0.3.0
	jobserver@0.1.32
	js-sys@0.3.77
	jsonwebtoken@8.1.0
	lazy_static@1.4.0
	lazycell@1.3.0
	lexical-core@0.7.6
	libc@0.2.169
	libloading@0.8.6
	libsodium-sys@0.2.7
	libsqlite3-sys@0.24.2
	local-ip-address@0.5.3
	lock_api@0.4.7
	log@0.4.17
	mac_address@1.1.5
	machine-uid@0.2.0
	machine-uid@0.3.0
	matches@0.1.9
	matchit@0.5.0
	memchr@2.7.4
	memoffset@0.6.5
	mime@0.3.16
	mime_guess@2.0.4
	minimal-lexical@0.2.1
	miniz_oxide@0.8.3
	minreq@2.6.0
	mio@1.0.3
	native-tls@0.2.12
	neli@0.6.4
	neli-proc-macros@0.1.3
	nix@0.23.1
	nom@5.1.2
	nom@7.1.1
	ntapi@0.4.1
	nu-ansi-term@0.49.0
	num-bigint@0.4.6
	num-integer@0.1.46
	num-traits@0.2.19
	num_cpus@1.13.1
	num_threads@0.1.6
	object@0.36.7
	once_cell@1.20.2
	openssl@0.10.68
	openssl-macros@0.1.1
	openssl-probe@0.1.5
	openssl-sys@0.9.104
	ordered-multimap@0.4.3
	osascript@0.3.0
	parking_lot@0.11.2
	parking_lot@0.12.0
	parking_lot_core@0.8.5
	parking_lot_core@0.9.3
	paste@1.0.7
	peeking_take_while@0.1.2
	pem@1.0.2
	percent-encoding@2.1.0
	pin-project@1.1.8
	pin-project-internal@1.1.8
	pin-project-lite@0.2.16
	pin-utils@0.1.0
	ping@0.4.0
	pkg-config@0.3.25
	ppv-lite86@0.2.16
	proc-macro2@0.4.30
	proc-macro2@1.0.93
	protobuf@3.7.1
	protobuf-codegen@3.7.1
	protobuf-parse@3.7.1
	protobuf-support@3.7.1
	punycode@0.4.1
	quickcheck@1.0.3
	quote@0.6.13
	quote@1.0.38
	rand@0.8.5
	rand_chacha@0.3.1
	rand_core@0.6.3
	rayon@1.10.0
	rayon-core@1.12.1
	redox_syscall@0.2.13
	redox_users@0.4.3
	regex@1.11.1
	regex-automata@0.4.9
	regex-syntax@0.8.5
	remove_dir_all@0.5.3
	reqwest@0.11.23
	ring@0.16.20
	ring@0.17.3
	rust-ini@0.18.0
	rustc-demangle@0.1.24
	rustc-hash@1.1.0
	rustls@0.20.4
	rustls@0.21.12
	rustls@0.23.21
	rustls-native-certs@0.6.2
	rustls-native-certs@0.7.3
	rustls-pemfile@1.0.0
	rustls-pemfile@2.2.0
	rustls-pki-types@1.10.1
	rustls-platform-verifier@0.3.4
	rustls-platform-verifier-android@0.1.1
	rustls-webpki@0.101.7
	rustls-webpki@0.102.8
	rustversion@1.0.6
	ryu@1.0.9
	same-file@1.0.6
	schannel@0.1.27
	scopeguard@1.1.0
	sct@0.7.0
	security-framework@2.11.1
	security-framework-sys@2.14.0
	serde@1.0.217
	serde_derive@1.0.217
	serde_json@1.0.81
	serde_spanned@0.6.8
	serde_urlencoded@0.7.1
	sha-1@0.10.0
	sha2@0.10.2
	shlex@1.3.0
	signal-hook-registry@1.4.0
	signature@1.5.0
	simple_asn1@0.6.1
	slab@0.4.6
	smallvec@1.8.0
	socket2@0.3.19
	socket2@0.4.4
	socket2@0.5.8
	sodiumoxide@0.2.7
	spin@0.5.2
	spin@0.9.3
	sqlformat@0.1.8
	sqlx@0.6.0
	sqlx-core@0.6.0
	sqlx-macros@0.6.0
	sqlx-rt@0.6.0
	static_assertions@1.1.0
	stringprep@0.1.2
	strsim@0.8.0
	subtle@2.6.1
	syn@0.15.44
	syn@1.0.93
	syn@2.0.96
	sync_wrapper@0.1.2
	sysinfo@0.29.10
	system-configuration@0.5.1
	system-configuration-sys@0.5.0
	tempfile@3.3.0
	termcolor@1.1.3
	textwrap@0.11.0
	thiserror@1.0.31
	thiserror-impl@1.0.31
	time@0.3.9
	time-macros@0.2.4
	tinyvec@1.6.0
	tinyvec_macros@0.1.0
	tokio@1.43.0
	tokio-macros@2.5.0
	tokio-native-tls@0.3.1
	tokio-rustls@0.23.4
	tokio-rustls@0.24.1
	tokio-rustls@0.26.1
	tokio-socks@0.5.2
	tokio-stream@0.1.8
	tokio-tungstenite@0.17.1
	tokio-util@0.7.1
	toml@0.5.9
	toml@0.7.8
	toml_datetime@0.6.8
	toml_edit@0.19.15
	tower@0.4.12
	tower-http@0.3.3
	tower-layer@0.3.1
	tower-service@0.3.1
	tracing@0.1.41
	tracing-attributes@0.1.28
	tracing-core@0.1.33
	try-lock@0.2.3
	tungstenite@0.17.2
	typenum@1.15.0
	unicase@2.6.0
	unicode-bidi@0.3.8
	unicode-ident@1.0.14
	unicode-normalization@0.1.19
	unicode-segmentation@1.9.0
	unicode-width@0.1.9
	unicode-xid@0.1.0
	unicode-xid@0.2.3
	unicode_categories@0.1.1
	untrusted@0.7.1
	untrusted@0.9.0
	url@2.2.2
	utf-8@0.7.6
	uuid@1.12.0
	vcpkg@0.2.15
	vec_map@0.8.2
	version_check@0.9.4
	walkdir@2.3.2
	want@0.3.0
	wasi@0.11.0+wasi-snapshot-preview1
	wasm-bindgen@0.2.100
	wasm-bindgen-backend@0.2.100
	wasm-bindgen-futures@0.4.50
	wasm-bindgen-macro@0.2.100
	wasm-bindgen-macro-support@0.2.100
	wasm-bindgen-shared@0.2.100
	web-sys@0.3.77
	webpki@0.22.0
	webpki-roots@0.22.4
	webpki-roots@0.25.4
	webpki-roots@0.26.7
	which@4.2.5
	whoami@1.2.1
	winapi@0.3.9
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-util@0.1.5
	winapi-x86_64-pc-windows-gnu@0.4.0
	windows@0.51.1
	windows-core@0.51.1
	windows-core@0.52.0
	windows-sys@0.36.1
	windows-sys@0.48.0
	windows-sys@0.52.0
	windows-sys@0.59.0
	windows-targets@0.48.5
	windows-targets@0.52.6
	windows_aarch64_gnullvm@0.48.5
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_msvc@0.36.1
	windows_aarch64_msvc@0.48.5
	windows_aarch64_msvc@0.52.6
	windows_i686_gnu@0.36.1
	windows_i686_gnu@0.48.5
	windows_i686_gnu@0.52.6
	windows_i686_gnullvm@0.52.6
	windows_i686_msvc@0.36.1
	windows_i686_msvc@0.48.5
	windows_i686_msvc@0.52.6
	windows_x86_64_gnu@0.36.1
	windows_x86_64_gnu@0.48.5
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnullvm@0.48.5
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_msvc@0.36.1
	windows_x86_64_msvc@0.48.5
	windows_x86_64_msvc@0.52.6
	winnow@0.5.40
	winreg@0.6.2
	winreg@0.11.0
	winreg@0.50.0
	zeroize@1.8.1
	zstd@0.13.2
	zstd-safe@7.2.1
	zstd-sys@2.0.13+zstd.1.5.6
"
declare -A GIT_CRATES=(
	[async-speed-limit]="https://github.com/open-trade/async-speed-limit;f89f702ae01d4016429543d2f0dda1086157e420"
	[confy]="https://github.com/rustdesk-org/confy;83db9ec19a2f97e9718aef69e4fc5611bb382479"
	[default_net]="https://github.com/rustdesk-org/default_net;78f8f70cd85151a3a2c4a3230d80d5272703c02e"
	[machine-uid]="https://github.com/rustdesk-org/machine-uid;381ff579c1dc3a6c54db9dfec47c44bcb0246542"
	[reqwest]="https://github.com/rustdesk-org/reqwest;9cb758c9fb2f4edc62eb790acfd45a6a3da21ed3"
	[sysinfo]="https://github.com/rustdesk-org/sysinfo;90b1705d909a4902dbbbdea37ee64db17841077d"
	[tokio-socks]="https://github.com/rustdesk-org/tokio-socks;94e97c6d7c93b0bcbfa54f2dc397c1da0a6e43d3"
)

inherit cargo systemd

DESCRIPTION="RustDesk Server"
HOMEPAGE="https://rustdesk.com/"
SRC_URI="https://github.com/rustdesk/${PN}/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz
	https://github.com/rustdesk/hbb_common/archive/refs/tags/driver.tar.gz -> hbb_common.tar.gz
	${CARGO_CRATE_URIS}"

S=${WORKDIR}/${P}

LICENSE="AGPL-3"
SLOT="0"
KEYWORDS="amd64"

PATCHES=(
	"${FILESDIR}"/0001-fix-systemd-service-units.patch
)

src_unpack() {
	cargo_src_unpack
	rm -rf "${WORKDIR}"/${P}/libs/hbb_common
	cp -a "${WORKDIR}"/hbb_common-driver "${WORKDIR}"/${P}/libs/hbb_common
}

src_install() {
	cargo_src_install

	systemd_dounit "${FILESDIR}"/rustdesk-hbbr.service || die "Cannot install Service-Unit"
	systemd_dounit "${FILESDIR}"/rustdesk-hbbs.service || die "Cannot install Service-Unit"
	doconfd "${S}"/systemd/rustdesk-server || die "Cannot install Config-File"

	keepdir /var/lib/rustdesk-server/
	keepdir /var/log/rustdesk-server/
	dodoc LICENSE README.md
}