X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=sql%2Fbuilder.sh;h=db1dcd182e8e8483a362be13a2788a897f079086;hb=refs%2Fheads%2Ffdpass2-pull;hp=4e144b98ba430256eb2327d457fe2bf2db100041;hpb=f2074a7a29e3d8f60c605b7e4ab6de3a00234665;p=brisk.git diff --git a/sql/builder.sh b/sql/builder.sh index 4e144b9..db1dcd1 100755 --- a/sql/builder.sh +++ b/sql/builder.sh @@ -7,9 +7,10 @@ DATECUR="$(date +%s)" # functions usage () { + local _v echo " USAGE" - echo " ./builder [-d|--dryrun] [-a|-p|--allfiles|--devfiles] [-s|--short] ..." - echo " ./builder <-h|--help|help>" + echo " $0 [-c|--config ] [-d|--dryrun] [<-a|--allfiles>|<-p|--devfiles>] [-s|--short] ..." + echo " $0 [-c|--config ] <-h|--help|help>" echo " commands are:" echo " create" echo " destroy" @@ -29,6 +30,15 @@ usage () { echo " [$MATCH_DROP]" echo "NOTE: to invert normal 'del' rules add '--MF' (move forward) suffix to each line" echo " to invert normal 'add' rules add '--MB' (move backward) suffix to each line" + echo + echo "ENVIRONMENT" + for _v in \ +apache_conf card_hand players_n tables_n tables_appr_n tables_auth_n tables_cert_n \ +brisk_auth_conf brisk_debug web_path ftok_path proxy_path legal_path prefix_path \ +brisk_conf usock_path sys_user web_only test_add \ +DBHOST DBUSER DBPORT DBBASE DBPASS PFX ; do + echo " $_v=${!_v}" + done exit $1 } @@ -55,12 +65,12 @@ one_or_all() { if [ "$1" ]; then echo "$1" elif [ "$TYPE_FILES" = "a" ]; then - echo sql.d/[0-9]* + find sql.d/ -name '[0-9]*' -type f | sort -n | tr '\n' ' ' elif [ "$TYPE_FILES" = "d" ]; then - echo sql.d/[0-9]*.{sql,devel} + find sql.d/ -name '[0-9]*' | egrep '.*_devel.sql$|^[^_]+.sql$' | sort -n | tr '\n' ' ' else - echo sql.d/[0-9]*.sql - fi); do + find sql.d/ -name '[0-9]*' | egrep '^[^_]+.sql$' | sort -n | tr '\n' ' ' + fi); do echo "-- FILE BEG: $fil" cat "$fil" echo "-- FILE END: $fil" @@ -71,12 +81,17 @@ one_or_all() { # # MAIN # - -CMD=$1 -shift +if [ "${1:0:1}" != "-" ]; then + CMD=$1 + shift +fi while [ $# -gt 0 ]; do case $1 in + -c|--config) + CONFIG_FILE=$2 + shift + ;; -d|--dryrun) DRY_RUN=y psql () { @@ -93,6 +108,9 @@ while [ $# -gt 0 ]; do -s|--short) SHORT=y ;; + -h|--help|help) + CMD=help + ;; *) break ;; @@ -117,6 +135,10 @@ if [ -f $HOME/.brisk_install ]; then source $HOME/.brisk_install fi +if [ -f "$CONFIG_FILE" ]; then + source "$CONFIG_FILE" +fi + pg_args="" test "$DBHOST" != "" && pg_args="$pg_args -h $DBHOST" test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER"