iAdmin 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #!/bin/sh
  2. ###############################################################################
  3. # Administrative utility for IBM i
  4. #
  5. # Copyright IBM Corp. 2012
  6. # The source code for this program is not published or other-
  7. # wise divested of its trade secrets, irrespective of what has
  8. # been deposited with the U.S. Copyright Office.
  9. #
  10. # ----------------------------------------------------------------------------
  11. #
  12. # The administrator must have *ALLOBJ and *SECADM special authority to run this
  13. # script.
  14. #
  15. usage() {
  16. echo ""
  17. echo "Usage: $0 "
  18. echo " {POSTINSTALL | PREUNINSTALL | "
  19. echo " GRANTAUTH --rolename server"
  20. echo " --userprofilename user_profile_name [options]"
  21. echo ""
  22. echo "Options for GRANTAUTH:"
  23. echo " --userdir wlp_usr_dir"
  24. echo " --outputdir wlp_output_dir"
  25. echo ""
  26. echo "The only currently supported value for --rolename is \"server\"."
  27. echo "You must specify \"server\" as the value for --rolename."
  28. echo ""
  29. echo "You must have *ALLOBJ and *SECADM special authority to use the"
  30. echo "POSTINSTALL and PREUNINSTALL commands."
  31. echo ""
  32. echo "You must have *ALLOBJ special permission, own or have *OBJMGT authority"
  33. echo "to all objects in the specified directory subtrees to use the GRANTAUTH"
  34. echo "command."
  35. exit 1
  36. }
  37. setWlpInstallDir() {
  38. CUR_DIR=`pwd`
  39. WLP_DIR=`dirname ${0}`/../../../../
  40. cd "${WLP_DIR}"
  41. WLP_INSTALL_DIR=`pwd`
  42. cd "${CUR_DIR}"
  43. }
  44. ##
  45. ## readServerEnv: Read server.env file and export environment variables.
  46. readServerEnv()
  47. {
  48. if [ -f "$1" ]; then
  49. while read -r line; do
  50. case $line in
  51. \#*);;
  52. *=*)
  53. # Only accept alphanumeric variable names to avoid eval complexities.
  54. if var=`echo "$line" | sed -e 's/^\([a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/'`; then
  55. value=\'`echo "$line" | sed -e 's/[^=]*=//' -e s/\'/\'\"\'\"\'/g`\'
  56. eval "$var=$value; export $var"
  57. fi
  58. esac
  59. done < "$1"
  60. fi
  61. }
  62. ##
  63. ## installEnvDefaults: Set variable defaults for a non-server or nonexistent
  64. ## server command.
  65. installEnvDefaults()
  66. {
  67. readServerEnv "${WLP_INSTALL_DIR}/etc/default.env"
  68. if [ -z "${WLP_USER_DIR}" ]
  69. then
  70. if [ -z "${WLP_DEFAULT_USER_DIR}" ]
  71. then
  72. WLP_DEFAULT_USER_DIR=${WLP_INSTALL_DIR}/usr
  73. fi
  74. WLP_USER_DIR=${WLP_DEFAULT_USER_DIR}
  75. fi
  76. if [ -z "${WLP_OUTPUT_DIR}" ]
  77. then
  78. if [ -z "${WLP_DEFAULT_OUTPUT_DIR}" ]
  79. then
  80. WLP_DEFAULT_OUTPUT_DIR=${WLP_USER_DIR}/servers
  81. fi
  82. WLP_OUTPUT_DIR=${WLP_DEFAULT_OUTPUT_DIR}
  83. fi
  84. }
  85. ##
  86. ## setLogsDir: Set LOGS_DIR
  87. setLogsDir()
  88. {
  89. readServerEnv "${WLP_INSTALL_DIR}/etc/server.env"
  90. installEnvDefaults
  91. LOGS_DIR=${WLP_OUTPUT_DIR}/.logs
  92. }
  93. if [ "`uname`" != "OS400" ]; then
  94. echo "The $0 command is supported only for IBM i."
  95. exit 1
  96. fi
  97. if [ ! $# -ge 1 ]; then
  98. usage
  99. fi
  100. WLPUSERDIR=
  101. WLPOUTPUTDIR=
  102. ROLENAME=
  103. USERPROFILENAME=
  104. ACTION=$1
  105. shift
  106. SAVED_OPTS=$@
  107. while [ $# -gt 0 ]; do
  108. case $1 in
  109. '--userdir') if [ $# -gt 1 ]; then
  110. WLPUSERDIR=$2;shift
  111. fi
  112. ;;
  113. '--outputdir') if [ $# -gt 1 ]; then
  114. WLPOUTPUTDIR=$2;shift
  115. fi
  116. ;;
  117. '--rolename') if [ $# -gt 1 ]; then
  118. ROLENAME=$2;shift
  119. if [ ${ROLENAME} != "server" ]; then
  120. usage
  121. fi
  122. fi
  123. ;;
  124. '--userprofilename') if [ $# -gt 1 ]; then
  125. USERPROFILENAME=$2;shift
  126. fi
  127. ;;
  128. *) usage
  129. ;;
  130. esac
  131. shift
  132. done
  133. ERR_CHK=0
  134. setWlpInstallDir
  135. if [ ${ACTION} = "POSTINSTALL" ]; then
  136. if [ -f ${WLP_INSTALL_DIR}/etc/default.env ]; then
  137. rm ${WLP_INSTALL_DIR}/etc/default.env
  138. if [ $? -ne 0 ]; then
  139. echo "Error: Cannot remove file ${WLP_INSTALL_DIR}/etc/default.env"
  140. exit 1
  141. fi
  142. fi
  143. else
  144. SCRIPT_DIR="${WLP_INSTALL_DIR}/bin"
  145. SCRIPT_DIR_OWNER=`ls -ld ${SCRIPT_DIR} | awk '{ print $3 }'`
  146. if [ ! ${SCRIPT_DIR_OWNER} = "QSYS" ]; then
  147. if [ ${ACTION} = "PREUNINSTALL" ]; then
  148. echo "Nothing to do because the \"iAdmin POSTINSTALL\" command has not been run."
  149. exit 0
  150. else
  151. if [ ${ACTION} = "GRANTAUTH" ]; then
  152. echo "Error: Nothing to do because the \"iAdmin POSTINSTALL\" command has not been run."
  153. exit 1
  154. fi
  155. fi
  156. fi
  157. if [ ${ACTION} = "GRANTAUTH" ]; then
  158. if [ ! ${ROLENAME} ] || [ ! ${USERPROFILENAME} ]; then
  159. usage
  160. fi
  161. fi
  162. fi
  163. _SCRIPT_LOCATION="${WLP_INSTALL_DIR}/lib/native/os400/bin"
  164. setLogsDir
  165. SAVED_UMASK=$(umask)
  166. umask 022
  167. if [ ! -d ${LOGS_DIR} ]; then
  168. mkdir -p ${LOGS_DIR}
  169. if [ $? != 0 ]; then
  170. echo "Error: Cannot create directory ${LOGS_DIR}."
  171. exit 1
  172. fi
  173. fi
  174. case "$ACTION" in
  175. 'POSTINSTALL')
  176. INSTALL_LOG=${LOGS_DIR}/$(basename $0)PostInstall.log
  177. if [ ! -f ${INSTALL_LOG} ]; then
  178. touch -C 819 ${INSTALL_LOG}
  179. fi
  180. umask ${SAVED_UMASK}
  181. echo "***************************************************************" >> ${INSTALL_LOG}
  182. echo `date` >> ${INSTALL_LOG}
  183. echo "Invoking ${_SCRIPT_LOCATION}/_iPostInstallUtility" >> ${INSTALL_LOG}
  184. echo "***************************************************************" >> ${INSTALL_LOG}
  185. ${_SCRIPT_LOCATION}/_iPostInstallUtility >> ${INSTALL_LOG} 2>&1
  186. ERR_CHK=$?
  187. if [ ${ERR_CHK} != 0 ]; then
  188. echo "The POSTINSTALL action completed with errors. See ${INSTALL_LOG} for details."
  189. else
  190. echo "The POSTINSTALL action completed successfully. See ${INSTALL_LOG} for details."
  191. fi
  192. ;;
  193. 'PREUNINSTALL')
  194. UNINSTALL_LOG=${LOGS_DIR}/$(basename $0)PreUninstall.log
  195. if [ ! -f ${UNINSTALL_LOG} ]; then
  196. touch -C 819 ${UNINSTALL_LOG}
  197. fi
  198. umask ${SAVED_UMASK}
  199. echo "***************************************************************" >> ${UNINSTALL_LOG}
  200. echo `date` >> ${UNINSTALL_LOG}
  201. echo "Invoking ${_SCRIPT_LOCATION}/_iPreUninstallUtility" >> ${UNINSTALL_LOG}
  202. echo "***************************************************************" >> ${UNINSTALL_LOG}
  203. ${_SCRIPT_LOCATION}/_iPreUninstallUtility >> ${UNINSTALL_LOG} 2>&1
  204. ERR_CHK=$?
  205. if [ ${ERR_CHK} != 0 ]; then
  206. echo "The PREUNINSTALL action completed with errors. See ${UNINSTALL_LOG} for details."
  207. else
  208. echo "The PREUNINSTALL action completed successfully. See ${UNINSTALL_LOG} for details."
  209. fi
  210. ;;
  211. 'GRANTAUTH')
  212. AUTH_LOG=${LOGS_DIR}/$(basename $0)GrantAuth.log
  213. if [ ! -f ${AUTH_LOG} ]; then
  214. touch -C 819 ${AUTH_LOG}
  215. fi
  216. umask ${SAVED_UMASK}
  217. echo "***************************************************************" >> ${AUTH_LOG}
  218. echo `date` >> ${AUTH_LOG}
  219. echo "Invoking ${_SCRIPT_LOCATION}/_iAuthUtility ${SAVED_OPTS}" >> ${AUTH_LOG}
  220. echo "***************************************************************" >> ${AUTH_LOG}
  221. ${_SCRIPT_LOCATION}/_iAuthUtility ${SAVED_OPTS} >> ${AUTH_LOG} 2>&1
  222. ERR_CHK=$?
  223. if [ ${ERR_CHK} != 0 ]; then
  224. echo "The GRANTAUTH action completed with errors. See ${AUTH_LOG} for details."
  225. else
  226. echo "The GRANTAUTH action completed successfully. See ${AUTH_LOG} for details."
  227. fi
  228. ;;
  229. *)
  230. usage
  231. ;;
  232. esac
  233. exit ${ERR_CHK}