Guest User

update-ffmpeg from Vivaldi Browser

a guest
Sep 13th, 2025
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.59 KB | Source Code | 0 0
  1. #!/bin/sh -eu
  2.  
  3. VIVALDI_VERSION=7.5.3735.74
  4. VIVALDI_VERSION_SHORT="${VIVALDI_VERSION%\.*\.*}"
  5. FFMPEG_VERSION=120726
  6. FFMPEG_MIN_GLIBC_ZIP=17
  7.  
  8. available () {
  9.   command -v "$1" >/dev/null 2>&1
  10. }
  11.  
  12. available ldd && LIBC_MINOR_VERSION="$(ldd --version | head -n1 | sed -n '/^ldd .* [2-9]\./s/.*\.\([0-9]\+\)$/\1/p')"
  13. LIBC_MINOR_VERSION="${LIBC_MINOR_VERSION:-17}"
  14. check_glibc () {
  15.   if [ "$LIBC_MINOR_VERSION" -lt "$1" ]; then
  16.     echo "Your glibc version is too old to search for a replacement libffmpeg that supports proprietary media" >&2
  17.     exit 1
  18.   fi
  19. }
  20.  
  21. FFMPEG_USE_SNAP=0
  22. case amd64 in
  23.   amd64|x86_64)
  24.     FFMPEG_LENGTH_SNAP=3486640
  25.     FFMPEG_LIB_OFFSET_SNAP=17341361
  26.     FFMPEG_MIN_GLIBC_SNAP=35
  27.     FFMPEG_SUM_SNAP=173067e361ed2ce36c2900b955e0e628f147a46750f77c10fc7591318b827c45
  28.     FFMPEG_SUM_ZIP=4e29ddd6850f79e84693979103ed96d9da4b34889deb386b15050197b61a6f74
  29.     FFMPEG_URL_SNAP=https://api.snapcraft.io/api/v1/snaps/download/XXzVIXswXKHqlUATPqGCj2w2l7BxosS8_82.snap
  30.     FFMPEG_URL_ZIP=https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download/0.101.0/0.101.0-linux-x64.zip
  31.     FFMPEG_XZ_OFFSET_SNAP=97
  32.     check_glibc "$FFMPEG_MIN_GLIBC_ZIP"
  33.     if [ "$LIBC_MINOR_VERSION" -ge "$FFMPEG_MIN_GLIBC_SNAP" ]; then
  34.       FFMPEG_USE_SNAP=1
  35.     fi
  36.     ;;
  37.   arm64|aarch64)
  38.     FFMPEG_LENGTH_SNAP=3014344
  39.     FFMPEG_LIB_OFFSET_SNAP=15009857
  40.     FFMPEG_MIN_GLIBC_SNAP=35
  41.     FFMPEG_SUM_SNAP=b02307b39bceac203b75c2669898c300257f0849acf2cdf6a1ee1325606b2f30
  42.     FFMPEG_URL_SNAP=https://api.snapcraft.io/api/v1/snaps/download/XXzVIXswXKHqlUATPqGCj2w2l7BxosS8_83.snap
  43.     FFMPEG_USE_SNAP=1
  44.     FFMPEG_XZ_OFFSET_SNAP=97
  45.     check_glibc "$FFMPEG_MIN_GLIBC_SNAP"
  46.     ;;
  47.   armhf|armv7hl)
  48.     FFMPEG_LENGTH_SNAP=2200872
  49.     FFMPEG_LIB_OFFSET_SNAP=10961465
  50.     FFMPEG_MIN_GLIBC_SNAP=35
  51.     FFMPEG_SUM_SNAP=7c6440f4648beeb7e0066acc3611d0c6d5ff9f748e596082d613f269876b553a
  52.     FFMPEG_URL_SNAP=https://api.snapcraft.io/api/v1/snaps/download/XXzVIXswXKHqlUATPqGCj2w2l7BxosS8_84.snap
  53.     FFMPEG_USE_SNAP=1
  54.     FFMPEG_XZ_OFFSET_SNAP=97
  55.     check_glibc "$FFMPEG_MIN_GLIBC_SNAP"
  56.     ;;
  57. esac
  58.  
  59. FFMPEG_INSTALL_DIR="/var/opt/vivaldi/media-codecs-$FFMPEG_VERSION"
  60. if [ "${1-}" = "--system" ]; then
  61.   if [ "${USER:-}" != "root" ]; then
  62.     echo "You may need to be root (or rerun this command with sudo)" >&2
  63.   fi
  64.   shift 1
  65. elif [ "${1-}" = "--user" ]; then
  66.   FFMPEG_INSTALL_DIR="$HOME/.local/lib/vivaldi/media-codecs-$FFMPEG_VERSION"
  67.   shift 1
  68. fi
  69.  
  70. cleanup_files () {
  71.   # Cleanup needs to be able to handle files from earlier installs, where the
  72.   # numbered path could be different.
  73.   if ls "${FFMPEG_INSTALL_DIR%/media-codecs-*}"/media-codecs-*/libffmpeg.so* >/dev/null 2>&1; then
  74.     rm -f "${FFMPEG_INSTALL_DIR%/media-codecs-*}"/media-codecs-*/libffmpeg.so* "${FFMPEG_INSTALL_DIR%/media-codecs-*}/media-codecs-$VIVALDI_VERSION_SHORT"
  75.   fi
  76.   if [ -d "${FFMPEG_INSTALL_DIR%/media-codecs-*}" ]; then
  77.     find "${FFMPEG_INSTALL_DIR%/media-codecs-*}" -depth -type d -empty -exec rmdir {} \;
  78.   fi
  79. }
  80.  
  81. if [ "${1-}" = "--undo" ]; then
  82.   cleanup_files
  83.   exit
  84. fi
  85.  
  86. if ! available sha256sum; then
  87.   echo "sha256sum is not installed; aborting" >&2
  88.   exit 1
  89. fi
  90.  
  91. # If a suitable file already exists we do not need to do anything and
  92. # can exit early.
  93. check_valid_libffmpeg () {
  94.   if [ -e "$FFMPEG_INSTALL_DIR/libffmpeg.so" ] && echo "$1  $FFMPEG_INSTALL_DIR/libffmpeg.so" | sha256sum -c >/dev/null 2>&1; then
  95.     echo "Proprietary media codecs ($FFMPEG_VERSION) was already present"
  96.     chmod -R u+rwX,go+rX-w "${FFMPEG_INSTALL_DIR%/media-codecs-*}"
  97.     exit 0
  98.   fi
  99. }
  100. if [ "$FFMPEG_USE_SNAP" = '1' ]; then
  101.   check_valid_libffmpeg "$FFMPEG_SUM_SNAP"
  102. else
  103.   check_valid_libffmpeg "$FFMPEG_SUM_ZIP"
  104. fi
  105.  
  106. # We don't need to check certificates because we verify package contents with
  107. # checksums. By avoiding the check we also allow for download on a distro that
  108. # lacks an up to date certificate store (see: VB-68785)
  109. if available wget; then
  110.   DOWNLOAD="wget -qO- --no-check-certificate"
  111.   CHECK_DOWNLOAD="wget --spider"
  112. elif available curl; then
  113.   DOWNLOAD="curl -sL --insecure"
  114.   CHECK_DOWNLOAD="curl -LI"
  115. else
  116.   echo "Neither Wget nor cURL is installed; aborting" >&2
  117.   exit 1
  118. fi
  119.  
  120. # Remove any previous version before installing the new one
  121. cleanup_files
  122.  
  123. # Fetch and extract libffmpeg
  124. mkdir -p "$FFMPEG_INSTALL_DIR"
  125. check_valid_libffmpeg_after_download () {
  126.   chmod -R u+rwX,go+rX-w "${FFMPEG_INSTALL_DIR%/media-codecs-*}"
  127.   if ! echo "$1  $2" | sha256sum -c >/dev/null 2>&1; then
  128.     echo "The extracted libffmpeg.so does not match the expected sha256sum; aborting" >&2
  129.     cleanup_files
  130.     exit 1
  131.   fi
  132.   mv "$2" "$FFMPEG_INSTALL_DIR/libffmpeg.so"
  133.   ln -fs "$FFMPEG_INSTALL_DIR" "${FFMPEG_INSTALL_DIR%/media-codecs-*}/media-codecs-$VIVALDI_VERSION_SHORT"
  134.   echo "Proprietary media codecs ($FFMPEG_VERSION) has been installed (PLEASE RESTART VIVALDI)"
  135. }
  136. FFMPEG_PARTIAL="$(mktemp "$FFMPEG_INSTALL_DIR/libffmpeg.so.XXXX")"
  137. echo "Downloading..."
  138. if [ "$FFMPEG_USE_SNAP" = '1' ]; then
  139.   # We hide the download errors here because wget/curl will complain since
  140.   # they are prevented from completing their download. This may confuse
  141.   # the user, causing them to suspect something has gone wrong.
  142.   $DOWNLOAD "$FFMPEG_URL_SNAP" 2>/dev/null | tail -c+"$FFMPEG_XZ_OFFSET_SNAP" | xz -dqq | tail -c+"$FFMPEG_LIB_OFFSET_SNAP" | head -c"$FFMPEG_LENGTH_SNAP" > "$FFMPEG_PARTIAL" ||:
  143.   check_valid_libffmpeg_after_download "$FFMPEG_SUM_SNAP" "$FFMPEG_PARTIAL"
  144. else
  145.   $DOWNLOAD "$FFMPEG_URL_ZIP" | gzip -d > "$FFMPEG_PARTIAL" ||:
  146.   check_valid_libffmpeg_after_download "$FFMPEG_SUM_ZIP" "$FFMPEG_PARTIAL"
  147. fi
Advertisement
Add Comment
Please, Sign In to add comment