#!/bin/bash # maravento.com # # Launch MEGAsync Instances # Tested: Ubuntu 24.04 LTS # Fork: https://github.com/NicoVarg99/MEGA-Instances # Dependencies: # sudo apt install zenity libatk-adaptor libgail-common libgtk2.0-0 (or libgtk2.0-0t64 for Ubuntu 24.04) # Download and Install: # sudo wget -O /usr/bin/msyncs https://raw.githubusercontent.com/maravento/vault/master/scripts/bash/msyncs # sudo chmod 755 /usr/bin/msyncs # Run: # msyncs start|stop|status # Remove: # sudo rm -rf /home/$USER/.config/msyncs /usr/bin/msyncs echo "MEGAsync Instances Starting. Wait..." printf "\n" # check no-root if [ "$(id -u)" == "0" ]; then echo "❌ This script should not be run as root." exit 1 fi # check SO UBUNTU_VERSION=$(lsb_release -rs) UBUNTU_ID=$(lsb_release -is | tr '[:upper:]' '[:lower:]') if [[ "$UBUNTU_ID" != "ubuntu" || ( "$UBUNTU_VERSION" != "22.04" && "$UBUNTU_VERSION" != "24.04" ) ]]; then echo "Unsupported system. Use at your own risk" # exit 1 fi # check dependencies DEPENDENCIES=("zenity" "libatk-adaptor" "libgail-common" "libgtk2.0-0") for dep in "${DEPENDENCIES[@]}"; do if [[ "$dep" == "libgtk2.0-0" ]]; then # Check for both libgtk2.0-0 and libgtk2.0-0t64 if ! dpkg-query -W -f='${Status}' "libgtk2.0-0" 2>/dev/null | grep -q "install ok installed" && \ ! dpkg-query -W -f='${Status}' "libgtk2.0-0t64" 2>/dev/null | grep -q "install ok installed"; then echo "Dependency 'libgtk2.0-0' or 'libgtk2.0-0t64' is not installed. Aborting" exit 1 fi else if ! dpkg-query -W -f='${Status}' "$dep" 2>/dev/null | grep -q "install ok installed"; then echo "Dependency '$dep' is not installed. Aborting" exit 1 fi fi done # Check if MEGAsync is installed for pkg in megasync; do dpkg -s "$pkg" &>/dev/null || command -v "$pkg" &>/dev/null || { echo "❌ '$pkg' is not installed. Run:" echo "sudo apt install $pkg" exit 1 } done # check lock LOCKFILE="/tmp/msyncs.lock" if [[ -f $LOCKFILE ]]; then echo "Script $0 is already running" exit 1 fi touch $LOCKFILE cleanup() { rm -f "$LOCKFILE" } trap cleanup EXIT # Variables REALHOME="$HOME" MEGADIR="MEGA" FILEPATH=$REALHOME/.config/msyncs FILE=$FILEPATH/status ERR=0 VERSION="1.0" echo "REALHOME = $REALHOME" unset QT_SCALE_FACTOR 2>/dev/null export NO_AT_BRIDGE=1 export QT_ACCESSIBILITY=0 # Function to run zenity silently zenity () { /usr/bin/zenity "$@" 2>/dev/null } # Function to check dependencies checkDep () { if [[ `whereis $1` == "$1:" ]]; then >&2 echo "Dependency '$1' seems to be missing" ERR=1 fi } # Function to create a Desktop Entry and set it to start at system startup generateDesktopEntry () { DEPATH=$REALHOME/.config/autostart/msyncs.desktop mkdir -p $REALHOME/.config/autostart echo "[Desktop Entry]" > $DEPATH echo "Type=Application" >> $DEPATH echo "Exec=/usr/bin/msyncs start" >> $DEPATH echo "Name=msyncs" >> $DEPATH echo "Comment=Open all your MEGAsync instances" >> $DEPATH echo "Icon=/usr/share/icons/hicolor/256x256/apps/mega.png" >> $DEPATH echo "Hidden=false" >> $DEPATH chmod +x $DEPATH } # Installation function start () { checkDep "zenity" checkDep "megasync" if [[ $ERR -ne 0 ]]; then >&2 echo "Error: Install all required dependencies before running MEGAsync Instances" exit 1 fi frun } # Start MEGAsync frun () { if [ -f $FILE ]; then if [ "$(cat $FILE)" == "1" ]; then echo "MEGAsync Instances are already configured, launching the instances..." killall megasync 2> /dev/null # Close open megasync instances # Launch each instance in its corresponding folder for d in "$REALHOME/$MEGADIR"/*/ ; do echo "Launching $d" HOME="$d" # Asegúrate de usar comillas para manejar espacios nohup megasync >/dev/null 2>&1 & done exit 0 fi fi echo "MEGAsync Instances are not configured. Will now start the configuration." if zenity --question --no-wrap --text="This is the first time you are running MEGAsync Instances.\nIn order to continue we must delete your existing MEGAsync instance.\nPress Yes to continue, No to abort."; then { killall megasync # Close open megasync instances rm -f $REALHOME/.config/autostart/msyncs.desktop rm -rf $MEGADIR rm -rf $FILEPATH } >/dev/null 2>&1 & else exit fi # Inicializar INSTNUM INSTNUM=0 # 1-9 number while [[ ! $INSTNUM =~ ^[1-9]$ ]]; do INSTNUM=$(zenity --entry --text="How many MEGAsync instances do you need? (1-9)") # check valid number if [[ ! $INSTNUM =~ ^[1-9]$ ]]; then zenity --error --text="Please enter a valid number between 1 and 9." fi done mkdir -p "$REALHOME/$MEGADIR" for (( i=1; i<=INSTNUM; i++ )); do NAME=$(zenity --entry --text="Insert the name for instance $i/$INSTNUM") ARRAY[$i]=$NAME mkdir -p "$REALHOME/$MEGADIR/$NAME" done # Required Environment Variables export GTK_MODULES="gail:atk-bridge" export QT_QPA_PLATFORMTHEME="gtk2" for (( i=1; i<=INSTNUM; i++ )); do zenity --warning --text="Instance ${ARRAY[i]} ($i/$INSTNUM). Close it after the configuration." HOME="$REALHOME/$MEGADIR/${ARRAY[$i]}" nohup megasync >/dev/null 2>&1 & done generateDesktopEntry zenity --warning --text="Will now launch all the instances. They will also start at every startup." echo 1 > "$FILE" # Mark as configured #bash "$0" & # Ejecutar de nuevo el script en segundo plano sleep 1 } # Stop MEGAsync stop() { echo "Stopping MEGAsync Instances..." killall megasync 2>/dev/null # Cerrar instancias de megasync echo "MEGAsync Instances stopped." } # Show status of MEGAsync status () { if pidof megasync > /dev/null; then echo "MEGAsync is running." else echo "MEGAsync is not running." fi } # Create configuration file if missing if [ ! -f $FILE ]; then mkdir -p $FILEPATH echo 0 > $FILE fi # Handle script arguments case "$1" in start) start ;; stop) stop ;; status) status ;; *) echo "Usage: $0 {start|stop|status}" exit 1 ;; esac