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