install-init.in 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #!/bin/bash
  2. ## Copyright © 2011 HPCC Systems. All rights reserved.
  3. ###<REPLACE>###
  4. source ${INSTALL_DIR}/etc/init.d/hpcc_common
  5. source ${INSTALL_DIR}/etc/init.d/init-functions
  6. installConfs ()
  7. {
  8. fileName=$1
  9. configPath=$2
  10. printf "Installing %-44s ..." "${fileName}"
  11. if [ ! -e ${configPath}/${fileName} ]; then
  12. if [ -e ${configPath}/rpmnew/${fileName} ]; then
  13. cp -f ${configPath}/rpmnew/${fileName} ${configPath}/${fileName}
  14. log_success_msg
  15. else
  16. if [ -e ${INSTALL_DIR}/${configPath}/rpmnew/${fileName} ]; then
  17. cp -f ${INSTALL_DIR}/${configPath}/rpmnew/${fileName} ${configPath}/${fileName}
  18. cp -f ${INSTALL_DIR}/${configPath}/rpmnew/${fileName} ${configPath}/rpmnew/${fileName}
  19. log_success_msg
  20. else
  21. log_failure_msg "Fail: File doesn't exist in rpmnew"
  22. fi
  23. fi
  24. else
  25. log_success_msg
  26. fi
  27. }
  28. installFile ()
  29. {
  30. fileNameFrom=$1
  31. fileNameTo=$2
  32. symlink=$3
  33. createDir=$4
  34. option="-f"
  35. if [ ${symlink} != 0 ];then
  36. option="-sf"
  37. fi
  38. if [ ! -z "${createDir}" ]; then
  39. if [ ! -d ${createDir} ];then
  40. mkdir -p ${createDir}
  41. fi
  42. fi
  43. cp ${option} ${fileNameFrom} ${fileNameTo} 2> /dev/null
  44. printf "Installing %-44s ..." "${fileNameTo}"
  45. if [ -L ${fileNameTo} ]; then
  46. log_success_msg
  47. elif [ -e ${fileNameTo} ] && [ ! -L ${fileNameTo} ] ; then
  48. log_success_msg
  49. else
  50. log_failure_msg
  51. fi
  52. }
  53. fileCheck ()
  54. {
  55. inFile=$1
  56. echo -n "Checking SSH Key for user $user ..."
  57. if [ ! -e $inFile ]; then
  58. echo "Fail"
  59. echo "Bad File name"
  60. fi
  61. while read line
  62. do
  63. first=$( echo $line | awk '{ print $1 }' )
  64. second=$( echo $line | awk '{ print $2 }' )
  65. passValue=0
  66. if [ -f $first ] && [ -f $second ]; then
  67. newSum=$( md5sum $second )
  68. if [ ${newSum} -eq ${first} ]; then
  69. sc=0
  70. else
  71. sc=1
  72. fi
  73. else
  74. sc=0
  75. fi
  76. if [ "$sc" -gt 0 ]; then
  77. passValue=$(( ${passValue} + 1 ))
  78. fi
  79. done < ${inFile}
  80. if [ ${passValue} -lt 3 ]; then
  81. __fileCheck=0
  82. echo "Fail"
  83. echo "*** Security Alert ***"
  84. echo "You are using a publicly available default key."
  85. echo "Please run ${path}/sbin/keygen.sh to generate a new key to make your system secure."
  86. echo "*** Security Alert ***"
  87. else
  88. __fileCheck=1
  89. echo "OK"
  90. fi
  91. }
  92. #---------------------------------------------------------------------
  93. # Main code
  94. #---------------------------------------------------------------------
  95. SECTION=${SECTION:-DEFAULT}
  96. confToUse="${INSTALL_DIR}${CONFIG_DIR}/${ENV_CONF_FILE}"
  97. if [ -d ${CONFIG_DIR} ]; then
  98. if [ -e ${CONFIG_DIR}/${ENV_CONF_FILE} ]; then
  99. confToUse="${CONFIG_DIR}/${ENV_CONF_FILE}"
  100. fi
  101. fi
  102. # Reading and processing conf file
  103. cfg.parser ${confToUse}
  104. cfg.section.${SECTION}
  105. if [ ${DEBUG:-NO_DEBUG} != "NO_DEBUG" ]; then
  106. echo "\$runtime=$runtime"
  107. echo "\$path=$path"
  108. echo "\$configs=$configs"
  109. echo "\$configsbackup=$configsbackup"
  110. echo "\$user=$user"
  111. echo "\$lock=$lock"
  112. echo "\$pid=$pid"
  113. echo "\$log=$log"
  114. echo "\$environment=$environment"
  115. echo "\$interface=$interface"
  116. echo "\$sourcedir=$sourcedir"
  117. echo
  118. fi
  119. #Checking if user exists and if doesn't then creating one
  120. useradd_d=$(echo "[DEFAULTLINUX]" > /tmp/tmp_defaultuser.conf;useradd -D >> /tmp/tmp_defaultuser.conf)
  121. cfg.parser /tmp/tmp_defaultuser.conf
  122. cfg.section.DEFAULTLINUX
  123. if [ "$HOME" != "$home" ]; then
  124. echo "Linux Default home directory is different from HPCC default."
  125. echo "Will continue to work with Linux Default $HOME....."
  126. homePath=$HOME/$user
  127. fi
  128. initPath="$path/etc/init.d"
  129. homePath=$HOME/$user
  130. binPath="$path/bin"
  131. add_user $user $group $homePath || exit 1
  132. echo ""
  133. # installing files
  134. installConfs "environment.conf" $configs/ 1 || exit 1
  135. installConfs "environment.xml" $configs/ 1 || exit 1
  136. installConfs "genenvrules.conf" $configs/ 1 || exit 1
  137. installFile "$path${CONFIG_DIR}/version" "${CONFIG_DIR}/version" 1 || exit 1
  138. installFile "$binPath/esp" "$binPath/configesp" 1 || exit 1
  139. installFile "$initPath/hpcc-init" "/etc/init.d/hpcc-init" 1 || exit 1
  140. installFile "$initPath/dafilesrv" "/etc/init.d/dafilesrv" 1 || exit 1
  141. installFile "$binPath/dfuplus" "/usr/bin/dfuplus" 1 || exit 1
  142. installFile "$binPath/eclcc" "/usr/bin/eclcc" 1 || exit 1
  143. installFile "$binPath/eclplus" "/usr/bin/eclplus" 1 || exit 1
  144. installFile "$binPath/soapplus" "/usr/bin/soapplus" 1 || exit 1
  145. installFile "$binPath/testsocket" "/usr/bin/testsocket" 1 || exit 1
  146. installFile "$binPath/wuget" "/usr/bin/wuget" 1 || exit 1
  147. installFile "$configs/$environment" "$sourcedir/$environment" 0 "$sourcedir"
  148. if [ ! -d ${homePath}/.ssh ]; then
  149. mkdir -p ${homePath}/.ssh
  150. fi
  151. totalFiles=$(ls -l ${homePath}/.ssh | head -n 1 | awk '{ print $2 }' )
  152. if [ -d $homePath/.ssh ] && [ "$totalFiles" -le 3 ]; then
  153. installFile "${path}/etc/sshkey/.ssh.md5" "${homePath}/.ssh.md5" 0 || exit 1
  154. fileCheck "${homePath}/.ssh.md5"
  155. if [ ${__fileCheck} -eq 0 ]; then
  156. installFile "${path}/etc/sshkey/.ssh/authorized_keys" "${homePath}/.ssh/authorized_keys" 0 || exit 1
  157. installFile "${path}/etc/sshkey/.ssh/id_rsa" "${homePath}/.ssh/id_rsa" 0 || exit 1
  158. installFile "${path}/etc/sshkey/.ssh/id_rsa.pub" "${homePath}/.ssh/id_rsa.pub" 0 || exit 1
  159. fi
  160. else
  161. printf "SSH keys are already installed for user %-15s ..." "$user"
  162. log_success_msg
  163. fi
  164. # Added code to change environment.conf file user home directory location for key generation
  165. if [ "$HOME" != "$home" ]; then
  166. sed -e "s;^\(.*\)\/home$;\1$HOME;" ${CONFIG_DIR}/${ENV_CONF_FILE} > temp.conf
  167. mv temp.conf ${CONFIG_DIR}/${ENV_CONF_FILE}
  168. fi
  169. # Setting up values for /etc/sudoers and /etc/security/limits.conf files
  170. ${path}/sbin/add_conf_settings.sh
  171. groupNum=`grep -w ${user} /etc/passwd | cut -d ':' -f 4`
  172. group=`grep -w ${groupNum} /etc/group | cut -d ':' -f 1`
  173. #Assigning correct permission for /User/hpcc
  174. chmod 700 ${homePath}/.ssh
  175. chown -R $user:$group ${homePath}
  176. $path/sbin/add_conf_settings.sh
  177. confPath=${path}${CONFIG_DIR}
  178. if [ -d ${confPath} ]; then
  179. for i in $(find $confPath)
  180. do
  181. if [ -d $confPath/$i ]; then
  182. if [ -d $configs/$i ]; then
  183. for infile in $(find $confPath/$i)
  184. do
  185. cp $confPath/$i/$infile $configs/$i/$infile
  186. done
  187. else
  188. mkdir $configs/$i
  189. for infile in $(find $confPath/$i)
  190. do
  191. cp "$confPath/$i/$infile" "$configs/$i/$infile"
  192. done
  193. fi
  194. fi
  195. done
  196. fi
  197. chown root:$group ${configs}
  198. chown -R $user:$group ${configs}/*
  199. chmod 775 ${configs}