max.sh 3.22 KB
Newer Older
1
2
3
#!/bin/bash

PWD=`pwd`
4
PORT=1984
5
6
7
8
9
10
11
12
13
14
15
16
17

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(){
18
    db_project_feed max_demo_lorem $PWD/demo/demo_data/
19
20
21
}
#adds xml datas to a new db
db_project_feed(){
22
23
24
    a=$(command -v basexclient)
    
    if [ -z $a ] && [ -z $BASEX_PATH ]
25
    then
26
	echo "Please install BaseX or set \$BASEX_PATH environment variable"
27
	exit 1
28
29
30
    else   
	if [ ! -z $a ]
	then
31
	    feed_cmd="basexclient -p$PORT -w -cfeed.txt"
32
	else
33
	    feed_cmd="$BASEX_PATH/bin/basexclient -p$PORT -w -cfeed.txt"
34
	fi
35
36
37
	echo "Please type your BaseX login/password :"
	echo "CREATE DATABASE "$1 > feed.txt
	echo "ADD "$2 >> feed.txt
38
	eval $feed_cmd
39
40
	rm feed.txt
	echo "INFO: The "$1" DB was successfully created."
41
42
	
    fi	
43
44
}

dje's avatar
dje committed
45
46
47
48
49
50
51
demo_edition_build(){
    if [ ! -d ../editions ]
    then
	echo 'Création répertoire "editions"'
	mkdir ../editions
    fi
    
chauveau's avatar
chauveau committed
52
53
54
55
    if [ -d ../editions/demo_lorem ]; then
	echo "Suppression de la demo existante"
	rm -rf ../editions/demo_lorem
    fi
56
    
57
    cp -r demo/demo_edition ../editions/demo_lorem
58
    cp demo/demo_lorem_config_inc.xml ../editions/demo_lorem
59
60
    echo "  -> resource files copy: DONE"
    node edition_manager.js -demo
dje's avatar
dje committed
61
62
63
64
65
66
67
    if [ $? -ne 0 ]
    then
	echo 'Process failed'
	exit 1
    else
	format_configuration_file
    fi
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
96
97
98
99
100
101
102
103
}

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 

104

105
106
107
108
109
110
111
#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

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
139
140
141
142
143
144
145
146
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