Created
December 23, 2011 12:42
-
-
Save qhwa/1514096 to your computer and use it in GitHub Desktop.
Build a web developer collaboration server in RedHat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#****************************************************************# | |
# ScriptName: build-wd-server.sh | |
# Author: hua.qiuh | |
# Create Date: 2011-12-02 | |
# Modify Author: | |
# Modify Date: 2011-12-02 | |
# Function: | |
#***************************************************************# | |
SOURCE_DIR=/root/source | |
function setup_wd_server(){ | |
create_users | |
install_softwares | |
setup_configs | |
} | |
function create_users(){ | |
info '>> creating users' | |
groupadd www -f | |
useradd -M www -g www | |
groupadd mysql -f | |
useradd -M mysql -g mysql | |
chmod 755 /home/ued65 | |
groupadd ued65 -f | |
useradd -m ued65 -g ued65 --password=ued65 | |
useradd -m git -g ued65 --password=ued65 -s /usr/local/bin/git-shell | |
chmod 755 /home/ued65 | |
chmod 755 /home/git | |
} | |
function install_softwares(){ | |
prepare_lib | |
install_git | |
install_imagemagick | |
install_mysql | |
install_php | |
install_ruby | |
install_nginx | |
install_passenger | |
} | |
function prepare_lib(){ | |
rpm -Uh $SOURCE_DIR/*.rpm | |
yum -y install \ | |
gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel \ | |
freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel \ | |
glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses \ | |
ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 \ | |
krb5-devel libidn libidn-devel openssl openssl-devel openldap \ | |
openldap-devel nss_ldap openldap-clients openldap-servers \ | |
> /dev/null | |
} | |
function install_git(){ | |
info '>> Installing git' | |
git --version && cong 'git has been installed' && return | |
install_from_source 'git' | |
} | |
function install_imagemagick(){ | |
info '>> Installing ImageMagick' | |
display --version && cong 'imagemagick has been installed' && return | |
install_from_source 'ImageMagick' | |
} | |
function install_mysql(){ | |
info '>> Installing MySQL' | |
mysql --version && cong 'MySQL has been installed' && return | |
yum --enablerepo=remi install mysql mysql-server mysql-libs | |
} | |
function install_php(){ | |
info '>> Installing PHP' | |
/usr/bin/php --version && cong 'PHP has been installed' && return | |
yum --enablerepo=remi install php-cli php-mysql php-fpm php-gd | |
install_from_source 'spawn-fcgi' | |
} | |
function install_php_ext(){ | |
cd $SOURCE_DIR | |
extract $1 && phpize && ./configure -q && make -j -s && make -s install | |
} | |
function install_ruby(){ | |
info '>> Installing Ruby' | |
ruby --version && cong 'Ruby has been installed' && return | |
install_from_source 'yaml' | |
install_from_source 'ruby' | |
install_ruby_exts | |
} | |
function install_ruby_exts(){ | |
cd ext | |
for ext in `ls` | |
do | |
if [ -f "$ext/extconf.rb" ]; then | |
cd $ext | |
log "compiling extension $ext" | |
ruby extconf.rb | |
make && make install | |
cd .. | |
fi | |
done | |
} | |
function install_nginx(){ | |
info '>> Installing Nginx' | |
[ -x /usr/local/nginx/sbin/nginx ] && cong 'Nginx has been installed' && return | |
install_from_source 'pcre' | |
install_from_source 'nginx' '--user=www --group=www' | |
} | |
function install_passenger(){ | |
info '>> Installing passenger' | |
#install_rack | |
cd $SOURCE_DIR || (warn 'Installing rack failed' ; return) | |
nginx_src_dir=$SOURCE_DIR/`find . -maxdepth 1 -type d -name 'nginx*'` | |
extract 'passenger' || (warn "passenger source not found!" && return) | |
./bin/passenger-install-nginx-module \ | |
--auto --prefix=/usr/local/nginx \ | |
--nginx-source-dir=$nginx_src_dir \ | |
--extra-configure-flags='--user=www --group=www' | |
} | |
function install_rack(){ | |
info '>>> Installing rack' | |
ruby -rrack -e 'puts 1' > /dev/null || | |
gem install rack | |
} | |
function install_from_source(){ | |
cd $SOURCE_DIR | |
extract $1 || (warn "$1 source not found!" && return) | |
log "Compiling $1 $2" | |
make -s clean | |
./configure -q $2 && make -j -s && make -s install && return | |
warn "installing $1 failed" | |
} | |
#--------------- configs -------------- | |
function setup_configs(){ | |
setup_nginx | |
setup_mysql | |
setup_samba | |
} | |
function setup_nginx(){ | |
/etc/init.d/php-fpm start | |
ln -s /root/wd-service/config/nginx /usr/local/nginx/conf/wd | |
info 'please add this line into /usr/local/nginx/conf/nginx.conf,' | |
info 'in the "http { }" block:' | |
info 'include wd/nginx.wd.conf;' | |
} | |
function setup_mysql(){ | |
mysql_install_db | |
service mysqld start | |
mysql -uroot < /root/wd-service/data/db.sql | |
} | |
function setup_samba(){ | |
echo -e "ued65\nued65" | smbpasswd -a ued65 -s | |
} | |
#--------------- helpers -------------- | |
function extract(){ | |
(tar xzf $1*.tar.gz || tar xzf $1*.tgz || tar xjf $1*.tar.bz2 || tar xjf $1*.tar.bz ) && cd $1* | |
} | |
function log(){ | |
echo -e "\e[35m$1\e[0m" | |
} | |
function warn(){ | |
echo -e "\e[31m$1\e[0m" | |
} | |
function info(){ | |
echo $1 | |
} | |
function cong(){ | |
echo -e "\e[32m$1\e[0m" | |
} | |
setup_wd_server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment