install-init.in 8.1 KB

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