v-update-sys-hestia-git 14 KB

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