install-init.in 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 "$initPath/dafilesrv" "/etc/init.d/dafilesrv" 1 || exit 1
  164. installFile "$binPath/dfuplus" "/usr/bin/dfuplus" 1 || exit 1
  165. installFile "$binPath/ecl" "/usr/bin/ecl" 1 || exit 1
  166. installFile "$binPath/eclcc" "/usr/bin/eclcc" 1 || exit 1
  167. installFile "$binPath/eclplus" "/usr/bin/eclplus" 1 || exit 1
  168. installFile "$binPath/wuget" "/usr/bin/wuget" 1 || exit 1
  169. installFile "$configs/$environment" "$sourcedir/$environment" 0 "$sourcedir"
  170. # locate sub install files.
  171. if [ -d ${INSTALL_DIR}/etc/init.d/install ]; then
  172. for subInstall in $(ls ${INSTALL_DIR}/etc/init.d/install); do
  173. source ${INSTALL_DIR}/etc/init.d/install/${subInstall}
  174. done
  175. fi
  176. # bash completion
  177. if [ -d ${INSTALL_DIR}/etc/bash_completion.d ] && [ -d /etc/bash_completion.d ]; then
  178. for subInstall in $(ls ${INSTALL_DIR}/etc/bash_completion.d | grep -v dpkg-tmp); do
  179. installFile ${INSTALL_DIR}/etc/bash_completion.d/$subInstall /etc/bash_completion.d/$subInstall 1 || exit 1
  180. done
  181. fi
  182. # Ubuntu Unity Launcher
  183. if [ -f ${INSTALL_DIR}/share/hpcc-systems.desktop ] && [ -d /usr/share/applications ]; then
  184. installFile ${INSTALL_DIR}/share/hpcc-systems.desktop /usr/share/applications 1 || exit 1
  185. fi
  186. # SSH config dir
  187. if [ ! -d ${homePath}/.ssh ]; then
  188. mkdir -p ${homePath}/.ssh
  189. fi
  190. totalFiles=$(ls -l ${homePath}/.ssh | head -n 1 | awk '{ print $2 }' )
  191. if [ -d $homePath/.ssh ] && [ "$totalFiles" -le 3 ]; then
  192. installFile "${path}/etc/sshkey/.ssh.md5" "${homePath}/.ssh.md5" 0 || exit 1
  193. fileCheck "${homePath}/.ssh.md5"
  194. if [ ${__fileCheck} -eq 0 ]; then
  195. installFile "${path}/etc/sshkey/.ssh/authorized_keys" "${homePath}/.ssh/authorized_keys" 0 || exit 1
  196. installFile "${path}/etc/sshkey/.ssh/id_rsa" "${homePath}/.ssh/id_rsa" 0 || exit 1
  197. installFile "${path}/etc/sshkey/.ssh/id_rsa.pub" "${homePath}/.ssh/id_rsa.pub" 0 || exit 1
  198. fi
  199. else
  200. printf "SSH keys are already installed for user %-15s ..." "$user"
  201. log_success_msg
  202. fi
  203. if [ ! -d ${homePath}/certificate ]; then
  204. mkdir -p ${homePath}/certificate
  205. fi
  206. if [ ! -e ${homePath}/certificate/certificate.pem ]; then
  207. openssl req -newkey rsa:2048 -keyout ${homePath}/certificate/key.pem -x509 \
  208. -days 365 -out ${homePath}/certificate/certificate.pem -passin \
  209. pass:hpccsystems-platform -passout pass:hpccsystems-platform -batch 1>/dev/null 2>&1
  210. printf "Self Signed Certificate installed for user %-12s ..." "$user"
  211. log_success_msg
  212. else
  213. printf "Self Signed Certificate already installed for user %-12s ..." "$user"
  214. log_success_msg
  215. fi
  216. # Added code to change environment.conf file user home directory location for key generation
  217. if [ "$homeBase" != "$home" ]; then
  218. sed -e "s;^[[:space:]]*home[[:space:]]*=.*$;home=$homeBase;" ${CONFIG_DIR}/${ENV_CONF_FILE} > temp.conf
  219. mv temp.conf ${CONFIG_DIR}/${ENV_CONF_FILE}
  220. fi
  221. # Setting up values for /etc/sudoers and /etc/security/limits.conf files
  222. ${path}/sbin/add_conf_settings.sh
  223. groupNum=`grep -w ${user} /etc/passwd | cut -d ':' -f 4`
  224. group=`grep -w ${groupNum} /etc/group | cut -d ':' -f 1`
  225. #Assigning correct permission for /User/hpcc
  226. chmod 700 ${homePath}/.ssh
  227. [ -e ${homePath}/.ssh/id_rsa.pub ] && chmod 600 ${homePath}/.ssh/id_rsa.pub
  228. chown -R $user:$group ${homePath}
  229. $path/sbin/add_conf_settings.sh
  230. confPath=${path}${CONFIG_DIR}
  231. if [ -d ${confPath} ]; then
  232. for i in $(find $confPath)
  233. do
  234. if [ -d $confPath/$i ]; then
  235. if [ -d $configs/$i ]; then
  236. for infile in $(find $confPath/$i)
  237. do
  238. cp $confPath/$i/$infile $configs/$i/$infile
  239. done
  240. else
  241. mkdir $configs/$i
  242. for infile in $(find $confPath/$i)
  243. do
  244. cp "$confPath/$i/$infile" "$configs/$i/$infile"
  245. done
  246. fi
  247. fi
  248. done
  249. fi
  250. chown root:$group ${configs}
  251. chown -R $user:$group ${configs}/*
  252. chmod 775 ${configs}
  253. # Add systemd support
  254. distrib_check
  255. if [ "${DISTRIB_NAME}" = "ubuntu" ] &&
  256. [ ${DISTRIB_MAJOR_VERSION} -ge 15 ]; then
  257. dpkg -S /sbin/init | grep -q systemd
  258. if [ $? -eq 0 ]; then
  259. cp ${INSTALL_DIR}/etc/init.d/hpcc-init.service /lib/systemd/system/
  260. cp ${INSTALL_DIR}/etc/init.d/hpcc-init@.service /lib/systemd/system/
  261. cp ${INSTALL_DIR}/etc/init.d/dafilesrv.service /lib/systemd/system/
  262. cp ${INSTALL_DIR}/etc/init.d/dafilesrv@.service /lib/systemd/system/
  263. systemctl daemon-reload
  264. fi
  265. fi
  266. createRuntime
  267. [ -e ${LOG_DIR}/hpcc-init.debug ] && chown ${user}:${user} ${LOG_DIR}/hpcc-init.debug
  268. exit 0