Skip to content

Instantly share code, notes, and snippets.

@filipeaguiar
Last active May 2, 2016 13:58
Show Gist options
  • Save filipeaguiar/f49bae37153e8d31ca68f04b8fde95e6 to your computer and use it in GitHub Desktop.
Save filipeaguiar/f49bae37153e8d31ca68f04b8fde95e6 to your computer and use it in GitHub Desktop.
Script Installer

installScripts.sh

This script downloads every shell script from an Github user's Gist in a folder on the user's workspace. Then it sets up the $PATH variable to include the .scripts folder, which contains symlinks to every script downloaded.

Instalation

This is how you can run this script:

$ export GITUSER="<your Github username>"
$ curl -o- -L https://git.io/vwMTa | bash

And that's it! You're done!

#!/bin/bash
SCRIPTDIR=".scripts"
SOURCEDIR="$SCRIPTDIR/source"
function getGists {
GISTS=$(curl https://api.github.com/users/$GITUSER/gists | grep "raw_url" | grep ".sh" | cut -d":" -f3 | sed -e 's/\/\///g' -e 's/\"//g' -e 's/,//g')
}
function getName {
name=$(echo ${1##gist.githubusercontent.com})
name=$(echo ${name##/*/})
}
function aviso {
COLS=$(tput cols)
printf -v REST "%*s" $(((COLS - ${#1}) / 2))
tput setaf 0
tput setab 3
printf "%*s" $COLS "$1$REST"
tput sgr0
echo
}
if [ ! -d $HOME/$SOURCEDIR ];
then
aviso "Criando diretrios"
mkdir $HOME/.scripts
aviso "Diretrio .scripts criado"
mkdir $HOME/.scripts/source
aviso "Diretrio .scripts/source criado"
fi
cd $HOME/$SOURCEDIR
getGists
for gist in $GISTS;
do
getName $gist
if [ ! -f $name ];
then
curl "https://$gist" -o $name
aviso "Arquivo $name Salvo"
else
aviso "arquivo $name ja existente"
fi
done
chmod +x $HOME/$SOURCEDIR/*.sh
aviso "Permissoes Configuradas"
for file in $(ls $HOME/$SOURCEDIR/)
do
n=${file%.sh}
ln -sf $HOME/$SOURCEDIR/$file /$HOME/$SCRIPTDIR/$n
aviso "link simbolico $n criado"
done
if [ "$SHELL" == "/bin/bash" ];
then
if grep -q "SCRIPTDIR" $HOME/.bashrc;
then aviso "PATH ja configurado"
else
echo "SCRIPTDIR=$HOME/$SCRIPTDIR" >> $HOME/.bashrc
echo "PATH=\$PATH:\$SCRIPTDIR" >> $HOME/.bashrc
PATH=$PATH:$HOME/$SCRIPTDIR
fi
elif [ "$SHELL" == "/bin/zsh" ];
then
if grep -q "SCRIPTDIR" $HOME/.zshrc;
then aviso "PATH ja configurado"
else
echo "SCRIPTDIR=$HOME/$SCRIPTDIR" >> $HOME/.zshrc
echo "PATH=\$PATH:\$SCRIPTDIR" >> $HOME/.zshrc
PATH=$PATH:$HOME/$SCRIPTDIR
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment