sh script.sh

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh script.sh相关的知识,希望对你有一定的参考价值。

#!/bin/bash

for ARGUMENT in "$@"; do
    KEY=$(echo $ARGUMENT | cut -f1 -d=)
    VALUE=$(echo $ARGUMENT | cut -f2 -d=)
    case "$KEY" in
    add_node) add_node=${VALUE} ;;
    *) ;;
    esac
done

if [ "$(id -u)" != '0' ]; then
    echo $"You have no permission to run $0 as non-root user. Use sudo"
    exit 1
fi

if [ "$1" = 'install' ]; then
    apt-get update &&
        apt-get -y install apt-transport-https lsb-release ca-certificates wget curl &&
        wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg &&
        sh -c 'echo "deb https://packages.sury.org/php/ stretch main" > /etc/apt/sources.list.d/php.list'
    # sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
    apt-get update
    # apt-get install -y apt-transport-https lsb-release ca-certificates curl gnupg mbstring json
    # curl https://packages.sury.org/php/apt.gpg | apt-key add -
    # echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" >/etc/apt/sources.list.d/php.list
    # apt-get update
    apt-get install -y --allow-unauthenticated php5.6 php5.6-sqlite3 sqlite3 apache2
    curl -O https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
    tar -xvzf ioncube_loaders_lin_x86-64.tar.gz
    EXT_DIR=$(php -i | grep ^extension_dir | cut -d '=' -f3 | cut -c 3-)
    echo "php extension dir=${EXT_DIR}"
    mkdir -p ${EXT_DIR}
    cp -rf ioncube/ioncube_loader_lin_5.6.so ${EXT_DIR}
    rm -rf ioncube_loaders_lin_x86-64.tar.gz ioncube
    echo "zend_extension=${EXT_DIR}/ioncube_loader_lin_5.6.so" >>/etc/php/5.6/apache2/php.ini
    echo "zend_extension=${EXT_DIR}/ioncube_loader_lin_5.6.so" >>/etc/php/5.6/cli/php.ini

    curl -O https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh
    chmod +x ./acme.sh
    ./acme.sh --install

    ### enable required modules for apache2 with https
    a2enmod headers
    a2enmod rewrite
    a2enmod ssl
    service apache2 restart

fi

email='webmaster@localhost'$()
sitesEnabled='/etc/apache2/sites-enabled/'
sitesAvailable='/etc/apache2/sites-available/'
userDir='/var/www/'
sitesAvailabledomain=$sitesAvailable${add_node}.conf

if [ "$rootDir" == "" ]; then
    rootDir=${add_node//./}
fi

### if root dir starts with '/', don't use /var/www as default starting point
if [[ "$rootDir" =~ ^/ ]]; then
    userDir=''
fi

rootDir=${userDir}${rootDir}

if [ "$add_node" != '' ]; then
    ### check if directory exists or not
    if ! [ -d $rootDir ]; then
        ### create the directory
        mkdir $rootDir
        ### give permission to root dir
        chmod 777 $rootDir
    fi
    ### write test file in the new domain dir
    # echo "<?php echo phpinfo(); ?>" >$rootDir/phpinfo.php

    if ! echo "
<VirtualHost *:80>
    DocumentRoot $rootDir
    ServerName ${add_node}
</VirtualHost>
" >$sitesAvailabledomain; then
        echo -e $"There is an ERROR creating ${add_node} file"
        exit
    else
        echo -e $"\nNew vhost created\n"
    fi
    ### enable website
    a2ensite ${add_node}
    ### restart Apache
    service apache2 restart

    ## issue cert
    mkdir -p /etc/apache2/ssl
    ./acme.sh --issue --apache -d ${add_node} &&
        if ! echo "
<IfModule mod_ssl.c>
    <VirtualHost *:443>
        DocumentRoot ${rootDir}
        ServerName ${add_node}
        SSLEngine on
        SSLCertificateFile    /etc/apache2/ssl/${add_node}.crt
        SSLCertificateKeyFile /etc/apache2/ssl/${add_node}.key
        SSLCertificateChainFile /etc/apache2/ssl/letsencrypt.pem
        SSLCACertificateFile /etc/apache2/ssl/letsencrypt.pem
    </VirtualHost>
</IfModule>
        " >>$sitesAvailabledomain; then
            echo -e $"There is an ERROR adding HTTPS vhost ${add_node}"
            exit
        else
            echo -e $"\nHTTPS vhost Added\n"
        fi
    ./acme.sh --install-cert -d ${add_node} \
        --cert-file /etc/apache2/ssl/${add_node}.crt \
        --key-file /etc/apache2/ssl/${add_node}.key \
        --fullchain-file /etc/apache2/ssl/letsencrypt.pem \
        --reloadcmd "service apache2 reload"

fi

url='https://shopsgates.com/node/last.dat'
curl ${url} -L -o ${rootDir}/index.php &&
    chmod 777 ${rootDir}/index.php

以上是关于sh script.sh的主要内容,如果未能解决你的问题,请参考以下文章

sh script.sh

sh script.sh

sh script.sh

sh script.sh

sh script.sh

sh startup-script.sh