...
 
Commits (1)
#!/bin/bash
# script for Yii2Module\Yii2CoursgratuitCom\CoursgratuitComModule
#
# This script needs the following arguments:
# @var $0 the path of this script
# @var $1 the mysql hostname
# @var $2 the mysql database name
# @var $3 the mysql user name
# @var $4 the mysql user password
# This script accepts the following non mandatory arguments:
# @var --mysqlhost={value} the mysql hostname (default: coursgratuit)
# @var --mysqldb={value} the mysql database name (default: coursgratuit)
# @var --mysqluser={value} the mysql user name (default: coursgratuit)
# @var --mysqlpass={value} the mysql user password (default: coursgratuit)
# @var --base-path={value} the base path for all repositories (default: /var/www)
# @var --ignore-app whether to ignore git application update (default: false)
# @var --ignore-php whether to ignore php update run (default: false)
# @var --ignore-csv whether to ignore git csv update (default: false)
# @var --ignore-asset whether to ignore git asset update (default: false)
#
set -eu
IFS=$'\n\t'
BASENAME=`dirname "$0"`
BASENAME=`realpath "$BASENAME"`
MYSQLHOST="$1"
MYSQLDBMS="$2"
MYSQLUSER="$3"
MYSQLPASS="$4"
R_APP_DIR="/var/www/yii2"
R_CSV_DIR="/var/www/yii2-coursgratuit-com-csv"
R_AST_DIR="/var/www/yii2-coursgratuit-com-assets"
MYSQLTERM="FIELDS ENCLOSED BY '\"' TERMINATED BY ';' ESCAPED BY '\\\\' LINES TERMINATED BY '\n'"
MYSQLHOST="localhost"
MYSQLDBMS="coursgratuit"
MYSQLUSER="coursgratuit"
MYSQLPASS="coursgratuit"
BASE_PATH="/var/www"
IGNORE_APP=0
IGNORE_PHP=0
IGNORE_CSV=0
IGNORE_AST=0
# argument management loop
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
for i in "[email protected]" do
case $i in
--mysqlhost=*)
MYSQLHOST="${i#*=}"
shift # past arg=val
;;
--mysqldb=*)
MYSQLDBMS="${i#*=}"
shift # past arg=val
;;
--mysqluser=*)
MYSQLUSER="${i#*=}"
shift # past arg=val
;;
--mysqlpass=*)
MYSQLPASS="${i#*=}"
shift # past arg=val
;;
--base-path=*)
BASE_PATH="${i#*=}"
shift # past arg=val
;;
--ignore-app)
IGNORE_APP=1
shift # past arg
;;
--ignore-php)
IGNORE_PHP=1
shift # past arg
;;
--ignore-csv)
IGNORE_CSV=1
shift # past arg
;;
--ignore-asset)
IGNORE_AST=1
shift # past arg
;;
*)
# unknown option
;;
esac
done
R_APP_DIR="$BASE_PATH/yii2"
R_CSV_DIR="$BASE_PATH/yii2-coursgratuit-com-csv"
R_AST_DIR="$BASE_PATH/yii2-coursgratuit-com-assets"
MYSQLTERM="FIELDS ENCLOSED BY '\"' TERMINATED BY ',' ESCAPED BY '\\\\' LINES TERMINATED BY '\n'"
CGC_CAT_FIELDS="coursgratuit_com_category_id, meta_created_at, meta_updated_at, coursgratuit_com_parent_category_id, path, name"
CGC_CRS_FIELDS="coursgratuit_com_cours_id, meta_created_at, meta_updated_at, coursgratuit_com_category_id, path, name, file_path, file_name, file_mime, file_md5, file_sha1, file_date_download, file_http_status"
......@@ -28,7 +84,7 @@ CGC_CRS_FIELDS="coursgratuit_com_cours_id, meta_created_at, meta_updated_at, cou
cd `dirname $0`
# update current code at current date
if [ -d ".git" ] ; then
if [ $IGNORE_APP = 0 ] && [ -d ".git" ] ; then
git pull --all
git add --all
git commit -m "Automatic update at `date +%Y-%m-%d`"
......@@ -36,12 +92,14 @@ if [ -d ".git" ] ; then
fi
# executes the update commands
php "$R_APP_DIR/yii" coursgratuit-com/update/categories
php "$R_APP_DIR/yii" coursgratuit-com/update/cours --onlyNewRecords
php "$R_APP_DIR/yii" coursgratuit-com/update/files --onlyNewRecords
if [ $IGNORE_PHP = 0]; then
php "$R_APP_DIR/yii" coursgratuit-com/update/categories
php "$R_APP_DIR/yii" coursgratuit-com/update/cours --onlyNewRecords
php "$R_APP_DIR/yii" coursgratuit-com/update/files --onlyNewRecords
fi
# go to data directory
if [ -d "$R_CSV_DIR" ] ; then
if [ $IGNORE_CSV = 0 ] && [ -d "$R_CSV_DIR" ] ; then
cd "$R_CSV_DIR"
if [ ! -d "$R_CSV_DIR/data" ] ; then
mkdir "$R_CSV_DIR/data"
......@@ -64,7 +122,7 @@ if [ -d "$R_CSV_DIR" ] ; then
fi
# go to asset directory
if [ -d "$R_AST_DIR" ] ; then
if [ $IGNORE_AST = 0 ] && [ -d "$R_AST_DIR" ] ; then
cd "$R_AST_DIR"
if [ -d ".git" ] ; then
# update to git with message at current date
......