install-init.in 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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/update-keys -g' to generate and deploy secure keys to"
  105. echo "all nodes declared in your environment.xml"
  106. echo "*** Security Alert ***"
  107. else
  108. __fileCheck=1
  109. echo "OK"
  110. fi
  111. }
  112. #---------------------------------------------------------------------
  113. # Main code
  114. #---------------------------------------------------------------------
  115. SECTION=${SECTION:-DEFAULT}
  116. confToUse="${INSTALL_DIR}${CONFIG_DIR}/${ENV_CONF_FILE}"
  117. if [ -d ${CONFIG_DIR} ]; then
  118. if [ -f ${CONFIG_DIR}/installed ] ; then
  119. exit 0
  120. fi
  121. if [ -e ${CONFIG_DIR}/${ENV_CONF_FILE} ]; then
  122. confToUse="${CONFIG_DIR}/${ENV_CONF_FILE}"
  123. fi
  124. fi
  125. # Reading and processing conf file
  126. cfg.parser ${confToUse}
  127. cfg.section.${SECTION}
  128. if [ ${DEBUG:-NO_DEBUG} != "NO_DEBUG" ]; then
  129. echo "\$runtime=$runtime"
  130. echo "\$path=$path"
  131. echo "\$configs=$configs"
  132. echo "\$configsbackup=$configsbackup"
  133. echo "\$user=$user"
  134. echo "\$lock=$lock"
  135. echo "\$pid=$pid"
  136. echo "\$log=$log"
  137. echo "\$environment=$environment"
  138. echo "\$interface=$interface"
  139. echo "\$sourcedir=$sourcedir"
  140. echo
  141. fi
  142. #Checking if user exists and if doesn't then creating one
  143. useradd_d=$(echo "[DEFAULTLINUX]" > /tmp/tmp_defaultuser.conf;useradd -D >> /tmp/tmp_defaultuser.conf)
  144. cfg.parser /tmp/tmp_defaultuser.conf
  145. cfg.section.DEFAULTLINUX
  146. if [ "$HOME" != "$home" ]; then
  147. echo "Linux Default home directory is different from HPCC default."
  148. echo "Will continue to work with Linux Default $HOME....."
  149. homePath=$HOME/$user
  150. fi
  151. initPath="$path/etc/init.d"
  152. homePath=$HOME/$user
  153. binPath="$path/bin"
  154. add_user $user $group $homePath || exit 1
  155. # If user already exists get the home directory
  156. homePath=$(cat /etc/passwd | grep -e "^${user}:" | cut -d':' -f6)
  157. homeBase=$(dirname $homePath)
  158. echo ""
  159. # installing files
  160. installConfs "environment.conf" $configs/ 1 || exit 1
  161. installConfs "environment.xml" $configs/ 1 || exit 1
  162. installConfs "genenvrules.conf" $configs/ 1 || exit 1
  163. installFile "$path${CONFIG_DIR}/version" "${CONFIG_DIR}/version" 1 || exit 1
  164. installFile "$initPath/dafilesrv" "/etc/init.d/dafilesrv" 1 || exit 1
  165. installFile "$binPath/dfuplus" "/usr/bin/dfuplus" 1 || exit 1
  166. installFile "$binPath/ecl" "/usr/bin/ecl" 1 || exit 1
  167. installFile "$binPath/eclcc" "/usr/bin/eclcc" 1 || exit 1
  168. installFile "$binPath/eclplus" "/usr/bin/eclplus" 1 || exit 1
  169. installFile "$binPath/wuget" "/usr/bin/wuget" 1 || exit 1
  170. installFile "$configs/$environment" "$sourcedir/$environment" 0 "$sourcedir"
  171. installFile "$path${CONFIG_DIR}/configmgr/configmgr.conf" \
  172. "${CONFIG_DIR}/configmgr/" 0 "${CONFIG_DIR}/configmgr" || exit 1
  173. installFile "$path${CONFIG_DIR}/configmgr/esp.xml" "${CONFIG_DIR}/configmgr/" 0 || exit 1
  174. installFile "$path${CONFIG_DIR}/config2mgr/esp.xml" \
  175. "${CONFIG_DIR}/config2mgr/" 0 "${CONFIG_DIR}/config2mgr" || exit 1
  176. # locate sub install files.
  177. if [ -d ${INSTALL_DIR}/etc/init.d/install ]; then
  178. for subInstall in $(ls ${INSTALL_DIR}/etc/init.d/install); do
  179. source ${INSTALL_DIR}/etc/init.d/install/${subInstall}
  180. done
  181. fi
  182. # bash completion
  183. if [ -d ${INSTALL_DIR}/etc/bash_completion.d ] && [ -d /etc/bash_completion.d ]; then
  184. for subInstall in $(ls ${INSTALL_DIR}/etc/bash_completion.d | grep -v dpkg-tmp); do
  185. installFile ${INSTALL_DIR}/etc/bash_completion.d/$subInstall /etc/bash_completion.d/$subInstall 1 || exit 1
  186. done
  187. fi
  188. # SSH config dir
  189. if [ ! -d ${homePath}/.ssh ]; then
  190. mkdir -p ${homePath}/.ssh
  191. fi
  192. totalFiles=$(ls -l ${homePath}/.ssh | head -n 1 | awk '{ print $2 }' )
  193. if [ -d $homePath/.ssh ] && [ "$totalFiles" -le 3 ]; then
  194. installFile "${path}/etc/sshkey/.ssh.md5" "${homePath}/.ssh.md5" 0 || exit 1
  195. fileCheck "${homePath}/.ssh.md5"
  196. if [ ${__fileCheck} -eq 0 ]; then
  197. installFile "${path}/etc/sshkey/.ssh/authorized_keys" "${homePath}/.ssh/authorized_keys" 0 || exit 1
  198. installFile "${path}/etc/sshkey/.ssh/id_rsa" "${homePath}/.ssh/id_rsa" 0 || exit 1
  199. installFile "${path}/etc/sshkey/.ssh/id_rsa.pub" "${homePath}/.ssh/id_rsa.pub" 0 || exit 1
  200. fi
  201. else
  202. printf "SSH keys are already installed for user %-15s ..." "$user"
  203. log_success_msg
  204. fi
  205. ## for now turn off certificate logic if we're switching to setupPKI and distributePKI
  206. #if [ ! -d ${homePath}/certificate ]; then
  207. # mkdir -p ${homePath}/certificate
  208. #fi
  209. #
  210. #if [ ! -e ${homePath}/certificate/key.pem ]; then
  211. # ssh-keygen -t rsa -N '' -f ${homePath}/certificate/key.pem \
  212. # 1>/dev/null 2>&1
  213. # openssl rsa -in ${homePath}/certificate/key.pem -pubout \
  214. # -out ${homePath}/certificate/public.key.pem
  215. # chmod 0644 ${homePath}/certificate/public.key.pem
  216. # rm -f ${homePath}/certificate/key.pem.pub
  217. # printf "RSA key installed for user %-28s ..." "$user"
  218. # log_success_msg
  219. #else
  220. # printf "RSA keys are already installed for user %-15s ..." "$user"
  221. # log_success_msg
  222. #fi
  223. #
  224. #if [ ! -e ${homePath}/certificate/certificate.pem ]; then
  225. # openssl req -new -key ${homePath}/certificate/key.pem -keyform PEM -x509 \
  226. # -days 365 -out ${homePath}/certificate/certificate.pem \
  227. # -batch 1>/dev/null 2>&1
  228. # printf "Self Signed Certificate installed for user %-12s ..." "$user"
  229. # log_success_msg
  230. #else
  231. # printf "Self Signed Certificate already installed for %-9s ..." "$user"
  232. # log_success_msg
  233. #fi
  234. # Added code to change environment.conf file user home directory location for key generation
  235. if [ "$homeBase" != "$home" ]; then
  236. sed -e "s;^[[:space:]]*home[[:space:]]*=.*$;home=$homeBase;" ${CONFIG_DIR}/${ENV_CONF_FILE} > temp.conf
  237. mv temp.conf ${CONFIG_DIR}/${ENV_CONF_FILE}
  238. fi
  239. # Setting up values for /etc/sudoers and /etc/security/limits.conf files
  240. ${path}/sbin/add_conf_settings.sh
  241. groupNum=`grep "^${user}:" /etc/passwd | cut -d ':' -f 4`
  242. group=`grep -w ${groupNum} /etc/group | cut -d ':' -f 1`
  243. #Assigning correct permission for /User/hpcc
  244. chmod 700 ${homePath}/.ssh
  245. [ -e ${homePath}/.ssh/id_rsa.pub ] && chmod 600 ${homePath}/.ssh/id_rsa.pub
  246. chown -R $user:$group ${homePath}
  247. $path/sbin/add_conf_settings.sh
  248. confPath=${path}${CONFIG_DIR}
  249. if [ -d ${confPath} ]; then
  250. for i in $(find $confPath)
  251. do
  252. if [ -d $confPath/$i ]; then
  253. if [ -d $configs/$i ]; then
  254. for infile in $(find $confPath/$i)
  255. do
  256. cp $confPath/$i/$infile $configs/$i/$infile
  257. done
  258. else
  259. mkdir $configs/$i
  260. for infile in $(find $confPath/$i)
  261. do
  262. cp "$confPath/$i/$infile" "$configs/$i/$infile"
  263. done
  264. fi
  265. fi
  266. done
  267. fi
  268. chown root:$group ${configs}
  269. chown -R $user:$group ${configs}/*
  270. chmod 775 ${configs}
  271. which_init_system=$(ps --no-headers -o comm 1)
  272. if [ "${which_init_system}" == "systemd" ]; then
  273. systemctl daemon-reload
  274. fi
  275. createRuntime
  276. [ -e ${LOG_DIR}/hpcc-init.debug ] && chown ${user}:${user} ${LOG_DIR}/hpcc-init.debug
  277. exit 0