_iPreUninstallUtility 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #!/bin/sh
  2. ###############################################################################
  3. # WebSphere Application Server liberty admininstrative pre-uninstall script for
  4. # IBM i
  5. #
  6. # Copyright IBM Corp. 2012, 2013
  7. # The source code for this program is not published or other-
  8. # wise divested of its trade secrets, irrespective of what has
  9. # been deposited with the U.S. Copyright Office.
  10. #
  11. # ----------------------------------------------------------------------------
  12. #
  13. # Run the _iPreUninstallUtility script before removing product files on IBM i.
  14. # However, this step is only for manual administrative "unzip"
  15. # installations. Do not use this command for manual developer installations.
  16. # The administrator must have *ALLOBJ and *SECADM special authority to run this
  17. # script.
  18. #
  19. #
  20. usage() {
  21. echo ""
  22. echo "Usage: _iPreUninstallUtility [options]"
  23. echo ""
  24. echo "Options:"
  25. echo " --action [ DLTPRDLOD | DLTPRDLIB | DLTSHRPRDLIB ]"
  26. echo " --appdatadir im_application_data_directory"
  27. echo ""
  28. echo "The --appdatadir option is required for the"
  29. echo "DLTPRDLOD action and is ignored by all other actions."
  30. exit 1
  31. }
  32. set_wlp_install_dir() {
  33. CUR_DIR=`pwd`
  34. WLP_DIR=`dirname ${0}`/../../../../
  35. cd "${WLP_DIR}"
  36. WLP_INSTALL_DIR=`pwd`
  37. cd "${CUR_DIR}"
  38. }
  39. ##
  40. ## evalJavaPropsFile: Reads Java properties from file specified in $1,
  41. ## and for every property it replaces all "." with "_" in the property name,
  42. ## sets the resulting named script variable to the property value and exports
  43. ## the variable.
  44. evalJavaPropsFile()
  45. {
  46. if [ -f "$1" ]; then
  47. while read -r line; do
  48. case $line in
  49. \#*);;
  50. *=*)
  51. # Only accept alphanumeric variable names to avoid eval complexities.
  52. if var=`echo "$line" | sed -e 's/^\([a-zA-Z0-9_\.][a-zA-Z0-9_\.]*\)=.*/\1/'`; then
  53. var=`echo $var | sed -e 's/\./_/g'`
  54. value=\'`echo "$line" | sed -e 's/[^=]*=//' -e s/\'/\'\"\'\"\'/g`\'
  55. eval "$var=$value; export $var"
  56. fi
  57. esac
  58. done < "$1"
  59. fi
  60. }
  61. delete_prod_lib() {
  62. echo "Executing delete_prod_lib"
  63. if [ -e ${WAS_PRODUCT_LIB_PATH} ]; then
  64. system "QSYS/DLTLIB LIB(${WAS_PRODUCT_LIB})"
  65. if [ $? -ne 0 ]; then
  66. ERR_CHK=1
  67. fi
  68. fi
  69. }
  70. delete_shared_prod_lib() {
  71. echo "Executing delete_shared_prod_lib"
  72. ALPHABET="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Z"
  73. PROD_LIB=${SHR_PROD_LIB}A
  74. DELETE_SHR_PRD_LIB=true
  75. for letter in $ALPHABET
  76. do
  77. if [ -e /QSYS.LIB/${PROD_LIB}.LIB ]; then
  78. DELETE_SHR_PRD_LIB=false
  79. echo "Library /QSYS.LIB/${PROD_LIB}.LIB exists, so the shared library will not be deleted"
  80. else
  81. echo "Library /QSYS.LIB/${PROD_LIB}.LIB does not exist"
  82. fi
  83. PROD_LIB=${SHR_PROD_LIB}${letter}
  84. done
  85. if [ "$DELETE_SHR_PRD_LIB" = "true" ]; then
  86. echo "Clearing output queue"
  87. system "QSYS/CLROUTQ OUTQ(QWAS9/QWASOUTQ)"
  88. if [ $? -ne 0 ]; then
  89. ERR_CHK=1
  90. fi
  91. echo "Removing TCP Service Table port entries"
  92. system "QSYS/CALL PGM(QWAS9/QWASCLN)"
  93. if [ $? -ne 0 ]; then
  94. ERR_CHK=1
  95. fi
  96. echo "Ending QWAS9 subsystem"
  97. system "QSYS/ENDSBS SBS(QWAS9) OPTION(*IMMED)"
  98. sleep 5
  99. echo "Since this is the last product, we can safely remove the Base Product Load QWAS00M"
  100. export QIBM_MULTI_THREADED=N
  101. system "CALL QSYS/QSZDLTPL PARM('$1 QWAS9 ' '')"
  102. if [ $? -ne 0 ]; then
  103. ERR_CHK=1
  104. fi
  105. system "QSYS/DLTLIB LIB(QWAS9)"
  106. if [ $? -ne 0 ]; then
  107. ERR_CHK=1
  108. fi
  109. else
  110. echo "Did not remove the shared product library (QWAS9) because other product installations are using the shared library"
  111. fi
  112. }
  113. delete_prod_load() {
  114. APP_DATA_LOC=$1
  115. echo "IM App Data location used: ${APP_DATA_LOC}"
  116. if [ "$PRODUCT_EDITION" = "EXPRESS" ]; then
  117. grep package.*com.ibm.websphere.liberty.EXPRESS.v90 ${APP_DATA_LOC}/installed.xml > tmp
  118. grep package.*com.ibm.websphere.liberty.EXPRESSTRIAL.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  119. grep package.*com.ibm.websphere.liberty.WEBENAB.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  120. grep package.*com.ibm.websphere.EXPRESS.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  121. grep package.*com.ibm.websphere.EXPRESSTRIAL.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  122. grep package.*com.ibm.websphere.WEBENAB.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  123. PROD_LOAD=QWAS01M
  124. echo "Product Load = $PROD_LOAD"
  125. fi
  126. if [ "$PRODUCT_EDITION" = "BASE" ]; then
  127. grep package.*com.ibm.websphere.liberty.BASE.v90 ${APP_DATA_LOC}/installed.xml > tmp
  128. grep package.*com.ibm.websphere.liberty.BASETRIAL.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  129. grep package.*com.ibm.websphere.BASE.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  130. grep package.*com.ibm.websphere.BASETRIAL.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  131. grep package.*com.ibm.websphere.DEVELOPERS.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  132. grep package.*com.ibm.websphere.DEVELOPERSILAN.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  133. PROD_LOAD=QWAS02M
  134. echo "Product Load = $PROD_LOAD"
  135. fi
  136. if [ "$PRODUCT_EDITION" = "DEVELOPERS" ]; then
  137. grep package.*com.ibm.websphere.liberty.DEVELOPERS.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  138. grep package.*com.ibm.websphere.liberty.DEVELOPERSILAN.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  139. PROD_LOAD=QWAS02M
  140. echo "Product Load = $PROD_LOAD"
  141. fi
  142. if [ "$PRODUCT_EDITION" = "ND" ]; then
  143. grep package.*com.ibm.websphere.liberty.ND.v90 ${APP_DATA_LOC}/installed.xml > tmp
  144. grep package.*com.ibm.websphere.liberty.NDTRIAL.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  145. grep package.*com.ibm.websphere.ND.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  146. grep package.*com.ibm.websphere.NDTRIAL.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  147. PROD_LOAD=QWAS03M
  148. echo "Product Load = $PROD_LOAD"
  149. fi
  150. if [ "$PRODUCT_EDITION" = "LIBERTY_CORE" ]; then
  151. grep package.*com.ibm.websphere.liberty.v90 ${APP_DATA_LOC}/installed.xml > tmp
  152. grep package.*com.ibm.websphere.liberty.TRIAL.v90 ${APP_DATA_LOC}/installed.xml >> tmp
  153. PROD_LOAD=QWAS05M
  154. echo "Product Load = $PROD_LOAD"
  155. fi
  156. count=0
  157. if [ -e tmp ]; then
  158. while read line
  159. do
  160. echo "$line"
  161. count=`expr $count + 1`
  162. done < tmp
  163. rm -f tmp
  164. echo "Total instances of package $PRODUCT_EDITION = $count"
  165. if [ -e /QSYS.LIB/QWAS9.LIB/${PROD_LOAD}.PRDLOD ]; then
  166. if [ $count -le 1 ]; then
  167. export QIBM_MULTI_THREADED=N
  168. system "CALL QSYS/QSZDLTPL PARM('${PROD_LOAD} QWAS9 ' '')"
  169. else
  170. echo "Not removing product load $PROD_LOAD because there are more than one instance of this offering"
  171. fi
  172. else
  173. echo "Product load $PROD_LOAD was not found"
  174. fi
  175. else
  176. echo "Could not find any instance of the offering $PRODUCT_EDITION, doing nothing"
  177. fi
  178. }
  179. do_default() {
  180. #
  181. echo "Executing $ACTION"
  182. delete_prod_lib
  183. delete_shared_prod_lib
  184. }
  185. if [ "`uname`" != "OS400" ]; then
  186. exit 1
  187. fi
  188. # Validate parameters
  189. # Do the whole 9 yards if no parameters are passed.
  190. ACTION=DODEFAULT
  191. ERR_CHK=0
  192. APPDATADIR=
  193. while [ $# -gt 0 ]; do
  194. case $1 in
  195. '--action') if [ $# -gt 1 ]; then
  196. ACTION=$2;shift
  197. fi
  198. ;;
  199. '--appdatadir') if [ $# -gt 1 ]; then
  200. APPDATADIR=$2;shift
  201. fi
  202. ;;
  203. *) usage
  204. ;;
  205. esac
  206. shift
  207. done
  208. echo "Action = $ACTION"
  209. if [ ${ACTION} = "DLTPRDLOD" ]; then
  210. if [ ! ${APPDATADIR} ]; then
  211. usage
  212. fi
  213. fi
  214. SHR_PROD_LIB=QWAS9
  215. set_wlp_install_dir
  216. echo "WebSphere liberty profile install root is ${WLP_INSTALL_DIR}"
  217. evalJavaPropsFile ${WLP_INSTALL_DIR}/lib/versions/WebSphereApplicationServer.properties
  218. echo "Product edition is "${com_ibm_websphere_productEdition}
  219. echo "Installation type is "${com_ibm_websphere_productInstallType}
  220. IS_IM_INSTALL=
  221. if [ ${com_ibm_websphere_productInstallType} = "InstallationManager" ]; then
  222. IS_IM_INSTALL=true
  223. else
  224. SCRIPT_DIR="${WLP_INSTALL_DIR}/bin"
  225. LSOUT=`ls -ld ${SCRIPT_DIR}`
  226. SCRIPT_DIR_OWNER=
  227. FCOUNT=0
  228. for LSTOKEN in $LSOUT
  229. do
  230. FCOUNT=`expr $FCOUNT + 1`
  231. if [ $FCOUNT = 3 ]; then
  232. SCRIPT_DIR_OWNER=$LSTOKEN
  233. break
  234. fi
  235. done
  236. echo Owner of ${SCRIPT_DIR} directory is ${SCRIPT_DIR_OWNER}
  237. if [ ! ${SCRIPT_DIR_OWNER} = "QSYS" ]; then
  238. echo "Nothing to do because the \"iAdmin POSTINSTALL\" command has not been run."
  239. exit 0
  240. fi
  241. fi
  242. if [ ! -e ${WLP_INSTALL_DIR}/etc/default.env ]; then
  243. echo "Error: ${WLP_INSTALL_DIR}/etc/default.env does not exist"
  244. exit 1
  245. fi
  246. . ${WLP_INSTALL_DIR}/etc/default.env
  247. PRODUCT_EDITION=${com_ibm_websphere_productEdition}
  248. case "$ACTION" in
  249. 'DODEFAULT') do_default
  250. ;;
  251. 'DLTPRDLOD') delete_prod_load ${APPDATADIR}
  252. ;;
  253. 'DLTPRDLIB') delete_prod_lib
  254. ;;
  255. 'DLTSHRPRDLIB') delete_shared_prod_lib
  256. ;;
  257. *)
  258. usage
  259. ;;
  260. esac
  261. exit ${ERR_CHK}