Ubuntu 脚本 常用软件+ruby on rails


初次使用Ubuntu,我想这个脚本会大大方便你配置Ubuntu,ruby on rails是本人的爱好,你也可以直接注释掉最后己行,只安装软件亦可

#!/bin/bash
RUBY_VERSION="1.8.6-p287"
RUBY_GEM_VERSION="1.3.1"
RAILS_APP_DEPLOYMENT_DIR="/var/www/rails"
MOD_RAILS_VERSION="2.0.3"
export LANG=C
#detect distro version
if [ -e /etc/RedHat-release ]; then
DISTRO="redhat"
elif [ -e /etc/debian_version ]; then
DISTRO="debian"
fi
#set apt-get modifier based on distro
if [ $DISTRO == "redhat" ]; then
APTMOD=" -y "
elif [ $DISTRO == "debian" ]; then
APTMOD="-y --force-yes"
fi
#misc settings based on distro
if [ $DISTRO == "redhat" ]; then
RAILS_APP_CONFIG="/etc/httpd/conf.d/railsapps.conf"
MOD_RAILS_CONFIG="/etc/httpd/conf.d/mod_rails.conf"
elif [ $DISTRO == "debian" ]; then
RAILS_APP_CONFIG="/etc/apache2/conf.d/railsapps.conf"
MOD_RAILS_CONFIG="/etc/apache2/conf.d/mod_rails.conf"
fi
####################
# HELPER FUNCTIONS #
####################
##
# view std out and append to log
function echolog() {
echo $* | tee -a /root/install.log
}
##
# download file and cd there
function download() {
local name=$1
local version=$2
local url=$3
mkdir -p /usr/local/src
cd /usr/local/src
if [ -d /usr/local/src/$name-$version ]; then
echolog "$name directory already exists, skipping the download"
cd /usr/local/src/$name-$version
return 0
fi
echolog "Grabbing $name from $url"
wget -qO - $url | tar xz
if [ $? -ne 0 ]; then
echolog "failed getting $url" >&2
return 1
fi
cd /usr/local/src/$name-$version
}
##
# apt-get update
function aptgetupdate() {
echolog Performing system update via package manager
apt-get update
apt-get $APTMOD upgrade
}
function aptgetmysf(){
#install the software what i want, it works in ubuntu
apt-get install $APTMOD  nautilus-open-terminal
apt-get install $APTMOD  compizconfig-settings-manager
apt-get install $APTMOD  libxine1-ffmpeg libxine1-plugins w32codecs libdvdcss2
apt-get install $APTMOD  gstreamer0.10-plugins-ugly gstreamer0.10-ffmpeg gstreamer0.10-fluendo-mpegdemux gstreamer0.10-gnonlin
apt-get remove $APTMOD totem-gstreamer -y
apt-get install $APTMOD  totem totem-xine totem-mozilla -y
apt-get install $APTMOD  mplayer mplayer-fonts mozilla-mplayer smplayer
apt-get install $APTMOD  acroread
apt-get install $APTMOD  mozilla-acroread
apt-get install $APTMOD  acroread-plugins
#    apt-get install $APTMOD  gnochm
apt-get install $APTMOD  flashplugin-nonfree
apt-get install $APTMOD  rar unrar
apt-get install $APTMOD  sun-java6-jre
apt-get install $APTMOD  sun-java6-jdk
apt-get install $APTMOD  sun-java6-plugin
apt-get install $APTMOD  libgtk2.0-dev xorg-dev ncurses-dev build-essential # need by vim
apt-get install $APTMOD  build-essential gcc make autoconf automake libtool gdb g++
}
##
# install prerequisites
function installprereqpackages() {
echolog Installing prerequisite packages via package manager
if [ $DISTRO == "redhat" ] ; then
apt-get $APTMOD install zlib-devel
apt-get $APTMOD install readline-devel readline
apt-get $APTMOD install mysql-devel
apt-get $APTMOD install libmysqlclient15-dev
apt-get $APTMOD install pcre pcre-devel
apt-get $APTMOD install which
apt-get $APTMOD install httpd-devel
elif [ $DISTRO == "debian" ]; then
apt-get install $APTMOD zlib1g-dev
apt-get install $APTMOD 'g++-3.4'
apt-get install $APTMOD libmysqlclient14-dev
apt-get install $APTMOD libreadline5-dev
apt-get install $APTMOD libwmf-bin
apt-get install $APTMOD libmysqlclient15-dev
apt-get install $APTMOD libssl-dev
apt-get install $APTMOD apache2-prefork-dev
fi
}
##
# install ImageMagik
function installimagemagik() {
download ImageMagick 6.4.3 http://downloads.rimuhosting.com/ImageMagick-6.4.3.tar.gz
echolog Installing ImageMagick VERSION=6.4.3
if [ $? -ne 0 ]; then echolog "failed downloading imagemagick" >&2; return 1; fi
./configure && make && make install
if [ $? -ne 0 ]; then
echolog "ImageMagick make install failed">&2
return 1
fi
}
##
# install ruby & dev libraries
function installruby() {
download ruby $RUBY_VERSION http://downloads.rimuhosting.com/ruby-$RUBY_VERSION.tar.gz
echolog Installing Ruby VERSION=$RUBY_VERSION
if [ $? -ne 0 ]; then echolog "failed downloading ruby" >&2; return 1; fi
./configure && make && make test && make install
if [ $? -ne 0 ]; then
echolog "Ruby make install failed">&2
return 1
fi
# so there'll be a /usr/bin/ruby to use
if [ -e /usr/local/bin/ruby -a ! -e /usr/bin/ruby ]; then
ln -sf /usr/local/bin/ruby /usr/bin/ruby
fi
# doing this voodoo to prevent errors like:
# /usr/local/lib/ruby/1.8/irb/completion.rb:10:in `require’: no such file to load—readline (LoadError)
cd /usr/local/src/ruby-$RUBY_VERSION/ext/readline
if [ $? -ne 0 ]; then echolog "no /usr/local/src/ruby-$VERSION_ACTUAL/ext/readline dir">&2;return 1;fi
ruby extconf.rb
if [ $? -ne 0 ]; then echolog "readline extconf.rb failed">&2;return 1;fi
make clean && make install
if [ $? -ne 0 ]; then echolog "readline make failed">&2;return 1;fi
}
##
# install ruby gem
function installrubygems() {
download rubygems $RUBY_GEM_VERSION http://downloads.rimuhosting.com/rubygems-$RUBY_GEM_VERSION.tgz
echolog Installing Ruby Gems VERSION=$RUBY_GEM_VERSION
if [ $? -ne 0 ]; then echolog "failed downloading rubygems" >&2; return 1; fi
ruby setup.rb
if [ $? -ne 0 ]; then
echolog "Rubygems install failed">&2
return 1
fi
}
##
# install commonly used gems
function installcommongems() {
echolog Installing commonly used Ruby Gems
GEM_LIST="rails mongrel mongrel_cluster capistrano rmagick ruby-openid sqlite3-ruby mysql icalendar BlueCloth"
for gem in $GEM_LIST; do
gem install --include-dependencies $gem;
if [ $? -ne 0 ]; then
echolog "failed to install gem '$gem'"
fi
done
#install mysql gem is sometimes trouble (CentOS), installing it individually
if [ $DISTRO == "redhat" ]; then
gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
elif [ $DISTRO == "debian" ]; then
gem install mysql
fi
#install mod_rails
gem install passenger --include-dependencies -v $MOD_RAILS_VERSION
#compile mod_rails apache module
#passenger-install-apache2-module
}
##
# create deployment environment
function createdeployenv() {
echolog Configuring mod_rails/Apache
#create app deployment directory w/correct permissions
mkdir $RAILS_APP_DEPLOYMENT_DIR
#remove apache default vhost / welcome screen
if [ $DISTRO == "redhat" ]; then
mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak
elif [ $DISTRO == "debian" ]; then
rm /etc/apache2/sites-enabled/000-default
fi
#add basic passenger config
echo "LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-$MOD_RAILS_VERSION/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-$MOD_RAILS_VERSION
PassengerRuby /usr/local/bin/ruby
RailsEnv production
#Tune these to suit your application
PassengerMaxPoolSize 2
PassengerMaxInstancesPerApp 2
PassengerPoolIdleTime 600" > $MOD_RAILS_CONFIG
#create test rails app
cd $RAILS_APP_DEPLOYMENT_DIR
rails testapp
#create virtual host for test rails app
echo "<VirtualHost *:80>
DocumentRoot ${RAILS_APP_DEPLOYMENT_DIR}/testapp/public
</VirtualHost>" > $RAILS_APP_CONFIG
#restart apache
if [ $DISTRO == "redhat" ]; then
/etc/init.d/httpd restart
elif [ $DISTRO == "debian" ]; then
/etc/init.d/apache2 restart
fi
}
####################
#    EXECUTION     #
####################
aptgetupdate
aptgetmysf
installprereqpackages
installimagemagik
installruby
installrubygems
installcommongems
#createdeployenv
exit 0

相关内容