Loading src/scripts/max.sh 0 → 100755 +175 −0 Original line number Diff line number Diff line #!/bin/bash RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color abort(){ echo -e "\n ${RED}Abort${NC} \n" exit 1 } display_usage(){ echo echo -e "\thelp: Affichage de l'aide." echo -e "\tversion: Affichage de la version de MaX." echo -e "\tdemo: Installation du corpus de démo." echo -e "\trun: Démarrage du serveur." echo -e "\tfeed: Ajout de sources XML" echo -e "\tfreeze: Statification du corpus" echo -e "\tclean: Suppression du corpus" echo } install(){ # install demo corpus .max/basex/bin/basex -Q".max/resources/bundles-installer.xq" } install_demo(){ if [ ! -d '.max/basex' ]; then echo 'Installation de MaX erronée.' else cp -r .max/fixtures/max .max/basex/data/ cp -r .max/fixtures/content_html . cp -r .max/fixtures/templates . cp -r .max/fixtures/autoroute . cp -r .max/fixtures/config.xml . cp -r .max/fixtures/locales . install echo 'Demo installée avec succès.' fi } check(){ # check config file according to rng if [ -f 'config.xml' ]; then\ .max/basex/bin/basex -q"validate:rng('config.xml', '.max/resources/max-configuration.rng')" || false echo 'MaX : Fichier config.xml valide.' else echo 'MaX : Fichier de configuration manquant : config.xml' abort fi } run() { # run server check .max/basex/bin/basexhttpstop || true .max/basex/bin/basexhttp -h1234 } clean() { # clean files read -r -e -p "Êtes-vous sûr? [o/N] ? " res if [ $res == 'o' ] || [ $res == 'O' ]; then rm -rf content_html;\ rm -rf templates;\ rm -rf autoroute;\ rm -rf locales;\ rm config.xml;\ if [ ! -f VERSION ]; then rm -rf .max; fi; else echo "Opération annulée" fi } feed(){ # add XML sources to 'max' db if [ -z $1 ]; then echo "USAGE : max.sh feed /path/to/dir/" abort elif [ ! -d $1 ]; then\ echo "Dossier "$1" introuvable !" echo "USAGE : max.sh feed path=/path/to/dir/" abort fi; .max/basex/bin/basex -c"OPEN max; ADD "$1 echo $1" ajouté à la base 'max'." } freeze(){ # freeze corpus as HTML pages run & if [ -d dist ]; then rm -rf dist fi sleep 5 echo -n "Statification..." wget -P dist -nH --mirror --page-requisites --html-extension --convert-links 'http://127.0.0.1:1234/fr/pages/index.html' echo -n "Version statique construite dans le répertoire dist/" } add(){ # Add bundle if [ -z $1 ]; then echo "USAGE : max.sh add bundle_url.git" abort elif [[ $1 == *.git ]] # * is used for pattern matching then basename=$(basename $1) filename=${basename%.*} if [ -d '.max/basex/webapp/max/bundles/'$filename ]; then echo 'Le bundle est déjà installé : .max/basex/webapp/max/bundles/'$filename abort else git clone $1 .max/basex/webapp/max/bundles/$filename if [ $? -eq 0 ]; then .max/basex/bin/basex -u -b bundleUrl="$1" ".max/resources/add-bundle.xq" else echo 'Clonage impossible de '$1 abort fi fi else echo "Seul les URLs de dépôt git sont acceptées" fi } DIRECTORY=$(cd "$(dirname "$0")" && pwd) #get max version if [[ ! -f ${DIRECTORY}/../VERSION ]] then MAX_VERSION=$(git rev-parse HEAD)'-dev' else MAX_VERSION=$(cat "${DIRECTORY}/VERSION") fi echo "---------------------------" echo " MaX V2 - $MAX_VERSION" echo "---------------------------" if [[ "$#" -eq 0 ]]; then display_usage; fi; while [[ "$#" -gt 0 ]]; do case $1 in help) display_usage exit 0;; version) echo $MAX_VERSION exit 0;; demo) install_demo exit 0;; run) run exit 0;; clean) clean exit 0;; freeze) freeze exit 0;; feed) feed $2 exit 0;; add) add $2 exit 0;; esac shift done # #set -- "${args[@]}" #while [[ "$#" -gt 0 ]]; do # case $1 in # #--disable-plugin) disable_plugin "$2" "$3";exit 0;; # *) echo "Unknown parameter passed: $1"; exit 1 ;; # esac # shift #done Loading
src/scripts/max.sh 0 → 100755 +175 −0 Original line number Diff line number Diff line #!/bin/bash RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color abort(){ echo -e "\n ${RED}Abort${NC} \n" exit 1 } display_usage(){ echo echo -e "\thelp: Affichage de l'aide." echo -e "\tversion: Affichage de la version de MaX." echo -e "\tdemo: Installation du corpus de démo." echo -e "\trun: Démarrage du serveur." echo -e "\tfeed: Ajout de sources XML" echo -e "\tfreeze: Statification du corpus" echo -e "\tclean: Suppression du corpus" echo } install(){ # install demo corpus .max/basex/bin/basex -Q".max/resources/bundles-installer.xq" } install_demo(){ if [ ! -d '.max/basex' ]; then echo 'Installation de MaX erronée.' else cp -r .max/fixtures/max .max/basex/data/ cp -r .max/fixtures/content_html . cp -r .max/fixtures/templates . cp -r .max/fixtures/autoroute . cp -r .max/fixtures/config.xml . cp -r .max/fixtures/locales . install echo 'Demo installée avec succès.' fi } check(){ # check config file according to rng if [ -f 'config.xml' ]; then\ .max/basex/bin/basex -q"validate:rng('config.xml', '.max/resources/max-configuration.rng')" || false echo 'MaX : Fichier config.xml valide.' else echo 'MaX : Fichier de configuration manquant : config.xml' abort fi } run() { # run server check .max/basex/bin/basexhttpstop || true .max/basex/bin/basexhttp -h1234 } clean() { # clean files read -r -e -p "Êtes-vous sûr? [o/N] ? " res if [ $res == 'o' ] || [ $res == 'O' ]; then rm -rf content_html;\ rm -rf templates;\ rm -rf autoroute;\ rm -rf locales;\ rm config.xml;\ if [ ! -f VERSION ]; then rm -rf .max; fi; else echo "Opération annulée" fi } feed(){ # add XML sources to 'max' db if [ -z $1 ]; then echo "USAGE : max.sh feed /path/to/dir/" abort elif [ ! -d $1 ]; then\ echo "Dossier "$1" introuvable !" echo "USAGE : max.sh feed path=/path/to/dir/" abort fi; .max/basex/bin/basex -c"OPEN max; ADD "$1 echo $1" ajouté à la base 'max'." } freeze(){ # freeze corpus as HTML pages run & if [ -d dist ]; then rm -rf dist fi sleep 5 echo -n "Statification..." wget -P dist -nH --mirror --page-requisites --html-extension --convert-links 'http://127.0.0.1:1234/fr/pages/index.html' echo -n "Version statique construite dans le répertoire dist/" } add(){ # Add bundle if [ -z $1 ]; then echo "USAGE : max.sh add bundle_url.git" abort elif [[ $1 == *.git ]] # * is used for pattern matching then basename=$(basename $1) filename=${basename%.*} if [ -d '.max/basex/webapp/max/bundles/'$filename ]; then echo 'Le bundle est déjà installé : .max/basex/webapp/max/bundles/'$filename abort else git clone $1 .max/basex/webapp/max/bundles/$filename if [ $? -eq 0 ]; then .max/basex/bin/basex -u -b bundleUrl="$1" ".max/resources/add-bundle.xq" else echo 'Clonage impossible de '$1 abort fi fi else echo "Seul les URLs de dépôt git sont acceptées" fi } DIRECTORY=$(cd "$(dirname "$0")" && pwd) #get max version if [[ ! -f ${DIRECTORY}/../VERSION ]] then MAX_VERSION=$(git rev-parse HEAD)'-dev' else MAX_VERSION=$(cat "${DIRECTORY}/VERSION") fi echo "---------------------------" echo " MaX V2 - $MAX_VERSION" echo "---------------------------" if [[ "$#" -eq 0 ]]; then display_usage; fi; while [[ "$#" -gt 0 ]]; do case $1 in help) display_usage exit 0;; version) echo $MAX_VERSION exit 0;; demo) install_demo exit 0;; run) run exit 0;; clean) clean exit 0;; freeze) freeze exit 0;; feed) feed $2 exit 0;; add) add $2 exit 0;; esac shift done # #set -- "${args[@]}" #while [[ "$#" -gt 0 ]]; do # case $1 in # #--disable-plugin) disable_plugin "$2" "$3";exit 0;; # *) echo "Unknown parameter passed: $1"; exit 1 ;; # esac # shift #done