Ubuntu 服务器 LEMPPP 配置安装工具
该版本增加了开源的PHP内容管理系统的安装,系统默认提供了由安图软件提供的开源软件源中精选的一些开源PHP内容管理系统,用户还可以自己为该脚本增加支持的CMS系统,只需要增加remote_apps 变量的项目即可,具体方法请见脚本说明。
您可以直接使用下列命令获得该脚本:
wget http://dl.antusoft.com/tools/server-setup-tool/sst-v0.3.sh或者直接点击下载链接下载到本地
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if the user if root
if [ $(id -u) != "0" ]; then
echo "ERROR: You must login as root ro run this script!"
exit 1
fi
#clear
# default global variables
declare -A vars
declare -A apps
# do you want to upgrade the server first before set it up?
vars=(
[upgrade_server]="n"
# the default website meta information
[default_website_owner]="cox"
[default_website_domain]="_"
[default_website_error_log]="n"
[default_website_access_log]="n"
[default_website_applications]=""
[default_website_error_log]="error.log"
[default_website_access_log]="access.log"
[default_website_log]="y"
# mysql database's root password
[mysql_root_password]="root"
# install nginx extras or not
[install_nginx_extras]="y"
[install_common_cgi_support]="y"
[install_perl_support]="y"
# install phpmyadmin to the document root of default website or not?
[install_phpmyadmin]="y"
[install_movabletype]="n"
)
export vars
apps=(
[apps_server_root]="http://dl.antusoft.com/"
[apps_server_root2]="http://dl.coin.so/"
[phpmyadmin]="tools/phpmyadmin/phpMyAdmin-3.5.3-all-languages.tar.gz"
[wordpress]="cms/wordpress/wordpress-3.4.2-zh_CN.tar.gz"
[wordpress_en]="cms/wordpress/wordpress-3.4.2.tar.gz"
[drupal]="cms/drupal/drupal-7.17.tar.gz"
[openatrium]="cms/drupal/dist/openatrium-6.x-1.5-core.tar.gz"
[dokuwiki]="cms/dokuwiki/dokuwiki-2012-10-13.tgz"
[textpattern]="cms/textpattern/textpattern-4.5.2.tar.gz"
[movabletype]="cms/movabletype/MT-5.2.tar.gz"
[mediawiki]=""
)
remote_apps=(
# you can add you own cms list here
# one record per line
# format:
# [CMS_NAME_KEY]="CMS_REMOTE_DOWNLOAD_URL"
# e.g.
[mediawiki]="http://download.wikimedia.org/mediawiki/1.20/mediawiki-1.20.0.tar.gz"
)
export remote_apps
export apps
# hightlight echo
function hightlight() {
echo -e "33[40;31;5m $1 33[0m "
}
# separate line
function separate_line() {
if [ "$1" = "b" ]; then
echo "================================================================="
else
echo "-----------------------------------------------------------------"
fi
}
# function set variable to set vars
function set_variable() {
separate_line
# if not variable name
if [ "$1" = "" ]; then
hightlight "ERROR: no variable name!"
return
fi
# if got a value
if [ "$2" != "" ]; then
vars[$1]=$2
fi
echo "Set the value of variable: $1"
# echo the description of this value
echo $3
# get new value from user input
read -p "current value is $(hightlight ${vars[$1]}) ): " v
if [ "$v" != "" ]; then
vars[$1]=$v
echo "$1 => $v"
else
echo "no changes, default value will be used."
echo "$1 => ${vars[$1]}"
fi
}
function declare_variable() {
if [ "$2" != "" ]; then
echo $2
else
echo $1
fi
}
function check_user() {
echo $(cat /etc/passwd|grep $1|wc -l)
}
function create_user() {
if [ "$(check_user $1)" = "0" ]; then
useradd $1
fi
}
function copyright() {
separate_line b
echo "Server Setup Tool for Ubuntu - by Cox"
separate_line
echo "Version: 0.3"
echo "Modified: 2012/11/16"
echo "Url: http://cox.antusoft.com/project/ubuntu-server-setup-tool/"
separate_line
echo "Author: Cox Antu"
echo "Email: cox # antusoft.com"
echo "Url: http://cox.antusoft.com/"
echo "Mobile: 183-7488-8188"
echo "QQ: 54778899"
separate_line b
echo ""
}
function help() {
echo "-h --help for help"
echo "-s --setup for setup"
separate_line
}
function update_server() {
apt-get update
if [ "${vars[upgrade_server]}" = "y" ]; then
echo "upgrading your server..."
stty -echo
echo y | apt-get upgrade
stty echo
fi
separate_line
}
function install_mysql() {
echo "Installing mysql for you..."
echo y | apt-get install mysql-client mysql-server
separate_line
}
function install_nginx() {
echo "Installing nginx for you..."
if [ "${vars[install_nginx_extras]}" = "y" ]; then
echo "You are going to install nginx-extras"
echo y | apt-get install nginx-extras
else
echo y | apt-get install nginx
fi
separate_line
}
function install_php() {
echo "Installing php support for nginx..."
echo y | apt-get install
php5 php5-fpm php5-mysql php5-curl php5-gd php5-idn
php-pear php5-imagick php5-imap php5-mcrypt php5-memcache
php5-mhash php5-ming php5-ps php5-pspell php5-recode
php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
php5-json
/etc/init.d/php5-fpm restart
separate_line
}
function php_socket() {
if [ -S /var/run/php5-fpm.sock ]; then
echo "unix:/var/run/php5-fpm.sock"
else
echo "127.0.0.1:9000"
fi
}
function install_common_cgi_support() {
echo "Installing common cgi support for nginx..."
echo y | apt-get install fcgiwrap
separate_line
}
function install_perl_support() {
echo "Installing perl support for nginx"
echo y | apt-get install
dbconfig-common libarchive-zip-perl libcache-perl
libclass-data-inheritable-perl libclass-errorhandler-perl
libclass-inspector-perl libclass-load-perl libclass-singleton-perl
libclass-trigger-perl libcommon-sense-perl libconvert-binhex-perl
libcrypt-dh-gmp-perl libdata-objectdriver-perl libdatetime-perl
libdatetime-timezone-perl libdbd-pg-perl libdbd-sqlite3-perl
libfile-nfslock-perl libgd-gd2-perl libheap-perl libimage-size-perl
libio-stringy-perl libipc-run-perl libjcode-pm-perl libjson-perl
liblist-moreutils-perl liblucene-queryparser-perl libmath-round-perl
liblwp-authen-wsse-perl libmime-charset-perl libmime-encwords-perl
libmodule-runtime-perl libnet-openid-common-perl libio-pty-perl
libossp-uuid-perl libossp-uuid16 libpackage-deprecationmanager-perl
libpackage-stash-perl libpackage-stash-xs-perl libparams-classify-perl
libparams-util-perl libparams-validate-perl libpq5 libsoap-lite-perl
libsub-install-perl libtask-weaken-perl libtext-simpletable-perl
libtry-tiny-perl liburi-fetch-perl libxml-atom-perl
libxml-xpath-perl libjson-xs-perl libxml-libxslt-perl
libdata-optlist-perl libdatetime-locale-perl libfcgi-perl
libmime-tools-perl libtheschwartz-perl libnet-openid-consumer-perl
separate_line
}
function setup_website_directly() {
# $1 => website domain name
# $2 => website owner
# $3 => applications list for install
# $4 => log or not to log
# $5 => error log
# $6 => access log
domain=$(declare_variable ${vars[default_website_domain]} $1)
owner=$(declare_variable ${vars[default_website_owner]} $2)
applications=$(declare_variable ${vars[default_website_applications]} $3)
log=$(declare_variable ${vars[default_website_log]} $4)
error=$(declare_variable ${vars[default_website_error_log]} $5)
access=$(declare_variable ${vars[default_website_access_log]} $6)
conf_file="/etc/nginx/sites-available/$domain"
listen="80"
server_name="$domain"
domain_root="/home/$owner/websites/$domain"
root="$domain_root/public"
logs_root="$domain_root/logs"
error_log="$logs_root/$error"
access_log="$logs_root/$access"
touch error_log
touch access_log
error_log="error_log $logs_root/$error"
access_log="access_log $logs_root/$access"
# if not to log the website
if [ "$log" = "n" ]; then
error_log="#$error_log"
access_log="#access_log"
fi
php_fastcgi_pass="$(php_socket)"
create_user $owner
mkdir -p $root
mkdir -p $logs_root
chown $owner:www-data -R $domain_root
chmod g+w -R $domain_root
cat >>$root/info.php<<EOF
<?php phpinfo(); ?>
EOF
# create configuration file
if [ -f $conf_file ]; then
cp $conf_file $conf_file.bak
cat /dev/null > $conf_file
fi
cat >>$conf_file<<EOF
server {
listen 80;
server_name $server_name;
root $root;
$error_log;
$access_log;
index index.php index.html index.htm;
# php
location ~ .php$ {
try_files $uri = 404;
fastcgi_pass $php_fastcgi_pass;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# perl cgi movable type
location ~ ^/mt.*.cgi {
# the exact pattern is required fo MT.
fastcgi_split_path_info ^(/mt.*.cgi)(.*)$;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include fastcgi_params;
# MT related
fastcgi_param PERL5LIB $document_root/lib;
fastcgi_param MT_HOME $document_root;
fastcgi_param MT_CONFIG $document_root/mt-config.cgi;
# fcgiwrap related
fastcgi_param SCRIPT_NAME $document_root$fastcgi_script_name";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name";
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
}
}
EOF
cur_dir="$(pwd)"
cd /etc/nginx/sites-enabled/
if [ ! -L $domain ]; then
ln -s $conf_file
fi
/etc/init.d/nginx restart
echo "Setup website for $domain succeed!"
separate_line
}
# applications installer
function application_installer() {
# $1 => application name
# $2 => application domain name
# $3 => application owner
# $4 => application subfolder
app=$(declare_variable "textpattern" $1)
domain=$(declare_variable ${vars[default_website_domain]} $2)
owner=$(declare_variable ${vars[default_website_owner]} $3)
subfolder=$(declare_variable "" $4)
if [ "$1" == "" ]; then
read -p "Do you want to select an application? (default to $app): " na
if [ "$na" != "" ]; then
app=$na
fi
read -p "Do you want to select an domain of this app? (default to $domain): " nd
if [ "$nd" != "" ]; then
domain=$nd
fi
fi
read -p "do you want to install the application in a sub folder of your website
root? (default to n ):(y/N) " sf
if [ "$sf" != "" ]; then
subfolder=$app
fi
uri="${apps[$app]}"
url="${apps[apps_server_root]}$uri"
if [ "$uri" = "" ]; then
url="${remote_apps[$app]}"
fi
conf="/etc/nginx/sites-available/$domain"
root="/home/$owner/websites/$domain/public"
echo "URI: $uri"
echo "URL: $url"
echo "CONF: $conf"
echo "ROOT: $root"
# if the domain has been used
if [ -f "$conf" ]; then
hightlight "the domain has been used, do you want to choose another one?"
echo "If you want to select a new domain, just type it here,"
echo "or you can just pass this note and use this domain, if so, "
echo "i will make a backup of your exist website"
read -p "(default to $domain)" new_domain
if [ "$new_domain" != "" ]; then
# copy exist website
# this will be separated to a standalone function
# mv "$conf" "$root/$domain.conf"
# cd "/home/$owner"
# echo "backup exist website"
# tar zcvf "$domain.backup.tar.gz" "/home/$owner/websites/$domain"
# mv "$root" "$root.old"
# setup_website_directly $domain $owner ""
domain=$new_domain
setup_website_directly $domain $owner ""
fi
else
setup_website_directly $domain $owner
fi
cd $root
wget -c $url
to="/tmp/application_installer/$app"
if [ ! -d $to ]; then
mkdir -p $to
fi
tar zxvf "$root/$(basename $url)" -C $to
sub=""
# how many files or folders?
dirs=($(ls $to))
if [ "${#dirs[@]}" = "1" ]; then
from="$to/${dirs[0]}/*"
else
from="$to/*"
fi
if [ "$subfolder" = "" ]; then
to="$root/"
else
to="$root/$subfolder/"
fi
if [ ! -d $to ]; then
mkdir -p $to
fi
echo "mv $from $to"
mv $from $to
echo "Install $app succeed"
echo "you can open your browser and visit : http://$domain/ to run
the application..."
}
function setup_website() {
read -p "(domain name): " domain
read -p "(owner): " owner
read -p "(applications): " applications
read -p "(log Y/n): " log
read -p "(error log): " error_log
read -p "(access log): " access_log
setup_website_directly $domain $owner $applications $log $error_log $access_log
}
function setup() {
copyright
# upgrade the server or not
set_variable upgrade_server "" "If you want to upgrade the server
before set it up, please choose y"
# install common nginx or with extras
set_variable install_nginx_extras "" "Do you want to install the extra
functions of nginx?"
# set the server's default domain name
set_variable default_website_domain "" "This should not be a domain you
want to use in your pub site."
# set the owner of the default website
set_variable default_website_owner "" "The website's content will be
stored in his home folder"
# set website logs
set_variable default_website_log "" "If you do not want to log your
website, pleast choose n."
set_variable default_website_error_log
set_variable default_website_access_log
# install perl support or not?
set_variable install_perl_support "" "If you want to run perl
applications in your server, you should choose y to install perl
support for nginx server."
separate_line b
# update or upgrade the server
update_server
# install mysql server the client
install_mysql
# install nginx or nginx-extras
install_nginx
# install php and some extra libs
install_php
# install perl support or not
if [ "${vars[install_perl_support]}" = "y" ]; then
install_perl_support
install_common_cgi_support
fi
setup_website_directly
application_installer
# $1 => website domain name
# $2 => website owner
# $3 => applications list for install
# $4 => log or not to log
# $5 => error log
# $6 => access log
}
# ==================================================================== #
# Start the program
case "$1" in
--help|-h)
help
;;
--setup-website|-sw)
setup_website
;;
--setup|-s|--install|-i)
setup
;;
--install-app|-ia)
application_installer
;;
*)
setup
esac
评论已关闭