Last active
December 19, 2018 09:21
-
-
Save lexxy23/0cc41a1be6680e3c5c11b69f87f0b8c1 to your computer and use it in GitHub Desktop.
dummy shell bash script to install Visual Studio Code on MacOS, assuming the executing user has sudo rights ^^
This file contains 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
#!/bin/bash | |
# Script to install VisualStudio Code, Atom or Github Desktop | |
# the app settings | |
DLURL="" | |
APPNAME="" | |
# our settings | |
GLOBALINST=0 | |
TMPDIR="/tmp" | |
APPFOLDER="$HOME/Applications" | |
TMPFILE="$TMPDIR/tmp.zip" | |
function printHelp(){ | |
echo "$0 = default is install Visual Studio Code latest version" | |
echo "-l = local user installation" | |
echo "-c = installs the Visual Studio Code editor" | |
echo "-g = global installation" | |
echo "-a = installs the Atom editor" | |
echo "-h = installs the Github Desktop client" | |
} | |
while getopts ':lgahc' OPTION ; do | |
case "$OPTION" in | |
l) | |
APPFOLDER="$HOME/Applications" | |
GLOBALINST=0 | |
;; # local installation | |
g) | |
APPFOLDER="/Applications" | |
GLOBALINST=1 | |
;; # global installation | |
a) # install atom :D | |
DLURL="https://atom.io/download/mac" | |
APPNAME="Atom.app" | |
;; | |
h) # install github desktop | |
DLURL="https://central.github.com/deployments/desktop/desktop/latest/darwin" | |
APPNAME="GitHub Desktop.app" | |
;; | |
c) | |
DLURL="https://go.microsoft.com/fwlink/?LinkID=620882" | |
APPNAME="Visual Studio Code.app" | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
printHelp | |
exit 1 | |
;; | |
*) | |
printHelp | |
;; | |
esac | |
done | |
if [ -z "$DLURL" ]; then | |
echo "No download url set, exiting" | |
printHelp | |
exit 2 | |
fi | |
echo "Downloading file from $DLURL.." | |
curl -L -o $TMPFILE $DLURL | |
RC=$? | |
if [ ! "$RC" -eq 0 ]; then | |
echo "Error when downloading the file from $DLURL." | |
exit 1 | |
fi | |
echo "Unpacking.." | |
if [ 1 = $GLOBALINST ]; then | |
sudo unzip -d "$TMPDIR" $TMPFILE | |
else | |
unzip -d "$TMPDIR" $TMPFILE | |
fi | |
if [ -r "$TMPDIR/$APPNAME" ]; then | |
echo "Removing existing old app $APPNAME.." | |
sudo rm -rf "$APPFOLDER/$APPNAME" | |
echo "Move app to app folder" | |
if [ 1 = $GLOBALINST ]; then | |
sudo mv "$TMPDIR/$APPNAME" "$APPFOLDER/" | |
else | |
mv "$TMPDIR/$APPNAME" "$APPFOLDER/" | |
fi | |
fi | |
echo "Remove tmp file.." | |
rm $TMPFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment