hst_autocompile.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. #!/bin/bash
  2. # set -e
  3. # Autocompile Script for HestiaCP package Files.
  4. # For building from local source folder use "~localsrc" keyword as hesia branch name,
  5. # and the script will not try to download the arhive from github, since '~' char is
  6. # not accepted in branch name.
  7. # Compile but dont install -> ./hst_autocompile.sh --hestia --noinstall --keepbuild '~localsrc'
  8. # Compile and install -> ./hst_autocompile.sh --hestia --install '~localsrc'
  9. # Clear previous screen output
  10. clear
  11. # Define download function
  12. download_file() {
  13. local url=$1
  14. local destination=$2
  15. local force=$3
  16. [ "$HESTIA_DEBUG" ] && echo >&2 DEBUG: Downloading file "$url" to "$destination"
  17. # Default destination is the current 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. echo >&2 "[!] 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. echo >&2 "[!] 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. [ "$HESTIA_DEBUG" ] && echo >&2 DEBUG: wget $url -q $dstopt --show-progress --progress=bar:force --limit-rate=3m
  45. wget $url -q $dstopt --show-progress --progress=bar:force --limit-rate=3m
  46. if [ $? -ne 0 ]; then
  47. echo >&2 "[!] Archive $ARCHIVE_DIR/$filename is corrupted and exit script"
  48. rm -f $ARCHIVE_DIR/$filename
  49. exit 1
  50. fi
  51. fi
  52. if [ ! -z "$destination" ] && [ "$is_archive" = "true" ]; then
  53. if [ "$destination" = "-" ]; then
  54. cat "$ARCHIVE_DIR/$filename"
  55. elif [ -d "$(dirname $destination)" ]; then
  56. cp "$ARCHIVE_DIR/$filename" "$destination"
  57. fi
  58. fi
  59. }
  60. get_branch_file() {
  61. local filename=$1
  62. local destination=$2
  63. [ "$HESTIA_DEBUG" ] && echo >&2 DEBUG: Get branch file "$filename" to "$destination"
  64. if [ "$use_src_folder" == 'true' ]; then
  65. if [ -z "$destination" ]; then
  66. [ "$HESTIA_DEBUG" ] && echo >&2 DEBUG: cp -f "$SRC_DIR/$filename" ./
  67. cp -f "$SRC_DIR/$filename" ./
  68. else
  69. [ "$HESTIA_DEBUG" ] && echo >&2 DEBUG: cp -f "$SRC_DIR/$filename" "$destination"
  70. cp -f "$SRC_DIR/$filename" "$destination"
  71. fi
  72. else
  73. download_file "https://raw.githubusercontent.com/$REPO/$branch/$filename" "$destination" $3
  74. fi
  75. }
  76. usage() {
  77. echo "Usage:"
  78. echo " $0 (--all|--hestia|--nginx|--php) [options] [branch] [Y]"
  79. echo ""
  80. echo " --all Build all hestia packages."
  81. echo " --hestia Build only the Control Panel package."
  82. echo " --nginx Build only the backend nginx engine package."
  83. echo " --php Build only the backend php engine package"
  84. echo " Options:"
  85. echo " --install Install generated packages"
  86. echo " --keepbuild Don't delete downloaded source and build folders"
  87. echo " --cross Compile hestia package for both AMD64 and ARM64"
  88. echo " --debug Debug mode"
  89. echo ""
  90. echo "For automated builds and installations, you may specify the branch"
  91. echo "after one of the above flags. To install the packages, specify 'Y'"
  92. echo "following the branch name."
  93. echo ""
  94. echo "Example: bash hst_autocompile.sh --hestia develop Y"
  95. echo "This would install a Hestia Control Panel package compiled with the"
  96. echo "develop branch code."
  97. }
  98. # Set compiling directory
  99. REPO='hestiacp/hestiacp'
  100. BUILD_DIR='/tmp/hestiacp-src'
  101. INSTALL_DIR='/usr/local/hestia'
  102. SRC_DIR="$(cd "$(dirname "$0")/.." && pwd)"
  103. ARCHIVE_DIR="$SRC_DIR/src/archive/"
  104. architecture="$(arch)"
  105. if [ $architecture == 'aarch64' ]; then
  106. BUILD_ARCH='arm64'
  107. else
  108. BUILD_ARCH='amd64'
  109. fi
  110. RPM_DIR="$BUILD_DIR/rpm/"
  111. DEB_DIR="$BUILD_DIR/deb/"
  112. if [ -f '/etc/redhat-release' ]; then
  113. BUILD_RPM=true
  114. BUILD_DEB=false
  115. OSTYPE='rhel'
  116. else
  117. BUILD_RPM=false
  118. BUILD_DEB=true
  119. OSTYPE='debian'
  120. fi
  121. # Set packages to compile
  122. for i in $*; do
  123. case "$i" in
  124. --all)
  125. NGINX_B='true'
  126. PHP_B='true'
  127. HESTIA_B='true'
  128. ;;
  129. --nginx)
  130. NGINX_B='true'
  131. ;;
  132. --php)
  133. PHP_B='true'
  134. ;;
  135. --hestia)
  136. HESTIA_B='true'
  137. ;;
  138. --debug)
  139. HESTIA_DEBUG='true'
  140. ;;
  141. --install | Y)
  142. install='true'
  143. ;;
  144. --noinstall | N)
  145. install='false'
  146. ;;
  147. --keepbuild)
  148. KEEPBUILD='true'
  149. ;;
  150. --cross)
  151. CROSS='true'
  152. ;;
  153. --help | -h)
  154. usage
  155. exit 1
  156. ;;
  157. --dontinstalldeps)
  158. dontinstalldeps='true'
  159. ;;
  160. *)
  161. branch="$i"
  162. ;;
  163. esac
  164. done
  165. if [[ $# -eq 0 ]]; then
  166. usage
  167. exit 1
  168. fi
  169. # Clear previous screen output
  170. clear
  171. # Set command variables
  172. if [ -z $branch ]; then
  173. echo -n "Please enter the name of the branch to build from (e.g. main): "
  174. read branch
  175. fi
  176. if [ $(echo "$branch" | grep '^~localsrc') ]; then
  177. branch=$(echo "$branch" | sed 's/^~//')
  178. use_src_folder='true'
  179. else
  180. use_src_folder='false'
  181. fi
  182. if [ -z $install ]; then
  183. echo -n 'Would you like to install the compiled packages? [y/N] '
  184. read install
  185. fi
  186. # Set Version for compiling
  187. if [ -f "$SRC_DIR/src/deb/hestia/control" ] && [ "$use_src_folder" == 'true' ]; then
  188. BUILD_VER=$(cat $SRC_DIR/src/deb/hestia/control | grep "Version:" | cut -d' ' -f2)
  189. NGINX_V=$(cat $SRC_DIR/src/deb/nginx/control | grep "Version:" | cut -d' ' -f2)
  190. PHP_V=$(cat $SRC_DIR/src/deb/php/control | grep "Version:" | cut -d' ' -f2)
  191. else
  192. BUILD_VER=$(curl -s https://raw.githubusercontent.com/$REPO/$branch/src/deb/hestia/control | grep "Version:" | cut -d' ' -f2)
  193. NGINX_V=$(curl -s https://raw.githubusercontent.com/$REPO/$branch/src/deb/nginx/control | grep "Version:" | cut -d' ' -f2)
  194. PHP_V=$(curl -s https://raw.githubusercontent.com/$REPO/$branch/src/deb/php/control | grep "Version:" | cut -d' ' -f2)
  195. fi
  196. if [ -z "$BUILD_VER" ]; then
  197. echo "Error: Branch invalid, could not detect version"
  198. exit 1
  199. fi
  200. echo "Build version $BUILD_VER, with Nginx version $NGINX_V and PHP version $PHP_V"
  201. if [ -e "/etc/redhat-release" ]; then
  202. HESTIA_V="${BUILD_VER}"
  203. else
  204. HESTIA_V="${BUILD_VER}_${BUILD_ARCH}"
  205. fi
  206. OPENSSL_V='3.0.7'
  207. PCRE_V='10.40'
  208. ZLIB_V='1.2.13'
  209. # Create build directories
  210. if [ "$KEEPBUILD" != 'true' ]; then
  211. rm -rf $BUILD_DIR
  212. fi
  213. mkdir -p $BUILD_DIR
  214. mkdir -p $DEB_DIR
  215. mkdir -p $RPM_DIR
  216. mkdir -p $ARCHIVE_DIR
  217. # Define a timestamp function
  218. timestamp() {
  219. date +%s
  220. }
  221. if [ "$dontinstalldeps" != 'true' ]; then
  222. # Install needed software
  223. if [ "$OSTYPE" = 'rhel' ]; then
  224. # Set package dependencies for compiling
  225. SOFTWARE='gcc gcc-c++ make libxml2-devel zlib-devel libzip-devel gmp-devel libcurl-devel gnutls-devel unzip openssl openssl-devel pkg-config sqlite-devel oniguruma-devel rpm-build wget tar git curl perl-IPC-Cmd'
  226. echo "Updating system DNF repositories..."
  227. dnf install -y -q 'dnf-command(config-manager)'
  228. dnf install -y -q dnf-plugins-core
  229. dnf config-manager --set-enabled powertools > /dev/null 2>&1
  230. dnf config-manager --set-enabled PowerTools > /dev/null 2>&1
  231. dnf upgrade -y -q
  232. echo "Installing dependencies for compilation..."
  233. dnf install -y -q $SOFTWARE
  234. else
  235. # Set package dependencies for compiling
  236. SOFTWARE='build-essential libxml2-dev libz-dev libzip-dev libgmp-dev libcurl4-gnutls-dev unzip openssl libssl-dev pkg-config libsqlite3-dev libonig-dev rpm'
  237. echo "Updating system APT repositories..."
  238. apt-get -qq update > /dev/null 2>&1
  239. echo "Installing dependencies for compilation..."
  240. apt-get -qq install -y $SOFTWARE > /dev/null 2>&1
  241. # Fix for Debian PHP Envroiment
  242. if [ $BUILD_ARCH == "amd64" ]; then
  243. if [ ! -L /usr/local/include/curl ]; then
  244. ln -s /usr/include/x86_64-linux-gnu/curl /usr/local/include/curl
  245. fi
  246. fi
  247. fi
  248. fi
  249. # Get system cpu cores
  250. NUM_CPUS=$(grep "^cpu cores" /proc/cpuinfo | uniq | awk '{print $4}')
  251. if [ "$HESTIA_DEBUG" ]; then
  252. if [ "$OSTYPE" = 'rhel' ]; then
  253. echo "OS type : RHEL / Rocky Linux / AlmaLinux / EuroLinux"
  254. else
  255. echo "OS type : Debian / Ubuntu"
  256. fi
  257. echo "Branch : $branch"
  258. echo "Install : $install"
  259. echo "Build RPM : $BUILD_RPM"
  260. echo "Build DEB : $BUILD_DEB"
  261. echo "Hestia version : $BUILD_VER"
  262. echo "Nginx version : $NGINX_V"
  263. echo "PHP version : $PHP_V"
  264. echo "Architecture : $BUILD_ARCH"
  265. echo "Debug mode : $HESTIA_DEBUG"
  266. echo "Source directory : $SRC_DIR"
  267. fi
  268. # Generate Links for sourcecode
  269. HESTIA_ARCHIVE_LINK='https://github.com/hestiacp/hestiacp/archive/'$branch'.tar.gz'
  270. if [[ $NGINX_V =~ - ]]; then
  271. NGINX='https://nginx.org/download/nginx-'$(echo $NGINX_V | cut -d"-" -f1)'.tar.gz'
  272. else
  273. NGINX='https://nginx.org/download/nginx-'$(echo $NGINX_V | cut -d"~" -f1)'.tar.gz'
  274. fi
  275. OPENSSL='https://www.openssl.org/source/openssl-'$OPENSSL_V'.tar.gz'
  276. PCRE='https://github.com/PCRE2Project/pcre2/releases/download/pcre2-'$PCRE_V'/pcre2-'$PCRE_V'.tar.gz'
  277. ZLIB='https://github.com/madler/zlib/archive/refs/tags/v'$ZLIB_V'.tar.gz'
  278. if [[ $PHP_V =~ - ]]; then
  279. PHP='http://de2.php.net/distributions/php-'$(echo $PHP_V | cut -d"-" -f1)'.tar.gz'
  280. else
  281. PHP='http://de2.php.net/distributions/php-'$(echo $PHP_V | cut -d"~" -f1)'.tar.gz'
  282. fi
  283. # Forward slashes in branchname are replaced with dashes to match foldername in github archive.
  284. branch_dash=$(echo "$branch" | sed 's/\//-/g')
  285. #################################################################################
  286. #
  287. # Building hestia-nginx
  288. #
  289. #################################################################################
  290. if [ "$NGINX_B" = true ]; then
  291. echo "Building hestia-nginx package..."
  292. if [ "$CROSS" = "true" ]; then
  293. echo "Cross compile not supported for hestia-nginx or hestia-php"
  294. exit 1
  295. fi
  296. # Change to build directory
  297. cd $BUILD_DIR
  298. BUILD_DIR_HESTIANGINX=$BUILD_DIR/hestia-nginx_$NGINX_V
  299. if [[ $NGINX_V =~ - ]]; then
  300. BUILD_DIR_NGINX=$BUILD_DIR/nginx-$(echo $NGINX_V | cut -d"-" -f1)
  301. else
  302. BUILD_DIR_NGINX=$BUILD_DIR/nginx-$(echo $NGINX_V | cut -d"~" -f1)
  303. fi
  304. if [ "$KEEPBUILD" != 'true' ] || [ ! -d "$BUILD_DIR_HESTIANGINX" ]; then
  305. # Check if target directory exist
  306. if [ -d "$BUILD_DIR_HESTIANGINX" ]; then
  307. #mv $BUILD_DIR/hestia-nginx_$NGINX_V $BUILD_DIR/hestia-nginx_$NGINX_V-$(timestamp)
  308. rm -r "$BUILD_DIR_HESTIANGINX"
  309. fi
  310. # Create directory
  311. mkdir -p $BUILD_DIR_HESTIANGINX
  312. # Download and unpack source files
  313. download_file $NGINX '-' | tar xz
  314. download_file $OPENSSL '-' | tar xz
  315. download_file $PCRE '-' | tar xz
  316. download_file $ZLIB '-' | tar xz
  317. # Change to nginx directory
  318. cd $BUILD_DIR_NGINX
  319. # configure nginx
  320. ./configure --prefix=/usr/local/hestia/nginx \
  321. --with-http_ssl_module \
  322. --with-openssl=../openssl-$OPENSSL_V \
  323. --with-openssl-opt=enable-ec_nistp_64_gcc_128 \
  324. --with-openssl-opt=no-nextprotoneg \
  325. --with-openssl-opt=no-weak-ssl-ciphers \
  326. --with-openssl-opt=no-ssl3 \
  327. --with-pcre=../pcre2-$PCRE_V \
  328. --with-pcre-jit \
  329. --with-zlib=../zlib-$ZLIB_V
  330. fi
  331. # Change to nginx directory
  332. cd $BUILD_DIR_NGINX
  333. # Check install directory and remove if exists
  334. if [ -d "$BUILD_DIR$INSTALL_DIR" ]; then
  335. rm -r "$BUILD_DIR$INSTALL_DIR"
  336. fi
  337. # Copy local hestia source files
  338. if [ "$use_src_folder" == 'true' ] && [ -d $SRC_DIR ]; then
  339. cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch_dash
  340. fi
  341. # Create the files and install them
  342. make -j $NUM_CPUS && make DESTDIR=$BUILD_DIR install
  343. # Clear up unused files
  344. if [ "$KEEPBUILD" != 'true' ]; then
  345. rm -r $BUILD_DIR_NGINX $BUILD_DIR/openssl-$OPENSSL_V $BUILD_DIR/pcre2-$PCRE_V $BUILD_DIR/zlib-$ZLIB_V
  346. fi
  347. cd $BUILD_DIR_HESTIANGINX
  348. # Move nginx directory
  349. mkdir -p $BUILD_DIR_HESTIANGINX/usr/local/hestia
  350. rm -rf $BUILD_DIR_HESTIANGINX/usr/local/hestia/nginx
  351. mv $BUILD_DIR/usr/local/hestia/nginx $BUILD_DIR_HESTIANGINX/usr/local/hestia/
  352. # Remove original nginx.conf (will use custom)
  353. rm -f $BUILD_DIR_HESTIANGINX/usr/local/hestia/nginx/conf/nginx.conf
  354. # copy binary
  355. cp $BUILD_DIR_HESTIANGINX/usr/local/hestia/nginx/sbin/nginx $BUILD_DIR_HESTIANGINX/usr/local/hestia/nginx/sbin/hestia-nginx
  356. # change permission and build the package
  357. cd $BUILD_DIR
  358. chown -R root:root $BUILD_DIR_HESTIANGINX
  359. if [ "$BUILD_DEB" = true ]; then
  360. # Get Debian package files
  361. mkdir -p $BUILD_DIR_HESTIANGINX/DEBIAN
  362. get_branch_file 'src/deb/nginx/control' "$BUILD_DIR_HESTIANGINX/DEBIAN/control"
  363. if [ "$BUILD_ARCH" != "amd64" ]; then
  364. sed -i "s/amd64/${BUILD_ARCH}/g" "$BUILD_DIR_HESTIANGINX/DEBIAN/control"
  365. fi
  366. get_branch_file 'src/deb/nginx/copyright' "$BUILD_DIR_HESTIANGINX/DEBIAN/copyright"
  367. get_branch_file 'src/deb/nginx/postinst' "$BUILD_DIR_HESTIANGINX/DEBIAN/postinst"
  368. get_branch_file 'src/deb/nginx/postrm' "$BUILD_DIR_HESTIANGINX/DEBIAN/portrm"
  369. chmod +x "$BUILD_DIR_HESTIANGINX/DEBIAN/postinst"
  370. chmod +x "$BUILD_DIR_HESTIANGINX/DEBIAN/portrm"
  371. # Init file
  372. mkdir -p $BUILD_DIR_HESTIANGINX/etc/init.d
  373. get_branch_file 'src/deb/nginx/hestia' "$BUILD_DIR_HESTIANGINX/etc/init.d/hestia"
  374. chmod +x "$BUILD_DIR_HESTIANGINX/etc/init.d/hestia"
  375. # Custom config
  376. get_branch_file 'src/deb/nginx/nginx.conf' "${BUILD_DIR_HESTIANGINX}/usr/local/hestia/nginx/conf/nginx.conf"
  377. # Build the package
  378. echo Building Nginx DEB
  379. dpkg-deb -Zxz --build $BUILD_DIR_HESTIANGINX $DEB_DIR
  380. fi
  381. if [ "$BUILD_RPM" = true ]; then
  382. # Get RHEL package files
  383. get_branch_file 'src/rpm/nginx/hestia-nginx.spec' "${BUILD_DIR_HESTIANGINX}/hestia-nginx.spec"
  384. sed -i "s/%HESTIA-NGINX-VERSION%/${NGINX_V}/g" "${BUILD_DIR_HESTIANGINX}/hestia-nginx.spec"
  385. get_branch_file 'src/rpm/nginx/hestia-nginx.service' "${BUILD_DIR_HESTIANGINX}/hestia-nginx.service"
  386. # Custom config
  387. get_branch_file 'src/rpm/nginx/nginx.conf' "${BUILD_DIR_HESTIANGINX}/usr/local/hestia/nginx/conf/nginx.conf"
  388. # Build the package
  389. mkdir -p $BUILD_DIR/rpmbuild
  390. echo Building Nginx RPM
  391. rpmbuild -bb --define "sourcedir $BUILD_DIR_HESTIANGINX" --buildroot=$BUILD_DIR/rpmbuild/ ${BUILD_DIR_HESTIANGINX}/hestia-nginx.spec > ${BUILD_DIR_HESTIANGINX}.rpm.log
  392. cp ~/rpmbuild/RPMS/$(arch)/hestia-nginx-*.rpm $RPM_DIR
  393. rm ~/rpmbuild/RPMS/$(arch)/hestia-nginx-*.rpm
  394. rm -rf $BUILD_DIR/rpmbuild
  395. fi
  396. rm -r $BUILD_DIR/usr
  397. if [ "$KEEPBUILD" != 'true' ]; then
  398. # Clean up the source folder
  399. rm -r hestia-nginx_$NGINX_V
  400. rm -rf $BUILD_DIR/rpmbuild
  401. if [ "$use_src_folder" == 'true' ] && [ -d $BUILD_DIR/hestiacp-$branch_dash ]; then
  402. rm -r $BUILD_DIR/hestiacp-$branch_dash
  403. fi
  404. fi
  405. fi
  406. #################################################################################
  407. #
  408. # Building hestia-php
  409. #
  410. #################################################################################
  411. if [ "$PHP_B" = true ]; then
  412. if [ "$CROSS" = "true" ]; then
  413. echo "Cross compile not supported for hestia-nginx or hestia-php"
  414. exit 1
  415. fi
  416. echo "Building hestia-php package..."
  417. BUILD_DIR_HESTIAPHP=$BUILD_DIR/hestia-php_$PHP_V
  418. BUILD_DIR_PHP=$BUILD_DIR/php-$(echo $PHP_V | cut -d"~" -f1)
  419. if [[ $PHP_V =~ - ]]; then
  420. BUILD_DIR_PHP=$BUILD_DIR/php-$(echo $PHP_V | cut -d"-" -f1)
  421. else
  422. BUILD_DIR_PHP=$BUILD_DIR/php-$(echo $PHP_V | cut -d"~" -f1)
  423. fi
  424. if [ "$KEEPBUILD" != 'true' ] || [ ! -d "$BUILD_DIR_HESTIAPHP" ]; then
  425. # Check if target directory exist
  426. if [ -d $BUILD_DIR_HESTIAPHP ]; then
  427. rm -r $BUILD_DIR_HESTIAPHP
  428. fi
  429. # Create directory
  430. mkdir -p $BUILD_DIR_HESTIAPHP
  431. # Download and unpack source files
  432. cd $BUILD_DIR
  433. download_file $PHP '-' | tar xz
  434. # Change to untarred php directory
  435. cd $BUILD_DIR_PHP
  436. # Configure PHP
  437. ./configure --prefix=/usr/local/hestia/php \
  438. --enable-fpm \
  439. --with-fpm-user=admin \
  440. --with-fpm-group=admin \
  441. --with-libdir=lib/$(arch)-linux-gnu \
  442. --with-openssl \
  443. --with-mysqli \
  444. --with-gettext \
  445. --with-curl \
  446. --with-zip \
  447. --with-gmp \
  448. --enable-mbstring
  449. fi
  450. cd $BUILD_DIR_PHP
  451. # Create the files and install them
  452. make -j $NUM_CPUS && make INSTALL_ROOT=$BUILD_DIR install
  453. # Copy local hestia source files
  454. if [ "$use_src_folder" == 'true' ] && [ -d $SRC_DIR ]; then
  455. [ "$HESTIA_DEBUG" ] && echo DEBUG: cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch_dash
  456. cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch_dash
  457. fi
  458. # Move php directory
  459. [ "$HESTIA_DEBUG" ] && echo DEBUG: mkdir -p $BUILD_DIR_HESTIAPHP/usr/local/hestia
  460. mkdir -p $BUILD_DIR_HESTIAPHP/usr/local/hestia
  461. [ "$HESTIA_DEBUG" ] && echo DEBUG: rm -r $BUILD_DIR_HESTIAPHP/usr/local/hestia/php
  462. if [ -d $BUILD_DIR_HESTIAPHP/usr/local/hestia/php ]; then
  463. rm -r $BUILD_DIR_HESTIAPHP/usr/local/hestia/php
  464. fi
  465. [ "$HESTIA_DEBUG" ] && echo DEBUG: mv ${BUILD_DIR}/usr/local/hestia/php ${BUILD_DIR_HESTIAPHP}/usr/local/hestia/
  466. mv ${BUILD_DIR}/usr/local/hestia/php ${BUILD_DIR_HESTIAPHP}/usr/local/hestia/
  467. # copy binary
  468. [ "$HESTIA_DEBUG" ] && echo DEBUG: cp $BUILD_DIR_HESTIAPHP/usr/local/hestia/php/sbin/php-fpm $BUILD_DIR_HESTIAPHP/usr/local/hestia/php/sbin/hestia-php
  469. cp $BUILD_DIR_HESTIAPHP/usr/local/hestia/php/sbin/php-fpm $BUILD_DIR_HESTIAPHP/usr/local/hestia/php/sbin/hestia-php
  470. # Change permissions and build the package
  471. chown -R root:root $BUILD_DIR_HESTIAPHP
  472. if [ "$BUILD_DEB" = true ]; then
  473. # Get Debian package files
  474. [ "$HESTIA_DEBUG" ] && echo DEBUG: mkdir -p $BUILD_DIR_HESTIAPHP/DEBIAN
  475. mkdir -p $BUILD_DIR_HESTIAPHP/DEBIAN
  476. get_branch_file 'src/deb/php/control' "$BUILD_DIR_HESTIAPHP/DEBIAN/control"
  477. if [ "$BUILD_ARCH" != "amd64" ]; then
  478. sed -i "s/amd64/${BUILD_ARCH}/g" "$BUILD_DIR_HESTIAPHP/DEBIAN/control"
  479. fi
  480. get_branch_file 'src/deb/php/copyright' "$BUILD_DIR_HESTIAPHP/DEBIAN/copyright"
  481. get_branch_file 'src/deb/php/postinst' "$BUILD_DIR_HESTIAPHP/DEBIAN/postinst"
  482. chmod +x $BUILD_DIR_HESTIAPHP/DEBIAN/postinst
  483. # Get custom config
  484. get_branch_file 'src/deb/php/php-fpm.conf' "${BUILD_DIR_HESTIAPHP}/usr/local/hestia/php/etc/php-fpm.conf"
  485. get_branch_file 'src/deb/php/php.ini' "${BUILD_DIR_HESTIAPHP}/usr/local/hestia/php/lib/php.ini"
  486. # Build the package
  487. echo Building PHP DEB
  488. [ "$HESTIA_DEBUG" ] && echo DEBUG: dpkg-deb --build $BUILD_DIR_HESTIAPHP $DEB_DIR
  489. dpkg-deb -Zxz --build $BUILD_DIR_HESTIAPHP $DEB_DIR
  490. fi
  491. if [ "$BUILD_RPM" = true ]; then
  492. # Get RHEL package files
  493. get_branch_file 'src/rpm/php/hestia-php.spec' "${BUILD_DIR_HESTIAPHP}/hestia-php.spec"
  494. sed -i "s/%HESTIA-PHP-VERSION%/${PHP_V}/g" "${BUILD_DIR_HESTIAPHP}/hestia-php.spec"
  495. get_branch_file 'src/rpm/php/hestia-php.service' "${BUILD_DIR_HESTIAPHP}/hestia-php.service"
  496. # Get custom config
  497. get_branch_file 'src/rpm/php/php-fpm.conf' "${BUILD_DIR_HESTIAPHP}/usr/local/hestia/php/etc/php-fpm.conf"
  498. get_branch_file 'src/rpm/php/php.ini' "${BUILD_DIR_HESTIAPHP}/usr/local/hestia/php/lib/php.ini"
  499. # Build RPM package
  500. mkdir -p $BUILD_DIR/rpmbuild
  501. echo Building PHP RPM
  502. rpmbuild -bb --define "sourcedir $BUILD_DIR_HESTIAPHP" --buildroot=$BUILD_DIR/rpmbuild/ ${BUILD_DIR_HESTIAPHP}/hestia-php.spec > ${BUILD_DIR_HESTIAPHP}.rpm.log
  503. cp ~/rpmbuild/RPMS/$(arch)/hestia-php-*.rpm $RPM_DIR
  504. rm ~/rpmbuild/RPMS/$(arch)/hestia-php-*.rpm
  505. rm -rf $BUILD_DIR/rpmbuild
  506. fi
  507. rm -r $BUILD_DIR/usr
  508. # clear up the source folder
  509. if [ "$KEEPBUILD" != 'true' ]; then
  510. rm -r $BUILD_DIR/php-$(echo $PHP_V | cut -d"~" -f1)
  511. rm -r $BUILD_DIR_HESTIAPHP
  512. if [ "$use_src_folder" == 'true' ] && [ -d $BUILD_DIR/hestiacp-$branch_dash ]; then
  513. rm -r $BUILD_DIR/hestiacp-$branch_dash
  514. fi
  515. fi
  516. fi
  517. #################################################################################
  518. #
  519. # Building hestia
  520. #
  521. #################################################################################
  522. arch="$BUILD_ARCH"
  523. if [ "$HESTIA_B" = true ]; then
  524. if [ "$CROSS" = "true" ]; then
  525. arch="amd64 arm64"
  526. fi
  527. for BUILD_ARCH in $arch; do
  528. echo "Building Hestia Control Panel package..."
  529. BUILD_DIR_HESTIA=$BUILD_DIR/hestia_$HESTIA_V
  530. # Change to build directory
  531. cd $BUILD_DIR
  532. if [ "$KEEPBUILD" != 'true' ] || [ ! -d "$BUILD_DIR_HESTIA" ]; then
  533. # Check if target directory exist
  534. if [ -d $BUILD_DIR_HESTIA ]; then
  535. rm -r $BUILD_DIR_HESTIA
  536. fi
  537. # Create directory
  538. mkdir -p $BUILD_DIR_HESTIA
  539. fi
  540. cd $BUILD_DIR
  541. rm -rf $BUILD_DIR/hestiacp-$branch_dash
  542. # Download and unpack source files
  543. if [ "$use_src_folder" == 'true' ]; then
  544. [ "$HESTIA_DEBUG" ] && echo DEBUG: cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch_dash
  545. cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch_dash
  546. elif [ -d $SRC_DIR ]; then
  547. download_file $HESTIA_ARCHIVE_LINK '-' 'fresh' | tar xz
  548. fi
  549. mkdir -p $BUILD_DIR_HESTIA/usr/local/hestia
  550. # Move needed directories
  551. cd $BUILD_DIR/hestiacp-$branch_dash
  552. cp -rf bin func install web $BUILD_DIR_HESTIA/usr/local/hestia/
  553. # Set permissions
  554. find $BUILD_DIR_HESTIA/usr/local/hestia/ -type f -exec chmod -x {} \;
  555. # Allow send email via /usr/local/hestia/web/inc/mail-wrapper.php via cli
  556. chmod +x $BUILD_DIR_HESTIA/usr/local/hestia/web/inc/mail-wrapper.php
  557. # Allow the executable to be executed
  558. chmod +x $BUILD_DIR_HESTIA/usr/local/hestia/bin/*
  559. find $BUILD_DIR_HESTIA/usr/local/hestia/install/ \( -name '*.sh' \) -exec chmod +x {} \;
  560. chmod -x $BUILD_DIR_HESTIA/usr/local/hestia/install/*.sh
  561. chown -R root:root $BUILD_DIR_HESTIA
  562. if [ "$BUILD_DEB" = true ]; then
  563. # Get Debian package files
  564. mkdir -p $BUILD_DIR_HESTIA/DEBIAN
  565. get_branch_file 'src/deb/hestia/control' "$BUILD_DIR_HESTIA/DEBIAN/control"
  566. if [ "$BUILD_ARCH" != "amd64" ]; then
  567. sed -i "s/amd64/${BUILD_ARCH}/g" "$BUILD_DIR_HESTIA/DEBIAN/control"
  568. fi
  569. get_branch_file 'src/deb/hestia/copyright' "$BUILD_DIR_HESTIA/DEBIAN/copyright"
  570. get_branch_file 'src/deb/hestia/preinst' "$BUILD_DIR_HESTIA/DEBIAN/preinst"
  571. get_branch_file 'src/deb/hestia/postinst' "$BUILD_DIR_HESTIA/DEBIAN/postinst"
  572. chmod +x $BUILD_DIR_HESTIA/DEBIAN/postinst
  573. chmod +x $BUILD_DIR_HESTIA/DEBIAN/preinst
  574. echo Building Hestia DEB
  575. dpkg-deb -Zxz --build $BUILD_DIR_HESTIA $DEB_DIR
  576. fi
  577. if [ "$BUILD_RPM" = true ]; then
  578. # Get RHEL package files
  579. get_branch_file 'src/rpm/hestia/hestia.spec' "${BUILD_DIR_HESTIA}/hestia.spec"
  580. sed -i "s/%HESTIA-VERSION%/${HESTIA_V}/g" "${BUILD_DIR_HESTIA}/hestia.spec"
  581. get_branch_file 'src/rpm/hestia/hestia.service' "${BUILD_DIR_HESTIA}/hestia.service"
  582. # Build RPM package
  583. mkdir -p $BUILD_DIR/rpmbuild
  584. echo Building Hestia RPM
  585. rpmbuild -bb --define "sourcedir $BUILD_DIR_HESTIA" --buildroot=$BUILD_DIR/rpmbuild/ ${BUILD_DIR_HESTIA}/hestia.spec > ${BUILD_DIR_HESTIA}.rpm.log
  586. cp ~/rpmbuild/RPMS/$(arch)/hestia-*.rpm $RPM_DIR
  587. rm ~/rpmbuild/RPMS/$(arch)/hestia-*.rpm
  588. rm -rf $BUILD_DIR/rpmbuild
  589. fi
  590. # clear up the source folder
  591. if [ "$KEEPBUILD" != 'true' ]; then
  592. rm -r $BUILD_DIR_HESTIA
  593. rm -rf hestiacp-$branch_dash
  594. fi
  595. cd $BUILD_DIR/hestiacp-$branch_dash
  596. done
  597. fi
  598. #################################################################################
  599. #
  600. # Install Packages
  601. #
  602. #################################################################################
  603. if [ "$install" = 'yes' ] || [ "$install" = 'y' ] || [ "$install" = 'true' ]; then
  604. # Install all available packages
  605. echo "Installing packages..."
  606. if [ "$OSTYPE" = 'rhel' ]; then
  607. for i in $RPM_DIR/*.rpm; do
  608. dnf -y install $i
  609. if [ $? -ne 0 ]; then
  610. exit 1
  611. fi
  612. done
  613. else
  614. for i in $DEB_DIR/*.deb; do
  615. dpkg -i $i
  616. if [ $? -ne 0 ]; then
  617. exit 1
  618. fi
  619. done
  620. fi
  621. unset $answer
  622. fi