v-update-sys-hestia-git 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. #!/bin/bash
  2. # Autocompile Script for HestiaCP deb Files.
  3. # Define download function
  4. download_file() {
  5. local url=$1
  6. local destination=$2
  7. local force=$3
  8. # Default destination is the curent working directory
  9. local dstopt=""
  10. if [ ! -z "$(echo "$url" | grep -E "\.(gz|gzip|bz2|zip|xz)$")" ]; then
  11. # When an archive file is downloaded it will be first saved localy
  12. dstopt="--directory-prefix=$ARCHIVE_DIR"
  13. local is_archive="true"
  14. local filename="${url##*/}"
  15. if [ -z "$filename" ]; then
  16. >&2 echo "[!] No filename was found in url, exiting ($url)"
  17. exit 1
  18. fi
  19. if [ ! -z "$force" ] && [ -f "$ARCHIVE_DIR/$filename" ]; then
  20. rm -f $ARCHIVE_DIR/$filename
  21. fi
  22. elif [ ! -z "$destination" ]; then
  23. # Plain files will be written to specified location
  24. dstopt="-O $destination"
  25. fi
  26. # check for corrupted archive
  27. if [ -f "$ARCHIVE_DIR/$filename" ] && [ "$is_archive" = "true" ]; then
  28. tar -tzf "$ARCHIVE_DIR/$filename" > /dev/null 2>&1
  29. if [ $? -ne 0 ]; then
  30. >&2 echo "[!] Archive $ARCHIVE_DIR/$filename is corrupted, redownloading"
  31. rm -f $ARCHIVE_DIR/$filename
  32. fi
  33. fi
  34. if [ ! -f "$ARCHIVE_DIR/$filename" ]; then
  35. wget $url -q $dstopt --show-progress --progress=bar:force --limit-rate=3m
  36. fi
  37. if [ ! -z "$destination" ] && [ "$is_archive" = "true" ]; then
  38. if [ "$destination" = "-" ]; then
  39. cat "$ARCHIVE_DIR/$filename"
  40. elif [ -d "$(dirname $destination)" ]; then
  41. cp "$ARCHIVE_DIR/$filename" "$destination"
  42. fi
  43. fi
  44. }
  45. # Set compiling directory
  46. BUILD_DIR='/tmp/hestiacp-src/'
  47. DEB_DIR="$BUILD_DIR/debs/"
  48. INSTALL_DIR='/usr/local/hestia'
  49. # Set command variables
  50. branch=$1
  51. install=$2
  52. # Set Version for compiling
  53. BUILD_VER=$(curl -s https://raw.githubusercontent.com/hestiacp/hestiacp/$branch/src/deb/hestia/control | grep "Version:" | cut -d' ' -f2)
  54. BUILD_ARCH='amd64'
  55. HESTIA_V="${BUILD_VER}_${BUILD_ARCH}"
  56. NGINX_V='1.16.0'
  57. OPENSSL_V='1.1.1b'
  58. PCRE_V='8.43'
  59. ZLIB_V='1.2.11'
  60. PHP_V='7.3.4'
  61. # Create build directories
  62. rm -rf $BUILD_DIR
  63. mkdir -p $DEB_DIR
  64. # Set package dependencies for compiling
  65. SOFTWARE='build-essential libxml2-dev libz-dev libcurl4-gnutls-dev unzip openssl libssl-dev pkg-config'
  66. # Define a timestamp function
  67. timestamp() {
  68. date +%s
  69. }
  70. # Set install flags
  71. if [ ! -z "$1" ]; then
  72. branch_check=$(curl -s --head -w %{http_code} https://raw.githubusercontent.com/hestiacp/hestiacp/$branch/src/deb/hestia/control -o /dev/null)
  73. if [ $branch_check -ne "200" ]; then
  74. echo "Error: invalid branch name specified."
  75. exit 1
  76. else
  77. branch=$1
  78. fi
  79. else
  80. source /usr/local/hestia/conf/hestia.conf
  81. branch=$RELEASE_BRANCH
  82. fi
  83. if [ ! -z "$2" ]; then
  84. install=$2
  85. else
  86. install="y"
  87. fi
  88. if [ -z "$branch" ]; then
  89. echo "No branch detected, please provide one using: v-update-sys-hestia-git branch"
  90. exit
  91. fi
  92. # Install needed software
  93. echo "Updating system APT repositories..."
  94. apt-get -qq update > /dev/null 2>&1
  95. echo "Installing dependencies for compilation..."
  96. apt-get -qq install -y $SOFTWARE > /dev/null 2>&1
  97. # Fix for Debian PHP Envroiment
  98. if [ ! -e /usr/local/include/curl ]; then
  99. ln -s /usr/include/x86_64-linux-gnu/curl /usr/local/include/curl
  100. fi
  101. # Get system cpu cores
  102. NUM_CPUS=$(grep "^cpu cores" /proc/cpuinfo | uniq | awk '{print $4}')
  103. # Set packages to compile
  104. HESTIA_B='true'
  105. # Set git repository raw path
  106. GIT_REP='https://raw.githubusercontent.com/hestiacp/hestiacp/'$branch'/src/deb'
  107. # Generate Links for sourcecode
  108. HESTIA_ARCHIVE_LINK='https://github.com/hestiacp/hestiacp/archive/'$branch'.zip'
  109. NGINX='https://nginx.org/download/nginx-'$NGINX_V'.tar.gz'
  110. OPENSSL='https://www.openssl.org/source/openssl-'$OPENSSL_V'.tar.gz'
  111. PCRE='https://ftp.pcre.org/pub/pcre/pcre-'$PCRE_V'.tar.gz'
  112. ZLIB='https://www.zlib.net/zlib-'$ZLIB_V'.tar.gz'
  113. PHP='http://de2.php.net/distributions/php-'$PHP_V'.tar.gz'
  114. #################################################################################
  115. #
  116. # Building hestia-nginx
  117. #
  118. #################################################################################
  119. if [ "$NGINX_B" = true ] ; then
  120. echo "Building hestia-nginx package..."
  121. # Change to build directory
  122. cd $BUILD_DIR
  123. # Check if target directory exist
  124. if [ -d $BUILD_DIR/hestia-nginx_$NGINX_V ]; then
  125. #mv $BUILD_DIR/hestia-nginx_$NGINX_V $BUILD_DIR/hestia-nginx_$NGINX_V-$(timestamp)
  126. rm -r $BUILD_DIR/hestia-nginx_$NGINX_V
  127. fi
  128. # Create directory
  129. mkdir $BUILD_DIR/hestia-nginx_$NGINX_V
  130. # Download and unpack source files
  131. download_file $NGINX | tar xz
  132. download_file $OPENSSL | tar xz
  133. download_file $PCRE | tar xz
  134. download_file $ZLIB | tar xz
  135. # Change to nginx directory
  136. cd nginx-$NGINX_V
  137. # configure nginx
  138. ./configure --prefix=/usr/local/hestia/nginx \
  139. --with-http_ssl_module \
  140. --with-openssl=../openssl-$OPENSSL_V \
  141. --with-openssl-opt=enable-ec_nistp_64_gcc_128 \
  142. --with-openssl-opt=no-nextprotoneg \
  143. --with-openssl-opt=no-weak-ssl-ciphers \
  144. --with-openssl-opt=no-ssl3 \
  145. --with-pcre=../pcre-$PCRE_V \
  146. --with-pcre-jit \
  147. --with-zlib=../zlib-$ZLIB_V
  148. # Check install directory and remove if exists
  149. if [ -d "$BUILD_DIR$INSTALL_DIR" ]; then
  150. rm -r "$BUILD_DIR$INSTALL_DIR"
  151. fi
  152. # Create the files and install them
  153. make -j $NUM_CPUS && make DESTDIR=$BUILD_DIR install
  154. # Cleare up unused files
  155. cd $BUILD_DIR
  156. rm -r nginx-$NGINX_V openssl-$OPENSSL_V pcre-$PCRE_V zlib-$ZLIB_V
  157. # Prepare Deb Package Folder Structure
  158. cd hestia-nginx_$NGINX_V/
  159. mkdir -p usr/local/hestia etc/init.d DEBIAN
  160. # Download control, postinst and postrm files
  161. cd DEBIAN
  162. download_file $GIT_REP/nginx/control
  163. download_file $GIT_REP/nginx/copyright
  164. download_file $GIT_REP/nginx/postinst
  165. download_file $GIT_REP/nginx/postrm
  166. # Set permission
  167. chmod +x postinst postrm
  168. # Move nginx directory
  169. cd ..
  170. mv $BUILD_DIR/usr/local/hestia/nginx usr/local/hestia/
  171. # Get Service File
  172. cd etc/init.d
  173. download_file $GIT_REP/nginx/hestia
  174. chmod +x hestia
  175. # Get nginx.conf
  176. cd ../../
  177. rm usr/local/hestia/nginx/conf/nginx.conf
  178. download_file $GIT_REP/nginx/nginx.conf -O usr/local/hestia/nginx/conf/nginx.conf
  179. # copy binary
  180. cp usr/local/hestia/nginx/sbin/nginx usr/local/hestia/nginx/sbin/hestia-nginx
  181. # change permission and build the package
  182. cd $BUILD_DIR
  183. chown -R root:root hestia-nginx_$NGINX_V
  184. dpkg-deb --build hestia-nginx_$NGINX_V
  185. mv *.deb $DEB_DIR
  186. # clear up the source folder
  187. rm -r hestia-nginx_$NGINX_V
  188. fi
  189. #################################################################################
  190. #
  191. # Building hestia-php
  192. #
  193. #################################################################################
  194. if [ "$PHP_B" = true ] ; then
  195. echo "Building hestia-php package..."
  196. # Change to build directory
  197. cd $BUILD_DIR
  198. # Check if target directory exist
  199. if [ -d $BUILD_DIR/hestia-php_$PHP_V ]; then
  200. #mv $BUILD_DIR/hestia-php_$PHP_V $BUILD_DIR/hestia-php_$PHP_V-$(timestamp)
  201. rm -r $BUILD_DIR/hestia-php_$PHP_V
  202. fi
  203. # Create directory
  204. mkdir ${BUILD_DIR}/hestia-php_$PHP_V
  205. # Download and unpack source files
  206. download_file $PHP | tar xz
  207. # Change to php directory
  208. cd php-$PHP_V
  209. # Configure PHP
  210. ./configure --prefix=/usr/local/hestia/php \
  211. --enable-fpm \
  212. --with-fpm-user=admin \
  213. --with-fpm-group=admin \
  214. --with-libdir=lib/x86_64-linux-gnu \
  215. --with-mysqli \
  216. --with-curl \
  217. --enable-mbstring
  218. # Create the files and install them
  219. make -j $NUM_CPUS && make INSTALL_ROOT=$BUILD_DIR install
  220. # Cleare up unused files
  221. cd $BUILD_DIR
  222. rm -r php-$PHP_V
  223. # Prepare Deb Package Folder Structure
  224. cd hestia-php_$PHP_V/
  225. mkdir -p usr/local/hestia DEBIAN
  226. # Download control, postinst and postrm files
  227. cd DEBIAN
  228. download_file $GIT_REP/php/control
  229. download_file $GIT_REP/php/copyright
  230. # Move php directory
  231. cd ..
  232. mv ${BUILD_DIR}/usr/local/hestia/php usr/local/hestia/
  233. # Get php-fpm.conf
  234. download_file $GIT_REP/php/php-fpm.conf -O usr/local/hestia/php/etc/php-fpm.conf
  235. # Get php.ini
  236. download_file $GIT_REP/php/php.ini -O usr/local/hestia/php/lib/php.ini
  237. # copy binary
  238. cp usr/local/hestia/php/sbin/php-fpm usr/local/hestia/php/sbin/hestia-php
  239. # change permission and build the package
  240. cd $BUILD_DIR
  241. chown -R root:root hestia-php_$PHP_V
  242. dpkg-deb --build hestia-php_$PHP_V
  243. mv *.deb $DEB_DIR
  244. # clear up the source folder
  245. rm -r hestia-php_$PHP_V
  246. fi
  247. #################################################################################
  248. #
  249. # Building hestia
  250. #
  251. #################################################################################
  252. if [ "$HESTIA_B" = true ] ; then
  253. echo "Building Hestia Control Panel package..."
  254. # Change to build directory
  255. cd $BUILD_DIR
  256. # Check if target directory exist
  257. if [ -d $BUILD_DIR/hestia_$HESTIA_V ]; then
  258. #mv $BUILD_DIR/hestia_$HESTIA_V $BUILD_DIR/hestia_$HESTIA_V-$(timestamp)
  259. rm -r $BUILD_DIR/hestia_$HESTIA_V
  260. fi
  261. # Create directory
  262. mkdir $BUILD_DIR/hestia_$HESTIA_V
  263. # Download and unpack source files
  264. download_file $HESTIA_ARCHIVE_LINK
  265. unzip -q $branch.zip
  266. rm $branch.zip
  267. # Prepare Deb Package Folder Structure
  268. cd hestia_$HESTIA_V/
  269. mkdir -p usr/local/hestia DEBIAN
  270. # Download control, postinst and postrm files
  271. cd DEBIAN
  272. download_file $GIT_REP/hestia/control
  273. download_file $GIT_REP/hestia/copyright
  274. download_file $GIT_REP/hestia/postinst
  275. # Set permission
  276. chmod +x postinst
  277. # Move needed directories
  278. cd ../../hestiacp-$branch
  279. mv bin func install web ../hestia_$HESTIA_V/usr/local/hestia/
  280. # Set permission
  281. cd ../hestia_$HESTIA_V/usr/local/hestia/bin
  282. chmod +x *
  283. # change permission and build the package
  284. cd $BUILD_DIR
  285. chown -R root:root hestia_$HESTIA_V
  286. dpkg-deb --build hestia_$HESTIA_V
  287. mv *.deb $DEB_DIR
  288. # clear up the source folder
  289. rm -r hestia_$HESTIA_V
  290. rm -r hestiacp-$branch
  291. fi
  292. #################################################################################
  293. #
  294. # Install Packages
  295. #
  296. #################################################################################
  297. if [ "$install" = 'yes' ] || [ "$install" = 'y' ]; then
  298. echo "Installing packages..."
  299. for i in $DEB_DIR/*.deb; do
  300. # Install all available packages
  301. dpkg -i $i
  302. done
  303. unset $answer
  304. # Remove temporary files
  305. rm -rf $BUILD_DIR
  306. fi