install-init.in 8.0 KB

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