0

So I was working on this script to auto install minecraft and i began to wonder is there a better way to do this?

#!/bin/bash

sudo apt-get upgrade
sudo apt-get update
sudo apt-get autoclean

echo " Jobs Done!"


sudo add-apt-repository ppa:webupd8team/java
sudo apt update; sudo apt install oracle-java8-installer
sudo apt install oracle-java8-set-default
sudo apt-get install default-jre
sudo apt-get autoclean
sudo add-apt-repository ppa:flexiondotorg/minecraft
sudo apt-get install minecraft-installer
sudo apt-get autoclean



echo "This world is about to get crafty!"


cd .minecraft
chmod 777 launcher.jar
java -Xmx3G -Xms3G -jar launcher.jar

The reason I ask is I wanted to make a way to easily install and then open minecraft for my friends that are a little less tech savy but could at least run a script. Would be curious the thought on the matter.

  • Do you want to see the output of the apt commands or not? – Panki Dec 19 '18 at 13:45
0

You can add the repositories first (make shure that they are trustworthy), then update, upgrade everything.

(Note: that you should update first and then upgrade, because the other way around, nothing will happen.)

The -y flags should prevent apt from asking every time. apt-install allows multiple packages to be specified.

The permissions 750 should suffice.

This should work (further explainations in the script comments):

#!/bin/bash

#add repos
sudo add-apt-repository ppa:webupd8team/java -y
sudo add-apt-repository ppa:flexiondotorg/minecraft -y

#make sure everything is up-to-date
sudo apt update
sudo apt upgrade -y

#install the packages
sudo apt install -y oracle-java8-installer oracle-java8-set-default default-jre minecraft-installer

#cleanup (not necessarily required)
sudo apt-get autoclean

echo "This world is about to get crafty!"

#if the .minecraft folder is located under /home/username/.minecraft, you should use ~/.minecraft
#temporarily change directory
pushd ~/.minecraft

#set permissions
chmod 750 launcher.jar

#start application in background, in order to finish script, the '&' is responsible for that
java -Xmx3G -Xms3G -jar launcher.jar &

#undo temporary directory change
popd
0

You can improve this by atleast checking the return codes of your commands (i.e. making sure everything worked). You can do this with either && or the special variable $?.

Also, why not add all the repos first, then do apt update only once? This should save some time.

chmod 777 is pretty much always a bad idea, giving the user execution rights should be enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.