Created
June 24, 2026 14:20
-
-
Save dakk/766928c85cf3b7fb2f8e60973c3a5967 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # ============================ config ============================ | |
| SRC_DIR="$HOME/MEGAsync" # where to clone the app | |
| VCPKG_ROOT="$HOME/mega/vcpkg" # your existing vcpkg | |
| QT_PREFIX="/usr/lib64/qt6" # Gentoo Qt6 | |
| BUILD_DIR="$SRC_DIR/build_release" | |
| INSTALL_PREFIX="/opt/megasync-qt6" # self-contained install dir | |
| BRANCH="feature/qt6-migration" | |
| APP_FORK="git@github.com:dakk/MEGAsync.git" | |
| SDK_FORK="git@github.com:dakk/mega-sdk.git" | |
| JOBS="$(nproc)" | |
| # ===================== 0. vcpkg (clone if missing) ===================== | |
| if [ ! -e "$VCPKG_ROOT/bootstrap-vcpkg.sh" ]; then | |
| echo ">> vcpkg not found at $VCPKG_ROOT — cloning" | |
| git clone https://github.com/microsoft/vcpkg "$VCPKG_ROOT" | |
| fi | |
| # ===================== 1. clone your MEGAsync qt6 branch (idempotent) ===================== | |
| if [ ! -e "$SRC_DIR/CMakeLists.txt" ]; then | |
| rm -rf "$SRC_DIR" | |
| git clone -b "$BRANCH" "$APP_FORK" "$SRC_DIR" | |
| fi | |
| cd "$SRC_DIR" | |
| # ===================== 2. SDK from YOUR fork's qt6 branch (idempotent) ===================== | |
| # (.gitmodules points at upstream meganz/sdk, which lacks the Qt6 binding fix.) | |
| if [ ! -e src/MEGASync/mega/CMakeLists.txt ]; then | |
| rm -rf src/MEGASync/mega | |
| git clone --recursive -b "$BRANCH" "$SDK_FORK" src/MEGASync/mega | |
| fi | |
| # ===================== 3. configure (Release, relocatable RPATH) ===================== | |
| cmake -DVCPKG_ROOT="$VCPKG_ROOT" \ | |
| -DCMAKE_PREFIX_PATH="$QT_PREFIX" \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DCMAKE_INSTALL_LIBDIR=lib \ | |
| -DCMAKE_INSTALL_RPATH='$ORIGIN/../lib' \ | |
| -S "$SRC_DIR" -B "$BUILD_DIR" | |
| # ===================== 4. build (app + isolated gfxworker + resources) ===================== | |
| cmake --build "$BUILD_DIR" --target MEGAsync -j"$JOBS" | |
| # ===================== 5. install to /opt (needs root) ===================== | |
| sudo cmake --install "$BUILD_DIR" --prefix "$INSTALL_PREFIX" | |
| # ===================== 6. discover where the binary and libs actually landed ===================== | |
| # (GNUInstallDirs may put libs in lib/ or lib64/; don't assume.) | |
| BIN_PATH="$(sudo find "$INSTALL_PREFIX" -type f -name megasync -print -quit)" | |
| LIB_PATH="$(sudo find "$INSTALL_PREFIX" -type f -name 'libavutil.so*' -print -quit)" | |
| if [ -z "$BIN_PATH" ] || [ -z "$LIB_PATH" ]; then | |
| echo "ERROR: could not locate installed binary or libs under $INSTALL_PREFIX:" >&2 | |
| echo " binary='$BIN_PATH' lib='$LIB_PATH'" >&2 | |
| sudo find "$INSTALL_PREFIX" -maxdepth 2 | sort >&2 | |
| exit 1 | |
| fi | |
| LIB_DIR="$(dirname "$LIB_PATH")" | |
| echo ">> binary: $BIN_PATH" | |
| echo ">> libs: $LIB_DIR" | |
| # make the bundled vcpkg libs resolve each other relative to themselves | |
| sudo find "$LIB_DIR" -maxdepth 1 -name '*.so*' -type f \ | |
| -exec patchelf --set-rpath '$ORIGIN' {} \; | |
| # ===================== 7. launcher + PATH symlink ===================== | |
| # The launcher points LD_LIBRARY_PATH at the real lib dir, so it works no matter | |
| # whether the libs landed in lib/ or lib64/. | |
| sudo tee "$INSTALL_PREFIX/run-megasync.sh" >/dev/null <<EOF | |
| #!/usr/bin/env bash | |
| export LD_LIBRARY_PATH="$LIB_DIR\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}" | |
| exec "$BIN_PATH" "\$@" | |
| EOF | |
| sudo chmod +x "$INSTALL_PREFIX/run-megasync.sh" | |
| sudo ln -sf "$INSTALL_PREFIX/run-megasync.sh" /usr/local/bin/megasync-qt6 | |
| echo | |
| echo "Installed to $INSTALL_PREFIX" | |
| echo " binary: $BIN_PATH" | |
| echo " libs: $LIB_DIR" | |
| echo " resources: $INSTALL_PREFIX/share/megasync/resources/*.rcc" | |
| echo "Run: megasync-qt6 (or $INSTALL_PREFIX/run-megasync.sh)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment