v-update-sys-hestia-git 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. #!/bin/bash
  2. # v-update-sys-hestia-git
  3. # Downloads and compiles/installs packages from GitHub repositories
  4. # Options: REPOSITORY BRANCH INSTALL [PACKAGES]
  5. # Example: v-update-sys-hestia-git hestiacp staging/beta install all
  6. # - Will download from the hestiacp repository
  7. # - Pulls code from staging/beta branch
  8. # - install: installs package immediately
  9. # - install-auto: installs package and schedules automatic updates from Git
  10. # - 'all': (optional) - compiles nginx and php alongside panel.
  11. # this option takes a long time, only use when needed
  12. # Define download function
  13. download_file() {
  14. local url=$1
  15. local destination=$2
  16. local force=$3
  17. # Default destination is the curent working directory
  18. local dstopt=""
  19. if [ ! -z "$(echo "$url" | grep -E "\.(gz|gzip|bz2|zip|xz)$")" ]; then
  20. # When an archive file is downloaded it will be first saved localy
  21. dstopt="--directory-prefix=$ARCHIVE_DIR"
  22. local is_archive="true"
  23. local filename="${url##*/}"
  24. if [ -z "$filename" ]; then
  25. >&2 echo "[!] No filename was found in url, exiting ($url)"
  26. exit 1
  27. fi
  28. if [ ! -z "$force" ] && [ -f "$ARCHIVE_DIR/$filename" ]; then
  29. rm -f $ARCHIVE_DIR/$filename
  30. fi
  31. elif [ ! -z "$destination" ]; then
  32. # Plain files will be written to specified location
  33. dstopt="-O $destination"
  34. fi
  35. # check for corrupted archive
  36. if [ -f "$ARCHIVE_DIR/$filename" ] && [ "$is_archive" = "true" ]; then
  37. tar -tzf "$ARCHIVE_DIR/$filename" > /dev/null 2>&1
  38. if [ $? -ne 0 ]; then
  39. >&2 echo "[!] Archive $ARCHIVE_DIR/$filename is corrupted, redownloading"
  40. rm -f $ARCHIVE_DIR/$filename
  41. fi
  42. fi
  43. if [ ! -f "$ARCHIVE_DIR/$filename" ]; then
  44. wget $url -q $dstopt --show-progress --progress=bar:force --limit-rate=3m
  45. fi
  46. if [ ! -z "$destination" ] && [ "$is_archive" = "true" ]; then
  47. if [ "$destination" = "-" ]; then
  48. cat "$ARCHIVE_DIR/$filename"
  49. elif [ -d "$(dirname $destination)" ]; then
  50. cp "$ARCHIVE_DIR/$filename" "$destination"
  51. fi
  52. fi
  53. }
  54. # Set compiling directory
  55. BUILD_DIR='/tmp/hestiacp-src'
  56. DEB_DIR="$BUILD_DIR/debs"
  57. INSTALL_DIR='/usr/local/hestia'
  58. ARCHIVE_DIR="${BUILD_DIR}/archive"
  59. # Set command variables
  60. fork=$1
  61. branch=$2
  62. install=$3
  63. flags=$4
  64. # Set Version for compiling
  65. BUILD_VER=$(curl -s https://raw.githubusercontent.com/$fork/hestiacp/$branch/src/deb/hestia/control | grep "Version:" | cut -d' ' -f2)
  66. BUILD_ARCH='amd64'
  67. HESTIA_V="${BUILD_VER}_${BUILD_ARCH}"
  68. NGINX_V=$(curl -s https://raw.githubusercontent.com/$fork/hestiacp/$branch/src/deb/nginx/control |grep "Version:" |cut -d' ' -f2)
  69. OPENSSL_V='1.1.1g'
  70. PCRE_V='8.43'
  71. ZLIB_V='1.2.11'
  72. PHP_V=$(curl -s https://raw.githubusercontent.com/$fork/hestiacp/$branch/src/deb/php/control |grep "Version:" |cut -d' ' -f2)
  73. # Create build directories
  74. rm -rf $BUILD_DIR
  75. mkdir -p $DEB_DIR
  76. mkdir -p $ARCHIVE_DIR
  77. # Set package dependencies for compiling
  78. SOFTWARE='build-essential libxml2-dev libz-dev libcurl4-gnutls-dev unzip openssl libssl-dev pkg-config setpriv'
  79. # Define a timestamp function
  80. timestamp() {
  81. date +%s
  82. }
  83. # Set install flags
  84. if [ ! -z "$1" ]; then
  85. fork_check=$(curl -s --head -w %{http_code} https://raw.githubusercontent.com/$fork/hestiacp/release/src/deb/hestia/control -o /dev/null)
  86. if [ $fork_check -ne "200" ]; then
  87. echo "ERROR: invalid repository name specified."
  88. exit 1
  89. else
  90. echo "[!] Download code from GitHub repository: $fork"
  91. fork="$1"
  92. fi
  93. else
  94. fork="hestiacp"
  95. fi
  96. if [ ! -z "$2" ]; then
  97. branch_check=$(curl -s --head -w %{http_code} https://raw.githubusercontent.com/hestiacp/hestiacp/$branch/src/deb/hestia/control -o /dev/null)
  98. if [ $branch_check -ne "200" ]; then
  99. echo "ERROR: invalid branch name specified."
  100. exit 1
  101. else
  102. /usr/local/hestia/bin/v-change-sys-config-value 'RELEASE_BRANCH' "$branch"
  103. echo "[!] Changed system release branch to: $branch."
  104. fi
  105. else
  106. source /usr/local/hestia/conf/hestia.conf
  107. branch=$RELEASE_BRANCH
  108. fi
  109. if [ -z "$branch" ]; then
  110. echo "ERROR: No branch detected."
  111. exit
  112. fi
  113. # Install needed software
  114. echo "[*] Updating APT package cache..."
  115. apt-get -qq update > /dev/null 2>&1
  116. echo "[*] Checking for missing dependencies and installing required libraries..."
  117. apt-get -qq install -y $SOFTWARE > /dev/null 2>&1
  118. # Fix for Debian PHP Envroiment
  119. ln -s /usr/include/x86_64-linux-gnu/curl /usr/local/include/curl > /dev/null 2>&1
  120. # Get system cpu cores
  121. NUM_CPUS=$(grep "^cpu cores" /proc/cpuinfo | uniq | awk '{print $4}')
  122. # Check for existence of flags argument and set packages to build
  123. if [ ! -z "$flags" ]; then
  124. if [ "$flags" = "all" ]; then
  125. HESTIA_B='true'
  126. NGINX_B='true'
  127. PHP_B='true'
  128. fi
  129. else
  130. HESTIA_B='true'
  131. fi
  132. # Set git repository raw path
  133. GIT_REP='https://raw.githubusercontent.com/'$fork'/hestiacp/'$branch'/src/deb'
  134. # Generate Links for sourcecode
  135. HESTIA_ARCHIVE_LINK='https://github.com/'$fork'/hestiacp/archive/'$branch'.tar.gz'
  136. NGINX='https://nginx.org/download/nginx-'$NGINX_V'.tar.gz'
  137. OPENSSL='https://www.openssl.org/source/openssl-'$OPENSSL_V'.tar.gz'
  138. PCRE='https://ftp.pcre.org/pub/pcre/pcre-'$PCRE_V'.tar.gz'
  139. ZLIB='https://www.zlib.net/zlib-'$ZLIB_V'.tar.gz'
  140. PHP='http://de2.php.net/distributions/php-'$PHP_V'.tar.gz'
  141. # Forward slashes in branchname are replaced with dashes to match foldername in github archive.
  142. branch=$(echo "$branch" |sed 's/\//-/g');
  143. #################################################################################
  144. #
  145. # Building hestia-nginx
  146. #
  147. #################################################################################
  148. if [ "$NGINX_B" = true ] ; then
  149. echo "[*] Building Package: hestia-nginx (backend web server)..."
  150. # Change to build directory
  151. cd $BUILD_DIR
  152. # Check if target directory exist
  153. if [ -d $BUILD_DIR/hestia-nginx_$NGINX_V ]; then
  154. #mv $BUILD_DIR/hestia-nginx_$NGINX_V $BUILD_DIR/hestia-nginx_$NGINX_V-$(timestamp)
  155. rm -r $BUILD_DIR/hestia-nginx_$NGINX_V
  156. fi
  157. # Create directory
  158. mkdir $BUILD_DIR/hestia-nginx_$NGINX_V
  159. # Download and unpack source files
  160. download_file $NGINX | tar xz
  161. download_file $OPENSSL | tar xz
  162. download_file $PCRE | tar xz
  163. download_file $ZLIB | tar xz
  164. # Change to nginx directory
  165. cd nginx-$NGINX_V
  166. # configure nginx
  167. ./configure --prefix=/usr/local/hestia/nginx \
  168. --with-http_ssl_module \
  169. --with-openssl=../openssl-$OPENSSL_V \
  170. --with-openssl-opt=enable-ec_nistp_64_gcc_128 \
  171. --with-openssl-opt=no-nextprotoneg \
  172. --with-openssl-opt=no-weak-ssl-ciphers \
  173. --with-openssl-opt=no-ssl3 \
  174. --with-pcre=../pcre-$PCRE_V \
  175. --with-pcre-jit \
  176. --with-zlib=../zlib-$ZLIB_V
  177. # Check install directory and remove if exists
  178. if [ -d "$BUILD_DIR$INSTALL_DIR" ]; then
  179. rm -r "$BUILD_DIR$INSTALL_DIR"
  180. fi
  181. # Create the files and install them
  182. make -j $NUM_CPUS && make DESTDIR=$BUILD_DIR install
  183. # Cleare up unused files
  184. cd $BUILD_DIR
  185. rm -r nginx-$NGINX_V openssl-$OPENSSL_V pcre-$PCRE_V zlib-$ZLIB_V
  186. # Prepare Deb Package Folder Structure
  187. cd hestia-nginx_$NGINX_V/
  188. mkdir -p usr/local/hestia etc/init.d DEBIAN
  189. # Download control, postinst and postrm files
  190. cd DEBIAN
  191. download_file $GIT_REP/nginx/control
  192. download_file $GIT_REP/nginx/copyright
  193. download_file $GIT_REP/nginx/postinst
  194. download_file $GIT_REP/nginx/postrm
  195. # Set permission
  196. chmod +x postinst postrm
  197. # Move nginx directory
  198. cd ..
  199. mv $BUILD_DIR/usr/local/hestia/nginx usr/local/hestia/
  200. # Get Service File
  201. cd etc/init.d
  202. download_file $GIT_REP/nginx/hestia
  203. chmod +x hestia
  204. # Get nginx.conf
  205. cd ../../
  206. rm usr/local/hestia/nginx/conf/nginx.conf
  207. download_file $GIT_REP/nginx/nginx.conf -O usr/local/hestia/nginx/conf/nginx.conf
  208. # copy binary
  209. cp usr/local/hestia/nginx/sbin/nginx usr/local/hestia/nginx/sbin/hestia-nginx
  210. # change permission and build the package
  211. cd $BUILD_DIR
  212. chown -R root:root hestia-nginx_$NGINX_V
  213. dpkg-deb --build hestia-nginx_$NGINX_V
  214. mv *.deb $DEB_DIR
  215. # clear up the source folder
  216. rm -r hestia-nginx_$NGINX_V
  217. fi
  218. #################################################################################
  219. #
  220. # Building hestia-php
  221. #
  222. #################################################################################
  223. if [ "$PHP_B" = true ] ; then
  224. echo "[*] Building Package: hestia-php (backend engine)..."
  225. # Change to build directory
  226. cd $BUILD_DIR
  227. # Check if target directory exist
  228. if [ -d $BUILD_DIR/hestia-php_$PHP_V ]; then
  229. #mv $BUILD_DIR/hestia-php_$PHP_V $BUILD_DIR/hestia-php_$PHP_V-$(timestamp)
  230. rm -r $BUILD_DIR/hestia-php_$PHP_V
  231. fi
  232. # Create directory
  233. mkdir ${BUILD_DIR}/hestia-php_$PHP_V
  234. # Download and unpack source files
  235. download_file $PHP | tar xz
  236. # Change to php directory
  237. cd php-$PHP_V
  238. # Configure PHP
  239. ./configure --prefix=/usr/local/hestia/php \
  240. --enable-fpm \
  241. --with-fpm-user=admin \
  242. --with-fpm-group=admin \
  243. --with-libdir=lib/x86_64-linux-gnu \
  244. --with-mysqli \
  245. --with-curl \
  246. --enable-mbstring
  247. # Create the files and install them
  248. make -j $NUM_CPUS && make INSTALL_ROOT=$BUILD_DIR install
  249. # Cleare up unused files
  250. cd $BUILD_DIR
  251. rm -r php-$PHP_V
  252. # Prepare Deb Package Folder Structure
  253. cd hestia-php_$PHP_V/
  254. mkdir -p usr/local/hestia DEBIAN
  255. # Download control, postinst and postrm files
  256. cd DEBIAN
  257. download_file $GIT_REP/php/control
  258. download_file $GIT_REP/php/copyright
  259. # Move php directory
  260. cd ..
  261. mv ${BUILD_DIR}/usr/local/hestia/php usr/local/hestia/
  262. # Get php-fpm.conf
  263. download_file $GIT_REP/php/php-fpm.conf -O usr/local/hestia/php/etc/php-fpm.conf
  264. # Get php.ini
  265. download_file $GIT_REP/php/php.ini -O usr/local/hestia/php/lib/php.ini
  266. # copy binary
  267. cp usr/local/hestia/php/sbin/php-fpm usr/local/hestia/php/sbin/hestia-php
  268. # change permission and build the package
  269. cd $BUILD_DIR
  270. chown -R root:root hestia-php_$PHP_V
  271. dpkg-deb --build hestia-php_$PHP_V
  272. mv *.deb $DEB_DIR
  273. # clear up the source folder
  274. rm -r hestia-php_$PHP_V
  275. fi
  276. #################################################################################
  277. #
  278. # Building hestia
  279. #
  280. #################################################################################
  281. if [ "$HESTIA_B" = true ] ; then
  282. echo "[*] Building Package: hestia (Control Panel)..."
  283. # Change to build directory
  284. cd $BUILD_DIR
  285. # Check if target directory exist
  286. if [ -d $BUILD_DIR/hestia_$HESTIA_V ]; then
  287. #mv $BUILD_DIR/hestia_$HESTIA_V $BUILD_DIR/hestia_$HESTIA_V-$(timestamp)
  288. rm -r $BUILD_DIR/hestia_$HESTIA_V
  289. fi
  290. # Create directory
  291. mkdir $BUILD_DIR/hestia_$HESTIA_V
  292. # Download and unpack source files
  293. download_file $HESTIA_ARCHIVE_LINK '-' 'fresh' | tar xz
  294. # Prepare Deb Package Folder Structure
  295. cd hestia_$HESTIA_V/
  296. mkdir -p usr/local/hestia DEBIAN
  297. # Download control, postinst and postrm files
  298. cd DEBIAN
  299. download_file $GIT_REP/hestia/control
  300. download_file $GIT_REP/hestia/copyright
  301. download_file $GIT_REP/hestia/postinst
  302. # Set permission
  303. chmod +x postinst
  304. # Move needed directories
  305. cd $BUILD_DIR/hestiacp-$branch
  306. mv bin func install web ../hestia_$HESTIA_V/usr/local/hestia/
  307. # Set permission
  308. cd ../hestia_$HESTIA_V/usr/local/hestia/bin
  309. chmod +x *
  310. # change permission and build the package
  311. cd $BUILD_DIR
  312. chown -R root:root hestia_$HESTIA_V
  313. dpkg-deb --build hestia_$HESTIA_V
  314. mv *.deb $DEB_DIR
  315. # clear up the source folder
  316. rm -r hestia_$HESTIA_V
  317. rm -r hestiacp-$branch
  318. fi
  319. #################################################################################
  320. #
  321. # Install Packages
  322. #
  323. #################################################################################
  324. # Define package installation functions
  325. warning_message() {
  326. echo ""
  327. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  328. echo "WARNING - Development builds should not be installed on"
  329. echo "systems with live production data without understanding"
  330. echo "the potential risks that are involved!"
  331. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  332. echo ""
  333. }
  334. install_build() {
  335. echo "Installing packages..."
  336. for i in $DEB_DIR/*.deb; do
  337. # Install all available packages
  338. dpkg -i $i
  339. done
  340. # Remove temporary files
  341. rm -rf $BUILD_DIR
  342. }
  343. # Define installation routine
  344. if [ "$install" = "install" ] || [ "$install" = "yes" ] || [ "$install" = "install-auto" ]; then
  345. install_build
  346. if [ "$install" = "install-auto" ]; then
  347. $HESTIA/bin/v-add-cron-hestia-autoupdate git
  348. fi
  349. else
  350. warning_message
  351. read -p "Do you wish to proceed with the installation? [y/n] " answer
  352. if [ "$answer" = 'y' ] || [ "$answer" = 'Y' ]; then
  353. install_build
  354. unset $answer
  355. else
  356. echo "Installation of development build aborted."
  357. echo "Removing temporary files..."
  358. rm -rf $BUILD_DIR
  359. unset $answer
  360. echo ""
  361. fi
  362. fi