Some fixes:
[jprojects-scripts.git] / dist.sh
1 #!/bin/bash
2
3 # Name of this project, detected by it's base path
4 NAME="${PWD##*/}"
5
6 # Generated JAR file
7 DIST="dist/${NAME}.jar"
8
9 # Configuration file
10 DIST_CONFIG_FILE="${HOME}/.jprojects-dist.sh"
11
12 # WildFly module base path
13 WILDFLY_MODULE_BASE_PATH="${HOME}/wildfly_domain/modules/org/mxchange"
14
15 # And for this "module" (as WildFly calls it)
16 WILDFLY_MODULE_PATH="${WILDFLY_MODULE_BASE_PATH}/${NAME}/main"
17
18 # module.xml
19 WILDFLY_MODULE_XML_FILE="wildfly/module.xml"
20
21 # Glassfish base path (domain)
22 GLASSFISH_BASE_PATH="${HOME}/gf_domain/lib"
23
24 # Windows personal domain
25 PERSONAL_DOMAIN_PATH="${HOME}/personal_domain/lib"
26
27 # Is the configuration file there?
28 if [ ! -f "${DIST_CONFIG_FILE}" ]
29 then
30         echo "$0: Configuration file '${DIST_CONFIG_FILE}' not found"
31         echo
32         echo "Following variables are needed:"
33         echo "- GLASSFISH_SSH_PATH"
34         echo "- GLASSFISH_SSH_USER"
35         echo "- GLASSFISH_SSH_SERVER"
36         echo
37         echo "And create a password-less SSH key."
38         exit 1
39 fi
40
41 # Load it
42 source "${DIST_CONFIG_FILE}"
43
44 # All set?
45 if [ -z "${GLASSFISH_SSH_PATH}" ]
46 then
47         echo "$0: Variable GLASSFISH_SSH_PATH not set."
48         exit 1
49 elif [ -z "${GLASSFISH_SSH_USER}" ]
50 then
51         echo "$0: Variable GLASSFISH_SSH_USER not set."
52         exit 1
53 elif [ -z "${GLASSFISH_SSH_SERVER}" ]
54 then
55         echo "$0: Variable GLASSFISH_SSH_SERVER not set."
56         exit 1
57 fi
58
59 # Generate list
60 LIST=$(find ../*/lib/${NAME}.jar)
61 LIST="${LIST} ${WILDFLY_MODULE_PATH}"
62
63 if [ -d "${GLASSFISH_BASE_PATH}" ]
64 then
65         echo "$0: Glassfish personal domain found, adding to LIST ..."
66         LIST="${LIST} ${GLASSFISH_BASE_PATH}"
67 fi
68
69 if [ -d "${PERSONAL_DOMAIN_PATH}" ]
70 then
71         echo "$0: Personal domain found, adding to LIST ..."
72         LIST="${LIST} ${PERSONAL_DOMAIN_PATH}"
73 fi
74
75 if [ ! -f "${DIST}" ]
76 then
77         echo "$0: '${DIST}' not found."
78         exit 1
79 elif [ ! -d "${WILDFLY_MODULE_BASE_PATH}" ]
80 then
81         echo "$0: WildFly base path '${WILDFLY_MODULE_BASE_PATH}' not created."
82 elif [ ! -d "${WILDFLY_MODULE_PATH}" ]
83 then
84         mkdir -vp "${WILDFLY_MODULE_PATH}"
85 fi
86
87 for project in ${LIST};
88 do
89         if [ -d "${project}" ]
90         then
91                 cp -v "${DIST}" "${project}"
92         elif [ -f "${project}" ]
93         then
94                 cp -v "${DIST}" "${project}"
95         else
96                 echo "$0: Project '${project}' not found."
97         fi
98
99 done
100
101 if [ "$1" != "r" -a "${NAME}" != "jcore" -a "${NAME}" != "jcore-swing" ]
102 then
103         echo "$0: Copying to remote '${GLASSFISH_SSH_SERVER}' ..."
104         scp "${DIST}" "${GLASSFISH_SSH_USER}@${GLASSFISH_SSH_SERVER}:${GLASSFISH_SSH_PATH}"
105 fi
106
107 # Copy module.xml ...
108 if [ -f "${WILDFLY_MODULE_XML_FILE}" ]
109 then
110         echo "$0: Generating module.xml ..."
111         XML_CONTENT=$(cat "${WILDFLY_MODULE_XML_FILE}")
112         XML_CONTENT="${XML_CONTENT//NAME/$NAME}"
113         echo "${XML_CONTENT}" > "${WILDFLY_MODULE_PATH}/module.xml"
114 fi
115
116 echo "$0: All done."
117 exit 0