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