v-update-sys-hestia-git 13 KB

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