max.sh 3.08 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash

PWD=`pwd`

display_usage(){
    echo ""
    echo " - MaX deployment tool - "
    echo "1 argument required"
    echo "   --help: shows help message"
    echo "   --init: init MaX environment"
    echo "   --install-demo: Creates a demonstration DB with its edition and deploies it as demo edition"
    echo "   --new-edition:  Generates a minimalist new edition configuration"
    echo ""
}

db_demo_feed(){
17
    db_project_feed max_demo_lorem $PWD/demo/demo_data/
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
}
#adds xml datas to a new db
db_project_feed(){
    if [ -z $BASEX_PATH ]
    then
	echo "Please set \$BASEX_PATH environment variable"
	exit 1
    else 
	echo "\$BASEX_PATH is defined ("$BASEX_PATH")"
	echo "Please type your BaseX login/password :"
	echo "CREATE DATABASE "$1 > feed.txt
	echo "ADD "$2 >> feed.txt
	$BASEX_PATH/bin/basexclient -w -cfeed.txt
	rm feed.txt
	echo "INFO: The "$1" DB was successfully created."
    fi
    
}

dje's avatar
dje committed
37
38
39
40
41
42
43
demo_edition_build(){
    if [ ! -d ../editions ]
    then
	echo 'Création répertoire "editions"'
	mkdir ../editions
    fi
    
chauveau's avatar
chauveau committed
44
45
46
47
    if [ -d ../editions/demo_lorem ]; then
	echo "Suppression de la demo existante"
	rm -rf ../editions/demo_lorem
    fi
48
    
49
    cp -r demo/demo_edition ../editions/demo_lorem
50
    cp demo/demo_lorem_config_inc.xml ../editions/demo_lorem
51
52
    echo "  -> resource files copy: DONE"
    node edition_manager.js -demo
dje's avatar
dje committed
53
54
55
56
57
58
59
    if [ $? -ne 0 ]
    then
	echo 'Process failed'
	exit 1
    else
	format_configuration_file
    fi
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
}

new_edition_build(){
    node edition_manager.js -new $1
    format_configuration_file
}

format_configuration_file(){
    FILE="../configuration/configuration.xml"
    mv $FILE $FILE".bak" || exit 1
    xmllint --format $FILE".bak" > $FILE
    rm $FILE".bak"
}

init_max(){
    cd ..
    bower install && gulp build
    #creates a .ignore file in nodejs dependencies folder
    touch $PWD"/../node_modules/.ignore"
}


# 1 argument required
if [  $# -lt 1 ]
then
    display_usage
    exit 1
fi    

# help required by user
if [[ ( $1 = "--help") ||  $1 = "-h" ]] 
then 
    display_usage
    exit 0
fi 

96

97
98
99
100
101
102
103
#creates config file if not exists (.dist copy)
if [ ! -f "../configuration/configuration.xml" ]
then
    echo "Configuration file does not exists: copying the .dist one"
    cp  ../configuration/configuration.dist.xml ../configuration/configuration.xml
fi

104
    
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
if [ $1 = "--new-edition" ]
then
    read -e -p "Identifiant du projet ?" project_id
    new_edition_build $project_id
    read -e -p "Dossier des sources XML à charger ?" data_path
    db_project_feed $project_id $data_path
    mkdir $PWD/../editions/$project_id
    mkdir $PWD/../editions/$project_id/ui
    mkdir $PWD/../editions/$project_id/ui/css
    mkdir $PWD/../editions/$project_id/ui/js
    mkdir $PWD/../editions/$project_id/ui/images
    touch $PWD/../editions/$project_id/ui/css/$project_id.css
    cp $PWD/menu_default.xml $PWD/../editions/$project_id/menu.xml
    exit 0
fi

if [ $1 = "--install-demo" ]
then
    db_demo_feed
    demo_edition_build
    exit 0
fi

if [ $1 = "--init" ]
then
    init_max
    exit 0
fi

#Invalid argument
echo ""
echo "ERROR: invalid argument"
display_usage
exit 1