install-init.in 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. # Generate environment.xml
  159. echo "Generate environment.xml"
  160. ${path}/sbin/envgen -env ${path}/etc/HPCCSystems/rpmnew/environment.xml -ip . -roxienodes 1 -thornodes 1 -slavesPerNode 1 -o data4=/var/lib/[NAME]/hpcc-data4/[COMPONENT] -set_xpath_attrib_value Software/EclCCServerProcess/Option @name maxCompileThreads -set_xpath_attrib_value Software/EclCCServerProcess/Option @value 2 -override roxie,@allFilesDynamic,true -override roxie,@laxyOpen,smart -override roxie,@localSlave,true -override roxie,@slaveConfig,simple > /dev/null 2>&1 || exit 1
  161. cp ${path}/etc/HPCCSystems/rpmnew/environment.xml ${path}/testing/regress/environment.xml || exit 1
  162. echo ""
  163. # installing files
  164. installConfs "environment.conf" $configs/ 1 || exit 1
  165. installConfs "environment.xml" $configs/ 1 || exit 1
  166. installConfs "genenvrules.conf" $configs/ 1 || exit 1
  167. installFile "$path${CONFIG_DIR}/version" "${CONFIG_DIR}/version" 1 || exit 1
  168. installFile "$initPath/dafilesrv" "/etc/init.d/dafilesrv" 1 || exit 1
  169. installFile "$binPath/dfuplus" "/usr/bin/dfuplus" 1 || exit 1
  170. installFile "$binPath/ecl" "/usr/bin/ecl" 1 || exit 1
  171. installFile "$binPath/eclcc" "/usr/bin/eclcc" 1 || exit 1
  172. installFile "$binPath/eclplus" "/usr/bin/eclplus" 1 || exit 1
  173. installFile "$binPath/wuget" "/usr/bin/wuget" 1 || exit 1
  174. installFile "$configs/$environment" "$sourcedir/$environment" 0 "$sourcedir"
  175. # locate sub install files.
  176. if [ -d ${INSTALL_DIR}/etc/init.d/install ]; then
  177. for subInstall in $(ls ${INSTALL_DIR}/etc/init.d/install); do
  178. source ${INSTALL_DIR}/etc/init.d/install/${subInstall}
  179. done
  180. fi
  181. # bash completion
  182. if [ -d ${INSTALL_DIR}/etc/bash_completion.d ] && [ -d /etc/bash_completion.d ]; then
  183. for subInstall in $(ls ${INSTALL_DIR}/etc/bash_completion.d | grep -v dpkg-tmp); do
  184. installFile ${INSTALL_DIR}/etc/bash_completion.d/$subInstall /etc/bash_completion.d/$subInstall 1 || exit 1
  185. done
  186. fi
  187. # Ubuntu Unity Launcher
  188. if [ -f ${INSTALL_DIR}/share/hpcc-systems.desktop ] && [ -d /usr/share/applications ]; then
  189. installFile ${INSTALL_DIR}/share/hpcc-systems.desktop /usr/share/applications 1 || exit 1
  190. fi
  191. # SSH config dir
  192. if [ ! -d ${homePath}/.ssh ]; then
  193. mkdir -p ${homePath}/.ssh
  194. fi
  195. totalFiles=$(ls -l ${homePath}/.ssh | head -n 1 | awk '{ print $2 }' )
  196. if [ -d $homePath/.ssh ] && [ "$totalFiles" -le 3 ]; then
  197. installFile "${path}/etc/sshkey/.ssh.md5" "${homePath}/.ssh.md5" 0 || exit 1
  198. fileCheck "${homePath}/.ssh.md5"
  199. if [ ${__fileCheck} -eq 0 ]; then
  200. installFile "${path}/etc/sshkey/.ssh/authorized_keys" "${homePath}/.ssh/authorized_keys" 0 || exit 1
  201. installFile "${path}/etc/sshkey/.ssh/id_rsa" "${homePath}/.ssh/id_rsa" 0 || exit 1
  202. installFile "${path}/etc/sshkey/.ssh/id_rsa.pub" "${homePath}/.ssh/id_rsa.pub" 0 || exit 1
  203. fi
  204. else
  205. printf "SSH keys are already installed for user %-15s ..." "$user"
  206. log_success_msg
  207. fi
  208. # Added code to change environment.conf file user home directory location for key generation
  209. if [ "$homeBase" != "$home" ]; then
  210. sed -e "s;^[[:space:]]*home[[:space:]]*=.*$;home=$homeBase;" ${CONFIG_DIR}/${ENV_CONF_FILE} > temp.conf
  211. mv temp.conf ${CONFIG_DIR}/${ENV_CONF_FILE}
  212. fi
  213. # Setting up values for /etc/sudoers and /etc/security/limits.conf files
  214. ${path}/sbin/add_conf_settings.sh
  215. groupNum=`grep -w ${user} /etc/passwd | cut -d ':' -f 4`
  216. group=`grep -w ${groupNum} /etc/group | cut -d ':' -f 1`
  217. #Assigning correct permission for /User/hpcc
  218. chmod 700 ${homePath}/.ssh
  219. [ -e ${homePath}/.ssh/id_rsa.pub ] && chmod 600 ${homePath}/.ssh/id_rsa.pub
  220. chown -R $user:$group ${homePath}
  221. $path/sbin/add_conf_settings.sh
  222. confPath=${path}${CONFIG_DIR}
  223. if [ -d ${confPath} ]; then
  224. for i in $(find $confPath)
  225. do
  226. if [ -d $confPath/$i ]; then
  227. if [ -d $configs/$i ]; then
  228. for infile in $(find $confPath/$i)
  229. do
  230. cp $confPath/$i/$infile $configs/$i/$infile
  231. done
  232. else
  233. mkdir $configs/$i
  234. for infile in $(find $confPath/$i)
  235. do
  236. cp "$confPath/$i/$infile" "$configs/$i/$infile"
  237. done
  238. fi
  239. fi
  240. done
  241. fi
  242. chown root:$group ${configs}
  243. chown -R $user:$group ${configs}/*
  244. chmod 775 ${configs}
  245. # Add systemd support
  246. distrib_check
  247. if [ "${DISTRIB_NAME}" = "ubuntu" ] &&
  248. [ ${DISTRIB_MAJOR_VERSION} -ge 15 ]; then
  249. dpkg -l | grep -q -e "^ii[[:space:]]*systemd "
  250. if [ $? -eq 0 ]; then
  251. cp ${INSTALL_DIR}/etc/init.d/hpcc-init.service /lib/systemd/system/
  252. cp ${INSTALL_DIR}/etc/init.d/hpcc-init@.service /lib/systemd/system/
  253. cp ${INSTALL_DIR}/etc/init.d/dafilesrv.service /lib/systemd/system/
  254. cp ${INSTALL_DIR}/etc/init.d/dafilesrv@.service /lib/systemd/system/
  255. systemctl daemon-reload
  256. fi
  257. fi
  258. createRuntime
  259. [ -e ${LOG_DIR}/hpcc-init.debug ] && chown ${user}:${user} ${LOG_DIR}/hpcc-init.debug
  260. exit 0