This repository has been archived on 2025-03-19. You can view files and clone it, but cannot push or open issues or pull requests.
scrcpy-debify/package.sh
2024-04-22 14:33:44 -06:00

75 lines
2.7 KiB
Bash
Executable file

#!/bin/bash
package_name="scrcpy"
verlte() {
printf '%s\n' "$1" "$2" | sort -C -V
}
verlt() {
! verlte "$2" "$1"
}
installed_version=$( scrcpy --version | head -n 1 | cut -d ' ' -f 2);[[ -z ${installed_version} ]] && installed_version="0.0.0"
github_metadata=$( curl -s https://api.github.com/repos/Genymobile/scrcpy/releases/latest )
tarball_url=$( echo "${github_metadata}" | grep 'tarball_url' | head -n 1 | cut -d '"' -f 4 )
server_url=$( echo "${github_metadata}" | grep "server" | grep 'browser_download_url' | head -n 1 | cut -d '"' -f 4 )
tarball_version=$( echo "${github_metadata}" | grep 'tag_name' | head -n 1 | cut -d '"' -f 4 | tr -d 'v' )
echo $server_url
echo $tarball_url
echo $tarball_version
echo $installed_version
if verlt $installed_version $tarball_version || [[ "$1" == "force" ]]; then
echo "proceeding..."
else
echo "already up-to-date!"
exit
fi
script_root=$( realpath $(dirname $0) )
src_dir="${script_root}/src/"
src_deb_dir="${src_dir}/debian"
work_dir="${script_root}/tmp"; rm -r "${work_dir}" # clean work dir
dl_dir="${work_dir}/dl";mkdir -p "${dl_dir}" # location to store downloaded tarball
wget "${tarball_url}" -O "${dl_dir}/${package_name}-${tarball_version}.tar.gz" # download tarball
wget "${server_url}" -O "${dl_dir}/scrcpy-server"
tarball_path=$( find "${dl_dir}" -name "*.tar.gz" | head -n 1 ); #locate downloaded tarball
source_dir="${work_dir}/src" # where the program source be extracted/worked on
build_dir="${work_dir}/${package_name}-${tarball_version}" #debuild dir name
mkdir -p "${source_dir}"; tar -C "${source_dir}" -xf "${tarball_path}" --strip-components 1 # extract tarball into deb template
cd "${source_dir}"
meson setup build --buildtype=release --strip -Db_lto=true -Dprebuilt_server="${dl_dir}/scrcpy-server" -Dprefix="${build_dir}"
ninja -C build
ninja -C build/ install
cd "${build_dir}"; dh_make -sy -f "${tarball_path}"; cd "${script_root}"
build_deb_dir="${build_dir}/debian"
sed '/Depends:/a \ ffmpeg' "${build_deb_dir}/control"
sed '/Depends:/a \ adb' "${build_deb_dir}/control"
sed '/Depends:/a \ libsdl2-2.0-0' "${build_deb_dir}/control"
sed '/Depends:/a \ libusb-1.0-0' "${build_deb_dir}/control"
cp "${src_deb_dir}/"* "${build_deb_dir}"
find "${build_dir}" -type f -not -path "${build_deb_dir}*" | tee "${build_deb_dir}/source/include-binaries"
sed -i 's;'"${build_dir}"'/;;' "${build_deb_dir}/source/include-binaries"
echo "override_dh_shlibdeps:" >> "${build_deb_dir}/rules"
echo " dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info" >> "${build_deb_dir}/rules"
cd "${build_dir}"
EDITOR=/bin/true dpkg-source -q --commit . "prepdeb"
debuild
cd "${script_root}"
mv "${work_dir}/"*.deb "${script_root}/"
rm -r "${work_dir}"