Launcher icon indicating copy to clipboard operation
Launcher copied to clipboard

Linux wrapper script can end up with a corrupted tarball and get stuck

Open peterix opened this issue 4 years ago • 4 comments

Operating System

Linux

Description of bug

~/.local/share/multimc/MultiMC
MultiMC Dir: /home/isaiah/.local/share/multimc
No missing dependencies found.
/home/isaiah/.local/share/multimc/MultiMC: line 93: 14152 Segmentation fault      "${MMC_DIR}/bin/MultiMC" -d "${MMC_DIR}" "$@"

Steps to reproduce

  • User installs the deb
  • User tries to start MultiMC
  • The run script does first time setup by downloading the tarball and extracting it
  • This operation fails
  • User is stuck with a broken install that can't self-fix and a whole lot of confusion

Suspected cause

Missing hash checks?

We should do hash checks. We should also redownload / redeploy the launcher if it fails to work, or at least tell the user how to fix the problem.

This issue is unique

  • [X] I have searched the issue tracker and did not find an issue describing my bug.

peterix avatar Jul 26 '21 17:07 peterix

diff --git a/run.sh b/run1.sh
old mode 100644
new mode 100755
index c493a51..b485ea5
--- a/run.sh
+++ b/run1.sh
@@ -9,15 +9,28 @@ else
     PACKAGE="mmc-stable-lin32.tar.gz"
 fi
 
-deploy() {
+download(){
     mkdir -p $INSTDIR
     cd ${INSTDIR}
 
     wget --progress=dot:force "https://files.multimc.org/downloads/${PACKAGE}" 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --auto-close --auto-kill --title="Downloading MultiMC..."
+    wget --progress=dot:force "https://files.multimc.org/downloads/${PACKAGE}.sig" 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --auto-close --auto-kill --title="Downloading MultiMC signature..."
+}
 
-    tar -xzf ${PACKAGE} --transform='s,MultiMC/,,'
-    rm ${PACKAGE}
-    chmod +x MultiMC
+deploy() {
+    cd ${INSTDIR}
+    sha256sum -c ${PACKAGE}.sig
+    if [ $?=0 ]
+    then
+        tar -xzf ${PACKAGE} --transform='s,MultiMC/,,'
+        rm ${PACKAGE} ${PACKAGE}.sig
+        chmod +x MultiMC
+    else
+        echo "Signature didn't match, redownloading..."
+        rm ${PACKAGE} ${PACKAGE}.sig
+        download
+        deploy
+    fi
 }
 
 runmmc() {
@@ -26,6 +39,7 @@ runmmc() {
 }
 
 if [[ ! -f ${INSTDIR}/MultiMC ]]; then
+    download
     deploy
     runmmc "$@"
 else

Quick patch I cooked up to fix this issue, needs proper testing.

ImperatorStorm avatar Jul 26 '21 18:07 ImperatorStorm

I would additionally add a file like extract.ok or something like that, which is created after extracting, and its non-presence would trigger re-extracting (checking the hash and redownloading if necessary). That would provide extra "failsafeness".

kb-1000 avatar Jul 26 '21 18:07 kb-1000

diff --git a/run.sh b/run1.sh
old mode 100644
new mode 100755
index c493a51..6b0f8da
--- a/run.sh
+++ b/run1.sh
@@ -9,15 +9,36 @@ else
     PACKAGE="mmc-stable-lin32.tar.gz"
 fi
 
-deploy() {
+download(){
     mkdir -p $INSTDIR
     cd ${INSTDIR}
 
     wget --progress=dot:force "https://files.multimc.org/downloads/${PACKAGE}" 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --auto-close --auto-kill --title="Downloading MultiMC..."
+    wget --progress=dot:force "https://files.multimc.org/downloads/${PACKAGE}.sig" 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --auto-close --auto-kill --title="Downloading MultiMC signature..."
+}
 
-    tar -xzf ${PACKAGE} --transform='s,MultiMC/,,'
-    rm ${PACKAGE}
-    chmod +x MultiMC
+deploy() {
+    cd ${INSTDIR}
+    sha256sum -c ${PACKAGE}.sig
+    if [ $?=0 ]
+    then
+        tar -xzf ${PACKAGE} --transform='s,MultiMC/,,'
+        rm ${PACKAGE} ${PACKAGE}.sig
+        chmod +x MultiMC
+        touch extract.ok
+    else
+        echo "Signature didn't match, redownloading..."
+        rm ${PACKAGE} ${PACKAGE}.sig
+        download
+        deploy
+    fi
+    if [ -e extract.ok ]
+    then
+        echo "Extraction succeeded..."
+    else
+        echo "Extraction failed, rechecking hash..."
+        deploy
+    fi
 }
 
 runmmc() {
@@ -26,6 +47,7 @@ runmmc() {
 }
 
 if [[ ! -f ${INSTDIR}/MultiMC ]]; then
+    download
     deploy
     runmmc "$@"
 else

Revised patch with @kb-1000's suggestion, also needs proper testing

ImperatorStorm avatar Jul 26 '21 18:07 ImperatorStorm

also related to https://github.com/MultiMC/Launcher/issues/1570

phit avatar Dec 22 '24 20:12 phit