Last active
August 29, 2015 14:08
-
-
Save firm1/948abecffb2f6ee1556b to your computer and use it in GitHub Desktop.
script
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 | |
#Set Script Name variable | |
SCRIPT=`basename ${BASH_SOURCE[0]}` | |
#Initialize variables to default values. | |
OPT_URL_REPO="https://github.com/zestedesavoir/zds-site.git" | |
OPT_BRANCH="dev" | |
#Set fonts for Help. | |
NORM=`tput sgr0` | |
BOLD=`tput bold` | |
REV=`tput smso` | |
#Help function | |
function HELP { | |
echo -e \\n"Documentation du script ${BOLD}${SCRIPT}.${NORM}"\\n | |
echo -e "${REV}Utilisation basique:${NORM} ${BOLD}$SCRIPT /opt/${NORM}"\\n | |
echo "Les options sont optionels. Les seules options reconnues sont les suivantes :" | |
echo "${REV}-u${NORM} --Modifie la valeur de l'option ${BOLD}url${NORM}. La valeur par defaut est: ${BOLD}https://github.com/zestedesavoir/zds-site.git${NORM}." | |
echo "${REV}-b${NORM} --Modifie la valeur de l'option ${BOLD}branch${NORM}. La valeur par defaut est: ${BOLD}dev${NORM}." | |
echo -e "${REV}-h${NORM} --Affiche le message d'aide. Aucune autre fonction n'est executee."\\n | |
echo -e "Exemple: ${BOLD}$SCRIPT -u https://github.com/zestedesavoir/zds-site.git -b dev /opt/${NORM}"\\n | |
exit 1 | |
} | |
#Check the number of arguments. If none are passed, print help and exit. | |
NUMARGS=$# | |
if [ $NUMARGS -eq 0 ]; then | |
HELP | |
fi | |
### Start getopts code ### | |
#Parse command line flags | |
#If an option should be followed by an argument, it should be followed by a ":". | |
#Notice there is no ":" after "h". The leading ":" suppresses error messages from | |
#getopts. This is required to get my unrecognized option code to work. | |
while getopts :u:b:h FLAG; do | |
case $FLAG in | |
u) #set option "url" | |
OPT_URL_REPO=$OPTARG | |
echo "Url du repo git : $OPT_URL_REPO" | |
;; | |
b) #set option "branch" | |
OPT_BRANCH=$OPTARG | |
echo "Branche : $OPT_BRANCH" | |
;; | |
h) #show help | |
HELP | |
;; | |
\?) #unrecognized option - show help | |
echo -e \\n"Option -${BOLD}$OPTARG${NORM} non permise." | |
HELP | |
#If you just want to display a simple error message instead of the full | |
#help, remove the 2 lines above and uncomment the 2 lines below. | |
#echo -e "Use ${BOLD}$SCRIPT -h${NORM} to see the help documentation."\\n | |
#exit 2 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) #This tells getopts to move on to the next argument. | |
### End getopts code ### | |
while [ $# -ne 0 ]; do | |
chemin=$1 | |
echo -e "Installation de ZDS dans le repertoire : $chemin sur $OSTYPE"\\n | |
sys_pkg="unzip wget git python-dev python-setuptools libxml2-dev python-lxml libxslt-dev libz-dev python-sqlparse libjpeg8 libjpeg8-dev libfreetype6 libfreetype6-dev" | |
### Verification du systeme cible ### | |
dist=`lsb_release -i` | |
tmp_pw=`pwd` | |
zds_dir="$chemin/zdsenv/$OPT_BRANCH" | |
echo "$dist" | |
if [[ $dist = *"CentOS"* ]]; then | |
cm_adm="sudo" | |
cmd_install="yum install" | |
elif [[ $dist = *"Debian"* ]]; then | |
cm_adm="sudo" | |
cmd_install="apt-get install -y" | |
elif [[ $dist = *"Ubuntu"* ]]; then | |
cm_adm="sudo" | |
cmd_install="apt-get install -y" | |
fi | |
echo "Installation des dépendances systèmes" | |
required_pkgs=`$cm_adm $cmd_install $sys_pkg` | |
required_pip=`easy_install pip` | |
required_venv=`pip install virtualenv` | |
echo "Création de l'environnement" | |
if [ ! -d "$chemin/zdsenv" ]; then | |
venv=`virtualenv $chemin/zdsenv --python=python2` | |
fi | |
if [ -d "$zds_dir" ]; then | |
sup=`rm -rf $zds_dir` | |
fi | |
clone=`git clone --depth 1 -b $OPT_BRANCH $OPT_URL_REPO $zds_dir` | |
echo "Installation des requirements (prennez un café, il y'en a pour quelques minutes)" | |
req=`source $chemin/zdsenv/bin/activate && cd $zds_dir && pip install --upgrade -r requirements.txt` | |
echo "Initialisation de la base de donnée : pensez à prendre du chocolat avec votre café " | |
bd_sync=`cd $zds_dir && python manage.py syncdb --noinput` | |
bd_sync=`cd $zds_dir && python manage.py migrate` | |
echo "Téléchargement du front" | |
front=`wget -P $zds_dir http://zestedesavoir.com/static/pack.zip` | |
dezip=`unzip $zds_dir/pack.zip -d $zds_dir/dist` | |
echo "Chargement des données de tests : Allez courir un peu, et revenez dans 5 min" | |
fixt=`cd $zds_dir && python manage.py load_fixtures size=low module=member,staff,category_forum,forum,tag,topic,post,article,tutorial,gallery,category_forum racine=user` | |
echo "Tout est ok. Vous êtes chaud ? lancez : python manage.py runserver" | |
tmp=`cd $zds_dir` | |
shift #Move on to next input file. | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment