Last active
January 22, 2022 03:19
-
-
Save vitorbritto/6871149 to your computer and use it in GitHub Desktop.
Shell Script - Este é um script shell básico para clonar um repositório no GitHub e executar comandos de estruturação para um projeto com Bower e Grunt.
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
# Executar no shell/bash com: bash install.sh | |
# ------------------------------------------------------------------------------ | |
# | Helpers | | |
# ------------------------------------------------------------------------------ | |
# Renderiza um log de informação | |
e_informa() { | |
printf "\n$(tput setaf 7)%s$(tput sgr0)\n" "$@" | |
} | |
# Renderiza um log de successo | |
e_successo() { | |
printf "$(tput setaf 64)✔ %s$(tput sgr0)\n" "$@" | |
} | |
# Renderiza um log de erro | |
e_erro() { | |
printf "$(tput setaf 1)✖ %s$(tput sgr0)\n" "$@" | |
} | |
# Renderiza um log de aviso | |
e_aviso() { | |
printf "$(tput setaf 136)! %s$(tput sgr0)\n" "$@" | |
} | |
# Verifica se o comando existe | |
tipo_existe() { | |
if [ $(type -P $1) ]; then | |
return 0 | |
fi | |
return 1 | |
} | |
# Pergunta para o usuário o que deseja fazer | |
pergunta() { | |
printf "\n" | |
e_aviso "$@" | |
read -p "Deseja prosseguir com a instalação? (y/n) " -n 1 | |
printf "\n" | |
} | |
# Continua se o usuário confirmar | |
se_confirmar() { | |
if [[ "$REPLY" =~ ^[Yy]$ ]]; then | |
return 0 | |
fi | |
return 1 | |
} | |
# ------------------------------------------------------------------------------ | |
# | Verifica Status | | |
# ------------------------------------------------------------------------------ | |
# Variáveis | |
DESTINO="diretorio/do/seu/seu-projeto" # Defina o caminho do seu projeto aqui | |
TARBALL="https://github.com/usuario/repositorio/tarball/master" # Defina o caminho do seu tarball aqui | |
REPOSITORIO="https://github.com/usuario/repositorio" # Defina o caminho do seu repositório aqui | |
run_status() { | |
# If missing, download and extract the repositorio repository | |
if [[ ! -d ${DESTINO} ]]; then | |
printf "$(tput setaf 7)Iniciando o download do repositório...\033[m\n" | |
mkdir ${DESTINO} | |
# Faz o download com cURL | |
curl -fsSLo ${HOME}/repositorio.tar.gz ${TARBALL} | |
# Extraindo... | |
tar -zxf ${HOME}/repositorio.tar.gz --strip-components 1 -C ${DESTINO} | |
# Removendo o tarball | |
rm -rf ${HOME}/repositorio.tar.gz | |
fi | |
cd ${DESTINO} | |
# Verifica se o bower está instalado na máquina | |
if tipo_existe 'bower'; then | |
e_informa "Iniciando o script..." | |
[[ $? ]] && bower install | |
[[ $? ]] && e_successo "Feito!" | |
else | |
printf "\n" | |
e_erro "O bower não está instalado na sua máquina." | |
pergunta "Você deseja instalar o bower agora?" | |
if se_confirmar; then | |
npm bower install -g | |
else | |
printf "Finalizando...\n" | |
fi | |
fi | |
# Verifica se o grunt está instalado na máquina | |
if tipo_existe 'grunt'; then | |
e_informa "Iniciando o script..." | |
[[ $? ]] && npm install | |
[[ $? ]] && e_successo "Feito!" | |
[[ $? ]] && grunt | |
# Se não estiver, pergunta se deseja instalar | |
else | |
printf "\n" | |
e_erro "O grunt não está instalado na sua máquina." | |
pergunta "Você deseja instalar o grunt agora?" | |
# Se confirmar, instala! | |
if se_confirmar; then | |
npm grunt-cli install -g | |
# Senão, finaliza o script! | |
else | |
printf "Finalizando...\n" | |
fi | |
fi | |
} | |
run_status |
Show de bola, me ajudou bastante!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muito bom