1 |
mocchiut |
1.1 |
#!/bin/bash --norc |
2 |
|
|
THISDIR=`pwd` |
3 |
mocchiut |
1.2 |
USERNAME=${PAM_DBUSER} |
4 |
mocchiut |
1.1 |
HOST="" |
5 |
|
|
DBNAME="" |
6 |
mocchiut |
1.4 |
FORCE="no" |
7 |
mocchiut |
1.3 |
COUNT=0;for word in `echo ${PAM_DBHOST} | tr [\/] [" "] |tr [?] [" "] |sed 's/mysql://g' `; do if [ $COUNT -eq 0 ]; then HOST=`echo $word`; fi; if [ $COUNT -eq 1 ]; then DBNAME=`echo $word`; fi; let COUNT=$COUNT+1; done |
8 |
mocchiut |
1.2 |
PASSWORD=${PAM_DBPSW} |
9 |
|
|
if [ $# -gt 0 ]; then |
10 |
mocchiut |
1.4 |
for INPUT in $*; do |
11 |
mocchiut |
1.1 |
if [ $INPUT == "--help" ] || [ $INPUT == "-h" ]; then |
12 |
|
|
echo "" |
13 |
|
|
echo " Usage: ./install_GL_PARAM.sh [options] " |
14 |
|
|
echo "" |
15 |
|
|
echo " Options: " |
16 |
|
|
echo "" |
17 |
|
|
echo " --user=username : MySQL username. " |
18 |
|
|
echo "" |
19 |
|
|
echo " --host=mysql://localhost/pamelaprod : MySQL host and DB name." |
20 |
|
|
echo "" |
21 |
|
|
echo " --psw=password : MySQL password" |
22 |
|
|
echo "" |
23 |
mocchiut |
1.4 |
echo " --force : do not wait [default: wait]" |
24 |
|
|
echo "" |
25 |
mocchiut |
1.1 |
exit 0 |
26 |
|
|
fi |
27 |
|
|
TEST=`echo $INPUT | sed 's/--user=//g'` |
28 |
|
|
if [ $TEST != $INPUT ]; then |
29 |
|
|
USERNAME=`echo $TEST` |
30 |
|
|
export USERNAME; |
31 |
|
|
fi |
32 |
|
|
TEST=`echo $INPUT | sed 's/--host=//g'` |
33 |
|
|
if [ $TEST != $INPUT ]; then |
34 |
mocchiut |
1.3 |
COUNT=0;for word in `echo $TEST | tr [\/] [" "] |tr [?] [" "]|sed 's/mysql://g' `; do if [ $COUNT -eq 0 ]; then HOST=`echo $word`; fi; if [ $COUNT -eq 1 ]; then DBNAME=`echo $word`; fi; let COUNT=$COUNT+1; done |
35 |
mocchiut |
1.1 |
export DBNAME; |
36 |
|
|
export HOST; |
37 |
|
|
fi |
38 |
|
|
TEST=`echo $INPUT | sed 's/--psw=//g'` |
39 |
|
|
if [ $TEST != $INPUT ]; then |
40 |
|
|
PASSWORD=`echo $TEST` |
41 |
|
|
export PASSWORD; |
42 |
|
|
fi |
43 |
mocchiut |
1.4 |
if [ "$INPUT" == "--force" ]; then |
44 |
|
|
FORCE="yes"; |
45 |
|
|
export FORCE; |
46 |
|
|
fi |
47 |
mocchiut |
1.1 |
done |
48 |
|
|
else |
49 |
mocchiut |
1.2 |
if [ "$USERNAME" == "" ] || [ "$HOST" == "" ] || [ "$DBNAME" == "" ]; then |
50 |
|
|
echo "" |
51 |
|
|
echo " Usage: ./install_GL_PARAM.sh [options] " |
52 |
|
|
echo "" |
53 |
|
|
echo " Options: " |
54 |
|
|
echo "" |
55 |
|
|
echo " --user=username : MySQL username. " |
56 |
|
|
echo "" |
57 |
|
|
echo " --host=mysql://localhost/pamelaprod : MySQL host and DB name." |
58 |
|
|
echo "" |
59 |
|
|
echo " --psw=password : MySQL password" |
60 |
|
|
echo "" |
61 |
|
|
exit 0 |
62 |
|
|
fi |
63 |
mocchiut |
1.1 |
fi; |
64 |
mocchiut |
1.2 |
echo "" |
65 |
|
|
echo " Updating GL_PARAM table on DB $DBNAME, $HOST with user $USERNAME and password $PASSWORD " |
66 |
|
|
echo "" |
67 |
mocchiut |
1.4 |
if [ "$FORCE" == "no" ]; then |
68 |
|
|
echo " WARNING: if already existing the GL_PARAM table will be RECREATED and you will LOSE all data in that table! " |
69 |
|
|
echo "" |
70 |
|
|
echo " =======> You have 30 seconds to stop me using CTRL+c <======= " |
71 |
|
|
echo "" |
72 |
|
|
sleep 30; |
73 |
|
|
fi; |
74 |
mocchiut |
1.2 |
echo " Updating GL_PARAM table" |
75 |
mocchiut |
1.1 |
# |
76 |
|
|
rm -rf ${THISDIR}/temp.sql |
77 |
|
|
PAM_CALIB2=$(echo $PAM_CALIB | sed 's/\//\\\//g') |
78 |
|
|
# |
79 |
|
|
echo "delete from GL_PARAM;" > ${THISDIR}/temp.sql |
80 |
|
|
mysql --user=$USERNAME --password=$PASSWORD --host=$HOST $DBNAME < ${THISDIR}/temp.sql |
81 |
|
|
# |
82 |
|
|
cat ${THISDIR}/install_GL_PARAM.sql | sed 's/fullpathgoesere/'${PAM_CALIB2}'/g' >> ${THISDIR}/temp.sql |
83 |
|
|
mysql --user=$USERNAME --password=$PASSWORD --host=$HOST $DBNAME < ${THISDIR}/temp.sql |
84 |
|
|
# |
85 |
mocchiut |
1.2 |
echo " done! " |
86 |
mocchiut |
1.1 |
echo "" |
87 |
|
|
echo "GL_PARAM TABLE NOW CONTAINS:" |
88 |
|
|
echo "" |
89 |
mocchiut |
1.4 |
echo "SET time_zone='+0:00';" > ${THISDIR}/temp.sql |
90 |
|
|
echo "select * from GL_PARAM;" >> ${THISDIR}/temp.sql |
91 |
mocchiut |
1.1 |
mysql --user=$USERNAME --password=$PASSWORD --host=$HOST $DBNAME < ${THISDIR}/temp.sql |
92 |
|
|
echo "" |
93 |
|
|
echo "Please check that path and names are correct." |
94 |
|
|
echo "" |
95 |
|
|
# |
96 |
|
|
rm -rf ${THISDIR}/temp.sql |