-
Notifications
You must be signed in to change notification settings - Fork 2
/
sugar-modules.sh
executable file
·72 lines (66 loc) · 1.76 KB
/
sugar-modules.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
CONFIG='config.php'
DB_PASS='sugar'
DB_USER='sugar'
DB_NAME='sugar'
DB_PORT='3306'
DB_HOST='localhost'
function usage()
{
echo
echo "Use:"
echo "# $0 [options]"
echo " -u, --user Specify user of database."
echo " -p, --password Specify password of database."
echo " -B, --database Specify database name."
echo " -P, --port Specify port of database."
echo " -h, --host Specify host of database."
echo " -c, --config Load configuration from config.php"
echo " -?, --help"
echo
exit 1
}
while [ ! -z "$1" ]
do
case "$1" in
-u|--user)
DB_USER=$2
shift 2
;;
-p|--password)
DB_PASS=$2
shift 2
;;
-P|--port)
DB_PASS=$2
shift 2
;;
-B|--database)
DB_NAME=$2
shift 2
;;
-h|--host)
DB_HOST=$2
shift 2
;;
-c|--config)
SUGAR_CONFIG=true
DB_USER=$(cat $CONFIG | grep db_user_name | tr -d \ ,\'\> | awk -F= '{print $2}')
DB_PASS=$(cat $CONFIG | grep db_password | tr -d \ ,\'\> | awk -F= '{print $2}')
DB_NAME=$(cat $CONFIG | grep db_name | tr -d \ ,\'\> | awk -F= '{print $2}')
DB_HOST=$(cat $CONFIG | grep db_host_name | tr -d \ ,\'\> | awk -F= '{print $2}')
shift 1
;;
-?|--help)
usage
;;
esac
done
MYSQL="mysql -u"$DB_USER" -p"$DB_PASS" -B "$DB_NAME" -h "$DB_HOST
SQL="(select distinct lhs_module as module_name from relationships) union (select distinct rhs_module as module_name from relationships) order by module_name;"
MODULES=$(echo $SQL | $MYSQL | grep -v module_name)
for MODULE in $MODULES
do
MODULE=$(echo $MODULE | tr [A-Z] [a-z])
./sugar-graphviz.sh -u $DB_USER -p $DB_PASS -B $DB_NAME -h $DB_HOST -r -m $MODULE
done