install-init.in 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. mkdir -p ${configPath}
  25. mkdir -p ${configPath}/rpmnew
  26. printf "Installing %-44s ..." "${fileName}"
  27. if [ ! -e ${configPath}/${fileName} ]; then
  28. # Always install new files without comment
  29. cp -f ${INSTALL_DIR}/${configPath}/rpmnew/${fileName} ${configPath}/${fileName}
  30. cp -f ${INSTALL_DIR}/${configPath}/rpmnew/${fileName} ${configPath}/rpmnew/${fileName}
  31. log_success_msg
  32. elif [ -e ${configPath}/rpmnew/${fileName} ] && ! `diff -q ${configPath}/rpmnew/${fileName} ${INSTALL_DIR}/${configPath}/rpmnew/${fileName} >/dev/null` ; then
  33. # There are changes in the default config since last installed
  34. if ! `diff -q ${configPath}/rpmnew/${fileName} ${configPath}/${fileName} >/dev/null` ; then
  35. # User has made their own changes too, so don't overwrite
  36. log_failure_msg "Not overwriting modified configuration file ${fileName}"
  37. else
  38. # User has NOT made their own changes - ok to update
  39. cp -f ${INSTALL_DIR}/${configPath}/rpmnew/${fileName} ${configPath}/${fileName}
  40. cp -f ${INSTALL_DIR}/${configPath}/rpmnew/${fileName} ${configPath}/rpmnew/${fileName}
  41. log_success_msg "Updated configuration file ${fileName}"
  42. fi
  43. else
  44. log_success_msg "No changes to configuration file ${fileName}"
  45. fi
  46. }
  47. installFile ()
  48. {
  49. fileNameFrom=$1
  50. fileNameTo=$2
  51. symlink=$3
  52. createDir=$4
  53. option="-f"
  54. if [ ${symlink} != 0 ];then
  55. option="-sf"
  56. fi
  57. if [ ! -z "${createDir}" ]; then
  58. if [ ! -d ${createDir} ];then
  59. mkdir -p ${createDir}
  60. fi
  61. fi
  62. cp ${option} ${fileNameFrom} ${fileNameTo} 2> /dev/null
  63. printf "Installing %-44s ..." "${fileNameTo}"
  64. if [ -L ${fileNameTo} ]; then
  65. log_success_msg
  66. elif [ -e ${fileNameTo} ] && [ ! -L ${fileNameTo} ] ; then
  67. log_success_msg
  68. else
  69. log_failure_msg
  70. fi
  71. }
  72. fileCheck ()
  73. {
  74. inFile=$1
  75. echo -n "Checking SSH Key for user $user ..."
  76. if [ ! -e $inFile ]; then
  77. echo "Fail"
  78. echo "Bad File name"
  79. fi
  80. while read line
  81. do
  82. first=$( echo $line | awk '{ print $1 }' )
  83. second=$( echo $line | awk '{ print $2 }' )
  84. passValue=0
  85. if [ -f $first ] && [ -f $second ]; then
  86. newSum=$( md5sum $second )
  87. if [ ${newSum} -eq ${first} ]; then
  88. sc=0
  89. else
  90. sc=1
  91. fi
  92. else
  93. sc=0
  94. fi
  95. if [ "$sc" -gt 0 ]; then
  96. passValue=$(( ${passValue} + 1 ))
  97. fi
  98. done < ${inFile}
  99. if [ ${passValue} -lt 3 ]; then
  100. __fileCheck=0
  101. echo "Fail"
  102. echo "*** Security Alert ***"
  103. echo "You are using a publicly available default key."
  104. echo "Please run 'sudo ${path}/sbin/keygen.sh' to generate a new key to make your system secure."
  105. echo "*** Security Alert ***"
  106. else
  107. __fileCheck=1
  108. echo "OK"
  109. fi
  110. }
  111. #---------------------------------------------------------------------
  112. # Main code
  113. #---------------------------------------------------------------------
  114. SECTION=${SECTION:-DEFAULT}
  115. confToUse="${INSTALL_DIR}${CONFIG_DIR}/${ENV_CONF_FILE}"
  116. if [ -d ${CONFIG_DIR} ]; then
  117. if [ -f ${CONFIG_DIR}/installed ] ; then
  118. exit 0
  119. fi
  120. if [ -e ${CONFIG_DIR}/${ENV_CONF_FILE} ]; then
  121. confToUse="${CONFIG_DIR}/${ENV_CONF_FILE}"
  122. fi
  123. fi
  124. # Reading and processing conf file
  125. cfg.parser ${confToUse}
  126. cfg.section.${SECTION}
  127. if [ ${DEBUG:-NO_DEBUG} != "NO_DEBUG" ]; then
  128. echo "\$runtime=$runtime"
  129. echo "\$path=$path"
  130. echo "\$configs=$configs"
  131. echo "\$configsbackup=$configsbackup"
  132. echo "\$user=$user"
  133. echo "\$lock=$lock"
  134. echo "\$pid=$pid"
  135. echo "\$log=$log"
  136. echo "\$environment=$environment"
  137. echo "\$interface=$interface"
  138. echo "\$sourcedir=$sourcedir"
  139. echo
  140. fi
  141. #Checking if user exists and if doesn't then creating one
  142. useradd_d=$(echo "[DEFAULTLINUX]" > /tmp/tmp_defaultuser.conf;useradd -D >> /tmp/tmp_defaultuser.conf)
  143. cfg.parser /tmp/tmp_defaultuser.conf
  144. cfg.section.DEFAULTLINUX
  145. if [ "$HOME" != "$home" ]; then
  146. echo "Linux Default home directory is different from HPCC default."
  147. echo "Will continue to work with Linux Default $HOME....."
  148. homePath=$HOME/$user
  149. fi
  150. initPath="$path/etc/init.d"
  151. homePath=$HOME/$user
  152. binPath="$path/bin"
  153. add_user $user $group $homePath || exit 1
  154. # If user already exists get the home directory
  155. homePath=$(cat /etc/passwd | grep -e "^${user}:" | cut -d':' -f6)
  156. homeBase=$(dirname $homePath)
  157. echo ""
  158. # installing files
  159. installConfs "environment.conf" $configs/ 1 || exit 1
  160. installConfs "environment.xml" $configs/ 1 || exit 1
  161. installConfs "genenvrules.conf" $configs/ 1 || exit 1
  162. installFile "$path${CONFIG_DIR}/version" "${CONFIG_DIR}/version" 1 || exit 1
  163. installFile "$binPath/dfuplus" "/usr/bin/dfuplus" 1 || exit 1
  164. installFile "$binPath/ecl" "/usr/bin/ecl" 1 || exit 1
  165. installFile "$binPath/eclcc" "/usr/bin/eclcc" 1 || exit 1
  166. installFile "$binPath/eclplus" "/usr/bin/eclplus" 1 || exit 1
  167. installFile "$binPath/wuget" "/usr/bin/wuget" 1 || exit 1
  168. installFile "$configs/$environment" "$sourcedir/$environment" 0 "$sourcedir"
  169. # locate sub install files.
  170. if [ -d ${INSTALL_DIR}/etc/init.d/install ]; then
  171. for subInstall in $(ls ${INSTALL_DIR}/etc/init.d/install); do
  172. source ${INSTALL_DIR}/etc/init.d/install/${subInstall}
  173. done
  174. fi
  175. # bash completion
  176. if [ -d ${INSTALL_DIR}/etc/bash_completion.d ] && [ -d /etc/bash_completion.d ]; then
  177. for subInstall in $(ls ${INSTALL_DIR}/etc/bash_completion.d | grep -v dpkg-tmp); do
  178. installFile ${INSTALL_DIR}/etc/bash_completion.d/$subInstall /etc/bash_completion.d/$subInstall 1 || exit 1
  179. done
  180. fi
  181. # Ubuntu Unity Launcher
  182. if [ -f ${INSTALL_DIR}/share/hpcc-systems.desktop ] && [ -d /usr/share/applications ]; then
  183. installFile ${INSTALL_DIR}/share/hpcc-systems.desktop /usr/share/applications 1 || exit 1
  184. fi
  185. # SSH config dir
  186. if [ ! -d ${homePath}/.ssh ]; then
  187. mkdir -p ${homePath}/.ssh
  188. fi
  189. totalFiles=$(ls -l ${homePath}/.ssh | head -n 1 | awk '{ print $2 }' )
  190. if [ -d $homePath/.ssh ] && [ "$totalFiles" -le 3 ]; then
  191. installFile "${path}/etc/sshkey/.ssh.md5" "${homePath}/.ssh.md5" 0 || exit 1
  192. fileCheck "${homePath}/.ssh.md5"
  193. if [ ${__fileCheck} -eq 0 ]; then
  194. installFile "${path}/etc/sshkey/.ssh/authorized_keys" "${homePath}/.ssh/authorized_keys" 0 || exit 1
  195. installFile "${path}/etc/sshkey/.ssh/id_rsa" "${homePath}/.ssh/id_rsa" 0 || exit 1
  196. installFile "${path}/etc/sshkey/.ssh/id_rsa.pub" "${homePath}/.ssh/id_rsa.pub" 0 || exit 1
  197. fi
  198. else
  199. printf "SSH keys are already installed for user %-15s ..." "$user"
  200. log_success_msg
  201. fi
  202. # Added code to change environment.conf file user home directory location for key generation
  203. if [ "$homeBase" != "$home" ]; then
  204. sed -e "s;^[[:space:]]*home[[:space:]]*=.*$;home=$homeBase;" ${CONFIG_DIR}/${ENV_CONF_FILE} > temp.conf
  205. mv temp.conf ${CONFIG_DIR}/${ENV_CONF_FILE}
  206. fi
  207. # Setting up values for /etc/sudoers and /etc/security/limits.conf files
  208. ${path}/sbin/add_conf_settings.sh
  209. groupNum=`grep -w ${user} /etc/passwd | cut -d ':' -f 4`
  210. group=`grep -w ${groupNum} /etc/group | cut -d ':' -f 1`
  211. #Assigning correct permission for /User/hpcc
  212. chmod 700 ${homePath}/.ssh
  213. [ -e ${homePath}/.ssh/id_rsa.pub ] && chmod 600 ${homePath}/.ssh/id_rsa.pub
  214. chown -R $user:$group ${homePath}
  215. $path/sbin/add_conf_settings.sh
  216. confPath=${path}${CONFIG_DIR}
  217. if [ -d ${confPath} ]; then
  218. for i in $(find $confPath)
  219. do
  220. if [ -d $confPath/$i ]; then
  221. if [ -d $configs/$i ]; then
  222. for infile in $(find $confPath/$i)
  223. do
  224. cp $confPath/$i/$infile $configs/$i/$infile
  225. done
  226. else
  227. mkdir $configs/$i
  228. for infile in $(find $confPath/$i)
  229. do
  230. cp "$confPath/$i/$infile" "$configs/$i/$infile"
  231. done
  232. fi
  233. fi
  234. done
  235. fi
  236. chown root:$group ${configs}
  237. chown -R $user:$group ${configs}/*
  238. chmod 775 ${configs}
  239. # Add systemd support
  240. distrib_check
  241. if [ "${DISTRIB_NAME}" = "ubuntu" ] &&
  242. [ ${DISTRIB_MAJOR_VERSION} -ge 15 ]; then
  243. dpkg -l | grep -q -e "^ii[[:space:]]*systemd "
  244. if [ $? -eq 0 ]; then
  245. cp ${INSTALL_DIR}/etc/init.d/hpcc-init.service /lib/systemd/system/
  246. cp ${INSTALL_DIR}/etc/init.d/hpcc-init@.service /lib/systemd/system/
  247. cp ${INSTALL_DIR}/etc/init.d/dafilesrv.service /lib/systemd/system/
  248. cp ${INSTALL_DIR}/etc/init.d/dafilesrv@.service /lib/systemd/system/
  249. systemctl daemon-reload
  250. fi
  251. fi
  252. createRuntime
  253. [ -e ${LOG_DIR}/hpcc-init.debug ] && chown ${user}:${user} ${LOG_DIR}/hpcc-init.debug
  254. exit 0