Skip to content

Commit

Permalink
steamlink-rpi: extract icu from debian package
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Leonard <[email protected]>
  • Loading branch information
antonlacon committed Dec 29, 2024
1 parent 7fc9225 commit 68dc066
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
17 changes: 13 additions & 4 deletions packages/addons/script/steamlink-rpi/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ PKG_ARCH="aarch64"
PKG_ADDON_PROJECTS="RPi4 RPi5"
PKG_LICENSE="custom"
PKG_SITE="https://support.steampowered.com/kb_article.php?ref=6153-IFGH-6589"
PKG_DEPENDS_TARGET="double-conversion krb5 libkeyutils md4c steamlink-ffmpeg steamlink-icu steamlink-libepoxy steamlink-libjpeg-turbo steamlink-libpng steamlink-mtdev steamlink-wayland steamlink-zstd"
#PKG_DEPENDS_TARGET="double-conversion krb5 libkeyutils md4c steamlink-ffmpeg steamlink-icu steamlink-libepoxy steamlink-libjpeg-turbo steamlink-libpng steamlink-mtdev steamlink-wayland steamlink-zstd"
PKG_DEPENDS_TARGET="double-conversion krb5 libkeyutils md4c unix_ar steamlink-ffmpeg steamlink-libepoxy steamlink-libjpeg-turbo steamlink-libpng steamlink-mtdev steamlink-wayland steamlink-zstd"
PKG_SECTION="script.program"
PKG_SHORTDESC="Steam Link App for Raspberry Pi"
PKG_LONGDESC="Installs the Steam Link App for Raspberry Pi from Valve for use in streaming from Steam clients. Addon is not associated with Valve. Use of Steam Link software is subject to the Steam Subscriber Agreement."
Expand All @@ -21,9 +22,12 @@ PKG_ADDON_PROVIDES="executable"

PKG_STEAMLINK_VERSION="1.3.13.281"
PKG_STEAMLINK_HASH="6773437c2659a93e7b8d4e9c5069315f7dbf701c168a29ac1119f7b69dd7b72e"
PKG_ICU_URL="http://http.us.debian.org/debian/pool/main/i/icu/libicu72_72.1-3_arm64.deb"
PKG_ICU_HASH="fa1b61e24b45d07c9ec15dbd1750aeea26eef6044270629ef58138fc09ca238f"

addon() {
# Add needed libraries
mkdir -p ${ADDON_BUILD}/${PKG_ADDON_ID}/resources
mkdir -p ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs

# double-conversion
Expand All @@ -42,14 +46,17 @@ addon() {
# md4c
cp -L $(get_install_dir md4c)/usr/lib/libmd4c.so.0 ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs/

# unix_ar
cp -L $(get_build_dir unix_ar)/unix_ar.py ${ADDON_BUILD}/${PKG_ADDON_ID}/resources/

# ffmpeg
cp -L $(get_install_dir steamlink-ffmpeg)/usr/lib/libavcodec.so.59 ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs/
cp -L $(get_install_dir steamlink-ffmpeg)/usr/lib/libavutil.so.57 ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs/

# icu
cp -L $(get_install_dir steamlink-icu)/usr/lib/libicudata.so.72 ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs/
cp -L $(get_install_dir steamlink-icu)/usr/lib/libicui18n.so.72 ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs/
cp -L $(get_install_dir steamlink-icu)/usr/lib/libicuuc.so.72 ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs/
# cp -L $(get_install_dir steamlink-icu)/usr/lib/libicudata.so.72 ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs/
# cp -L $(get_install_dir steamlink-icu)/usr/lib/libicui18n.so.72 ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs/
# cp -L $(get_install_dir steamlink-icu)/usr/lib/libicuuc.so.72 ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs/

# libepoxy
cp -L $(get_install_dir steamlink-libepoxy)/usr/lib/libepoxy.so.0 ${ADDON_BUILD}/${PKG_ADDON_ID}/system-libs/
Expand All @@ -75,5 +82,7 @@ post_install_addon() {
# Add steamlink version to download to addon
sed -e "s/@STEAMLINK_VERSION@/${PKG_STEAMLINK_VERSION}/" \
-e "s/@STEAMLINK_HASH@/${PKG_STEAMLINK_HASH}/" \
-e "s#@ICU_URL@#${PKG_ICU_URL}#" \
-e "s/@ICU_HASH@/${PKG_ICU_HASH}/" \
-i ${ADDON_BUILD}/${PKG_ADDON_ID}/default.py
}
62 changes: 53 additions & 9 deletions packages/addons/script/steamlink-rpi/source/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@
# Copyright (C) 2019-present Team LibreELEC (https://libreelec.tv)

import os
import shutil
import sys
import tarfile
import subprocess
import xbmcaddon
import xbmcgui
from hashlib import sha256
from pathlib import Path
from shutil import rmtree
from sys import exit
from tempfile import TemporaryDirectory
from time import sleep
from urllib.request import urlretrieve

sys.path.append('/storage/.kodi/addons/script.program.steamlink-rpi/resources')
import unix_ar


STEAMLINK_VERSION = "@STEAMLINK_VERSION@"
STEAMLINK_HASH = "@STEAMLINK_HASH@"
STEAMLINK_TARBALL_NAME = f"steamlink-rpi-bookworm-arm64-{STEAMLINK_VERSION}.tar.gz"
STEAMLINK_URL = f"http://media.steampowered.com/steamlink/rpi/bookworm/arm64/{STEAMLINK_TARBALL_NAME}"
ICU_URL = "@ICU_URL@"
ICU_HASH = "@ICU_HASH@"
ADDON_DIR = xbmcaddon.Addon().getAddonInfo("path")
PROGRESS_BAR = xbmcgui.DialogProgress()

Expand Down Expand Up @@ -55,6 +60,24 @@ def ProgressBarReport(chunk_count, chunk_size, total_size):
else:
PROGRESS_BAR.update(0, "Filesize Unknown")

def DownloadFile(url, destination, desired_hash):
""" Download file """
file_name = url.rsplit("/", 1)
PROGRESS_BAR.create("File Download", f"Downloading {file_name}...")
urlretrieve(url, destination, ProgressBarReport)

download_hash = GetSHA256Hash(destination)
if download_hash == desired_hash:
PROGRESS_BAR.update(100, f"File download complete.")
PROGRESS_BAR.close()
else:
PROGRESS_BAR.update(0, "Download Error: bad file hash. Try again later.")
sleep(5)
if os.path.isfile(destination):
os.remove(destination)
PROGRESS_BAR.close()
sys.exit(1)

def DownloadSteamlink():
""" Download Steam Link for RPi """
with TemporaryDirectory() as temp_dir:
Expand All @@ -74,12 +97,12 @@ def DownloadSteamlink():
PROGRESS_BAR.update(0, "Download Error: bad file hash. Try again later.")
sleep(5)
PROGRESS_BAR.close()
exit(1)
sys.exit(1)
else:
PROGRESS_BAR.update(0, "Download Error: bad download or missing file")
sleep(5)
PROGRESS_BAR.close()
exit(1)
sys.exit(1)

def PrepareSteamlink():
""" System preparation before launching Steam Link """
Expand All @@ -93,20 +116,41 @@ def PrepareSteamlink():
def StartSteamlink():
# Check if addon wants to update Steam Link
if os.path.isfile(f"{ADDON_DIR}/steamlink/version.txt"):
STEAMLINK_INSTALLED_VERSION = OutputFileContents(f"{ADDON_DIR}/steamlink/version.txt").rstrip()
steamlink_installed_version = OutputFileContents(f"{ADDON_DIR}/steamlink/version.txt").rstrip()

# Update Steamlink handling
if STEAMLINK_VERSION != STEAMLINK_INSTALLED_VERSION:
rmtree(f"{ADDON_DIR}/steamlink/")
if STEAMLINK_VERSION != steamlink_installed_version:
shutil.rmtree(f"{ADDON_DIR}/steamlink/")
os.remove(f"{ADDON_DIR}/prep.ok")

# Download Steam Link if not present
# Download needed files
if not os.path.isfile(f"{ADDON_DIR}/prep.ok"):
DownloadSteamlink()
with TemporaryDirectory() as temp_dir:
steamlink_tarball_path = os.path.join(temp_dir, STEAMLINK_TARBALL_NAME)
# Steam Link
DownloadFile(STEAMLINK_URL, steamlink_tarball_path, STEAMLINK_HASH)
if os.path.isfile(steamlink_tarball_path):
steamlink_tarball = tarfile.open(steamlink_tarball_path)
steamlink_tarball.extractall(path=f"{ADDON_DIR}/")
icu_deb_path = os.path.join(temp_dir, "icu.deb")
# Debian's icu package
DownloadFile(ICU_URL, icu_deb_path, ICU_HASH)
if os.path.isfile(icu_deb_path):
deb = unix_ar.open(icu_deb_path)
data_tarball = deb.open("data.tar.xz")
contents = tarfile.open(fileobj=data_tarball)
contents.extractall(os.path.join(temp_dir, "steamlink-icu"))
icu_lib_path = os.path.join(temp_dir, "steamlink-icu", "usr/lib/aarch64-linux-gnu")
shutil.copy(os.path.join(icu_lib_path, "libicudata.so.72"), f"{ADDON_DIR}/system-libs/", follow_symlinks=True)
shutil.copy(os.path.join(icu_lib_path, "libicui18n.so.72"), f"{ADDON_DIR}/system-libs/", follow_symlinks=True)
shutil.copy(os.path.join(icu_lib_path, "libicuuc.so.72"), f"{ADDON_DIR}/system-libs/", follow_symlinks=True)

# DownloadSteamlink()
PrepareSteamlink()

# Start Steamlink
xbmcgui.Dialog().notification("Steam Link", "Starting Steam Link", xbmcgui.NOTIFICATION_INFO, 3000)
steamlink_start_result = Execute(f"systemd-run {ADDON_DIR}/bin/steamlink-start.sh")


StartSteamlink()

0 comments on commit 68dc066

Please sign in to comment.