#!/bin/bash # Shutdown the program and delete all tmp files function shutdown { # Cleanup [ -d $TMP ] && rm -fr $TMP exit 0 } # Never run this program as root if [[ $EUID -eq 0 ]]; then echo >&2 "This program should never be run using sudo or as the root user!\n" exit 1 fi # Basic variables warning=0 VERSION=2 BACKTITLE="Alternative Downloader for Curse Minecraft Modpacks V0.3" MMCDIR="" MMCBIN="" # Check for needed programs if [ "$(which jq)" = "" ] || [ "$(which recode)" = "" ] || [ "$(which dialog)" = "" ]; then echo >&2 "You are missing one or more of the following programs:" echo >&2 "- jq (Processing json data on the command line)" echo >&2 "- recode (Translate html encoded text back to ascii)" echo >&2 "- dialog (Show some fancy GUI on the command line)" while true; do read -p "Do you wish to install the missing programs? " yn case $yn in [Yy]* ) if [ ! "$(which apt-get)" = "" ]; then sudo apt-get -y install jq recode dialog; elif [ ! "$(which pacman)" = "" ]; then sudo pacman -S jq recode dialog elif [ ! "$(which yum)" = "" ]; then sudo yum install jq recode dialog elif [ ! "$(which zypper)" = "" ]; then sudo zypper jq recode dialog elif [ ! "$(which emerge)" = "" ]; then sudo emerge jq recode dialog else echo "There is no known package manger installed. Please install the programs manually and start this program again!" exit 1 fi break ;; [Nn]* ) exit 1;; * ) echo "Please answer yes or no.";; esac done fi # Reading existing config if [ -r /tmp/curse_downloader_config ]; then . /tmp/curse_downloader_config fi if [ "$warning" -lt "$VERSION" ] ; then dialog --backtitle "$BACKTITLE" --title "What is this?" --yesno "\ \nWelcome! This is my alternative installer for Minecraft mod packs \ hosted on curse.com. Unfortunately the curse launcher is only available \ on Windows at the moment. Providing modpacks for Linux is a pain for \ the modpack authors and the users. This program is intended to make \ this a bit easier for you.\n\n\ This program was written by EfficiencyVI. It is not related, maintained \ or affiliated with curse.com. It is also in an early development. That \ means expect it to not work, show odd errors, destroy your data or kill \ your hamster!\n\n\ I put a lot of effort in ensuring that this program works as best as \ possible and I'm pretty sure everything will work for you. But I will \ take no resposibility or guarantee that everything goes wrong no matter \ if you use it correct or not.\n\n\ Only if you are okay to be a test bunny click \"Yes\" to proceed!" 30 70 # Read response from dialog dialog=$? case $dialog in 1|255) exit 1;; *) echo "warning=$VERSION" >> /tmp/curse_downloader_config;; esac fi # Start a new installation # Create temp file for menus and temp data TMP=/tmp/curse.$$ INPUT=$TMP/input OUTPUT=$TMP/output mkdir $TMP > /dev/null 2>&1 rm -fr $TMP/* > /dev/null 2>&1 mkdir $TMP/modpack > /dev/null 2>&1 # Check for installation path # Fixes issue #1 Thanks to marcmagus loc=($(ls -a $HOME | grep -i "multimc")) for i in "${!loc[@]}" do # Skip standard folder and use as fallback if [ "${loc[i]}" = ".MultiMC" ] ; then MMCDIR=$HOME"/.MultiMC" MMCBIN=$MMCDIR"/MultiMC" continue fi if [ -d $HOME/${loc[i]}/instances ] ; then dialog --backtitle "$BACKTITLE" --title "Possible installation of MultiMC found" --yesno "\ \nThere is a possible installation of MultiMC on your system. The folder is located \ in $HOME/${loc[i]}. \ \n\nMost likely this program was installed by a software manager or by yourself. \ If you are not sure about this select \"No\" to search for more possible installations \ or install the program in the default directory. \ \n\nIf you want to use this installation select \"Yes\". \"No\" will search for more \ MultiMC instances or use an existing standard installation or install it for you." 30 70 # Read response from dialog dialog=$? case $dialog in 0) MMCDIR=$HOME/${loc[i]} if [ -x $HOME/${loc[i]}/MultiMC ] ; then MMCBIN=$HOME/${loc[i]}/MultiMC else # find alternative binary location (for the real weird) locb=(${PATH//:/ }) for j in "${!locb[@]}" do tmpb=$(ls ${locb[j]} | grep -i "multimc") echo $tmpb if [ ! "$tmpb" = "" ] && [ -x ${locb[j]}/$tmpb ] ; then dialog --backtitle "$BACKTITLE" --title "Possible binary of MultiMC found" --yesno "\ \nThere is a possible binary file of MultiMC in ${locb[j]}/$tmpb. Do you want to use this binary?" 30 70 dialogb=$? case $dialogb in 0) MMCBIN=${locb[j]}/$tmpb break ;; esac fi done fi break ;; esac fi done if [ "$MMCDIR" = "" ] || [ "$MMCBIN" = "" ] ; then dialog --backtitle "$BACKTITLE" --title "An error occured" --msgbox "\ \nOh oh! Sorry, but I could not determine a suitable installation location \ or binary file. If you don't know what to do. No panic! \ \n\n1.) Restart this program \ \n2.) Select \"No\" when it shows you an existing installation on your system \ \n3.) Install MultiMC in the default location" 30 70 fi # Only offer installation if standard path was not changed # and MultiMC is not installed if [ "$MMCDIR" = "" ] && [ ! -d $HOME/.MultiMC/ ] ; then dialog --backtitle "$BACKTITLE" --title "About MultiMC" --yesno "\ \nMultiMC is an alternative launcher for Minecraft. It gives you a lot \ of options to manage multiple instances of Minecraft like Modpacks, \ Vanilla customization and so on. It is the easiest way to make custom \ modpacks running on your computer.\n\n\ If you click yes this program will try to download the correct version \ for your plattform. The software is installed in your home directory in \ the \".MultiMC\" folder.\n\nIf you want to know more about MultiMC visit \ the official website and support the authors. https://multimc.org" 30 70 # Read response from dialog dialog=$? case $dialog in 0) if [ ! -d ~/.MultiMC/ ]; then if [ $(getconf LONG_BIT) = "64" ]; then URL="https://files.multimc.org/downloads/mmc-stable-lin64.tar.gz" else URL="https://files.multimc.org/downloads/mmc-stable-lin32.tar.gz" fi wget -O $TMP/MultiMC.tar.gz "$URL" 2>&1 | \ stdbuf -o0 awk '/[.] +[0-9][0-9]?[0-9]?%/ { print substr($0,63,3) }' | \ dialog --backtitle "$BACKTITLE" --title "MultiMC setup" --gauge "Downloading MultiMC" 10 100 tar -xzf $TMP/MultiMC.tar.gz -C $TMP mkdir $HOME/.MultiMC cp -r $TMP/MultiMC/* $HOME/.MultiMC/ MMCDIR=$HOME"/.MultiMC" MMCBIN=$MMCDIR"MultiMC" fi ;; *) if [ "$MMCDIR" = "" ] || [ "$MMCBIN" = "" ] ; then dialog --backtitle "$BACKTITLE" --title "An error occured" --msgbox "\ \nOh oh! Sorry, but I could not determine a suitable location for MultiMC. \ If you don't know what to do, restart this program and select the standard \ installation for your system." 30 70 shutdown fi esac fi for i in $(seq 1 10) do wget --quiet -O - https://mods.curse.com/modpacks/minecraft?page=$i | sed -n -e 's!.*