v-update-sys-hestia-git 13 KB

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