Last active
January 7, 2016 11:44
-
-
Save ball6847/d632ee2c50315b05e922 to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
TERM=xterm | |
PREFIX=/opt/gitlab | |
SOURCE_DIR=$PREFIX/src | |
LIB_DIR=$PREFIX/lib | |
GITLAB_HOME=$PREFIX/home/git | |
GITLAB_VERSION=8.3.2 | |
GITLAB_INSTALL_DIR=$GITLAB_HOME/gitlab | |
GITLAB_SHELL_VERSION=2.6.9 | |
GITLAB_SHELL_INSTALL_DIR=$GITLAB_HOME/gitlab-shell | |
GITLAB_WORKHORSE_VERSION=0.5.1 | |
GITLAB_WORKHORSE_INSTALL_DIR=$GITLAB_HOME/gitlab-workhorse | |
REDIS_SOCKET=$PREFIX/var/run/redis.sock | |
POSTGRES_HOME=$PREFIX/var/lib/postgresql | |
POSTGRES_DATA=$POSTGRES_HOME/data | |
POSTGRES_SOCKET_DIR=$PREFIX/var/run/postgresql | |
GO_PATH=$PREFIX/opt/go | |
NCORE=`grep -c ^processor /proc/cpuinfo` # number of cpu core | |
PATH=$PREFIX/bin:$PREFIX/opt/node-v5.3.0-linux-x64/bin:$GO_PATH/bin:$PATH | |
LD_LIBRARY_PATH=$PREFIX/lib:$PREFIX/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64 | |
export PATH | |
export LD_LIBRARY_PATH | |
exec_as_git() { | |
sudo -HEu git \ | |
LD_LIBRARY_PATH=$LD_LIBRARY_PATH \ | |
RAILS_ENV=production \ | |
GOROOT=$GO_PATH \ | |
"$@" | |
} | |
exec_as_postgres() { | |
sudo -Hiu postgres "$@" | |
} | |
start_gitlab() { | |
redis-server $PREFIX/etc/redis.conf & # to start redis server | |
exec_as_postgres postgres -D $POSTGRES_DATA -k $POSTGRES_SOCKET_DIR & | |
} | |
# end bootstrap | |
# ------------------------------------------------------------------- | |
# export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH | |
yum -y update | |
yum -y groupinstall 'Development Tools' | |
yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git cmake libcom_err-devel.i686 libcom_err-devel.x86_64 nodejs gettext-devel zlib-devel gcc bzip2-devel tk-devel | |
mkdir -p $PREFIX/{home,bin,lib,src,opt,var/lib/postgresql} | |
# System Users, see: https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centos#3-system-users | |
adduser -r --shell /bin/bash --comment 'GitLab' --create-home --home-dir $GITLAB_HOME git | |
# @TODO: add postgres and redis user, then add git to those group, to make socket file secure | |
echo "export PATH=$PREFIX/bin:\$PATH" >> $GITLAB_HOME/.bashrc | |
# ------------------------------------------------------------------- | |
# install ruby | |
cd $SOURCE_DIR | |
(curl --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz | tar xz) && cd ruby-2.3.0 | |
./configure --prefix=$PREFIX --disable-install-rdoc | |
make | |
make install | |
gem install bundler --no-doc | |
# ------------------------------------------------------------------- | |
# install python | |
# debs: python -> libgit2 -> rugged -> gitlab | |
cd $SOURCE_DIR | |
(curl --progress https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz | tar zx) | |
mkdir Python-2.7.11/build && cd Python-2.7.11/build | |
../configure --prefix=$PREFIX | |
make | |
make install | |
(curl -k --progress https://bootstrap.pypa.io/get-pip.py | python) && pip install virtualenv | |
# ------------------------------------------------------------------- | |
# install nodejs | |
cd $PREFIX/opt | |
(curl --progress https://nodejs.org/dist/v5.3.0/node-v5.3.0-linux-x64.tar.gz | tar zx) | |
# ------------------------------------------------------------------- | |
# install go | |
cd $PREFIX/opt | |
(curl -L --progress https://storage.googleapis.com/golang/go1.5.2.linux-amd64.tar.gz | tar zx) | |
# ------------------------------------------------------------------- | |
# install cmake | |
# debs: cmake (2.8+) -> libgit2 -> rugged -> gitlab | |
cd $SOURCE_DIR | |
(curl -k --progress https://cmake.org/files/v3.4/cmake-3.4.1.tar.gz | tar zx) && mkdir cmake-3.4.1/build && cd cmake-3.4.1/build | |
../configure --prefix=$PREFIX | |
make | |
make install | |
# ------------------------------------------------------------------- | |
# install latest icu, centos5 libicu is outdated and not compatible with gitlab | |
cd $SOURCE_DIR | |
(curl --progress http://download.icu-project.org/files/icu4c/56.1/icu4c-56_1-src.tgz | tar zx) && cd icu/source | |
./configure --prefix=$PREFIX | |
make | |
make install | |
# ------------------------------------------------------------------- | |
# install openssl | |
# debs: libssl -> libcurl + libssh2 -> libgit2 -> rugged -> gitlab | |
cd $SOURCE_DIR | |
(curl -L --progress https://github.com/openssl/openssl/archive/OpenSSL_1_0_2e.tar.gz | tar zx) && cd openssl-OpenSSL_1_0_2e | |
./config no-threads shared --prefix=$PREFIX | |
make | |
make install | |
# ------------------------------------------------------------------- | |
# install libcurl | |
# debs: libcurl -> -> libssh2 -> libgit2 -> rugged -> gitlab | |
cd $SOURCE_DIR | |
(curl --progress http://curl.haxx.se/download/curl-7.46.0.tar.gz | tar zx) && cd curl-7.46.0 | |
./configure --prefix=$PREFIX --with-ssl=$PREFIX/include/openssl | |
make | |
make install | |
# ------------------------------------------------------------------- | |
# install libssh2 | |
# debs: libssh2 -> libgit2 -> rugged -> gitlab | |
cd $SOURCE_DIR | |
(curl --progress http://www.libssh2.org/download/libssh2-1.6.0.tar.gz | tar zx) && mkdir libssh2-1.6.0/build && cd libssh2-1.6.0/build | |
../configure --prefix=$PREFIX --with-openssl --with-libssl-prefix=$PREFIX | |
make && make install | |
# ------------------------------------------------------------------- | |
# install libgit2 | |
# libgit2 -> rugged -> gitlab | |
cd $SOURCE_DIR | |
(curl -L --progress https://github.com/libgit2/libgit2/archive/v0.23.4.tar.gz | tar zx) && mkdir libgit2-0.23.4/build && cd libgit2-0.23.4/build | |
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PREFIX/lib64/pkgconfig:/usr/lib/pkgconfig | |
$PREFIX/bin/cmake .. -DBUILD_CLAR=Off -DCMAKE_INSTALL_PREFIX=$PREFIX | |
make && make install | |
# ------------------------------------------------------------------- | |
# install git | |
cd $SOURCE_DIR | |
(curl -L --progress https://github.com/git/git/archive/v2.7.0-rc3.tar.gz | tar xz) && cd git-2.7.0-rc3 | |
make configure | |
./configure --prefix=$PREFIX | |
make all | |
make install | |
# ------------------------------------------------------------------- | |
# install PostgreSQL, and create postgres user and initdb | |
# see, http://www.postgresql.org/docs/9.4/static/install-procedure.html | |
# see, http://www.yolinux.com/TUTORIALS/LinuxTutorialPostgreSQL.html | |
cd $PREFIX/src | |
(curl --progress https://ftp.postgresql.org/pub/source/v9.4.5/postgresql-9.4.5.tar.gz | tar xz) && cd postgresql-9.4.5 | |
./configure --prefix=$PREFIX --sysconfdir=$PREFIX/etc | |
make | |
make install | |
adduser -r --shell /bin/bash --create-home --home-dir $PREFIX/var/lib/postgresql postgres | |
mkdir -p $POSTGRES_SOCKET_DIR | |
chown -R postgres:postgres $POSTGRES_SOCKET_DIR | |
mkdir -p $POSTGRES_DATA | |
chown -R postgres:postgres $POSTGRES_DATA | |
echo " | |
export PATH=$PREFIX/bin:\$PATH | |
export PGLIB=$PREFIX/lib/postgresql | |
export PGDATA=$POSTGRES_DATA | |
export PGHOST=$POSTGRES_SOCKET_DIR | |
" > $PREFIX/var/lib/postgresql/.bash_profile | |
exec_as_postgres initdb | |
exec_as_postgres postgres -D $POSTGRES_DATA -k $POSTGRES_SOCKET_DIR -c listen_addresses='' & # start service | |
exec_as_postgres psql -c "CREATE USER git CREATEDB;" -d template1 | |
exec_as_postgres psql -c "CREATE DATABASE gitlabhq_production OWNER git;" -d template1 | |
# ------------------------------------------------------------------- | |
# install redis | |
cd $PREFIX/src/ | |
(curl --progress http://download.redis.io/releases/redis-3.0.6.tar.gz | tar xz) && cd redis-3.0.6 | |
PREFIX=$PREFIX make | |
PREFIX=$PREFIX make install | |
mkdir -p $PREFIX/etc | |
mkdir -p $PREFIX/var/log | |
mkdir -p $PREFIX/var/lib/redis | |
mkdir -p $PREFIX/var/run | |
cp redis.conf $PREFIX/etc | |
sed -i -r "s#^port [0-9]{4}\$#port 0#" $PREFIX/etc/redis.conf | |
sed -i -r "s#^logfile .+\$#logfile $PREFIX/var/log/redis.log#" $PREFIX/etc/redis.conf | |
sed -i -r "s#^dir .+\$#dir $PREFIX/var/lib/redis#" $PREFIX/etc/redis.conf | |
sed -i -r "s#^pidfile .+\$#pidfile $PREFIX/var/run/redis.pid#" $PREFIX/etc/redis.conf | |
echo " | |
unixsocket $REDIS_SOCKET | |
unixsocketperm 0777 | |
" >> $PREFIX/etc/redis.conf | |
redis-server $PREFIX/etc/redis.conf & # to start redis server | |
# ------------------------------------------------------------------- | |
# install gitlab-shell | |
cd $GITLAB_HOME | |
(curl --progress https://github.com/gitlabhq/gitlab-shell/archive/v$GITLAB_SHELL_VERSION.tar.gz | exec_as_git tar zx) | |
mv gitlab-shell-$GITLAB_SHELL_VERSION gitlab-shell | |
cd $GITLAB_SHELL_INSTALL_DIR | |
exec_as_git cp config.yml.example config.yml | |
exec_as_git sed -i -r " | |
s#/home/git#$GITLAB_HOME#; | |
s#/var/run/redis/redis\.sock#$REDIS_SOCKET#; | |
s#/usr/bin/redis-cli#$(which redis-cli)#; | |
" config.yml | |
exec_as_git $GITLAB_SHELL_INSTALL_DIR/bin/install | |
# ------------------------------------------------------------------- | |
# install gitlab-workhorse | |
cd $GITLAB_HOME | |
curl --progress https://gitlab.com/gitlab-org/gitlab-workhorse/repository/archive.tar.gz?ref=$GITLAB_WORKHORSE_VERSION | exec_as_git tar zx | |
find -type d -name gitlab-workhorse-$GITLAB_WORKHORSE_VERSION-* -exec mv {} gitlab-workhorse \; | |
cd $GITLAB_WORKHORSE_INSTALL_DIR | |
exec_as_git make | |
# ------------------------------------------------------------------- | |
# install gitlab | |
cd $GITLAB_HOME | |
curl --progress https://gitlab.com/gitlab-org/gitlab-ce/repository/archive.tar.gz?ref=v$GITLAB_VERSION | exec_as_git tar zx | |
find -type d -name gitlab-ce-v$GITLAB_VERSION-* -exec mv {} $GITLAB_INSTALL_DIR \; | |
cd $GITLAB_INSTALL_DIR | |
exec_as_git git config --global user.name "GitLab" | |
exec_as_git git config --global user.email "example@example.com" | |
exec_as_git git config --global core.autocrlf input | |
# remove HSTS config from the default headers, we configure it in nginx | |
exec_as_git sed -i "/headers\['Strict-Transport-Security'\]/d" ${GITLAB_INSTALL_DIR}/app/controllers/application_controller.rb | |
exec_as_git bundle config build.charlock_holmes --with-icu-include=$PREFIX/include --with-icu-lib=$PREFIX/lib | |
exec_as_git bundle config build.rugged --use-system-libraries --with-git2-dir=$PREFIX | |
exec_as_git bundle install -j$NCORE --deployment --without development test aws mysql | |
exec_as_git cp config/gitlab.yml.example config/gitlab.yml | |
exec_as_git cp config/database.yml.postgresql config/database.yml | |
exec_as_git cp config/resque.yml.example config/resque.yml | |
exec_as_git cp config/unicorn.rb.example config/unicorn.rb | |
exec_as_git sed -i -r " | |
s#/home/git#$GITLAB_HOME#; | |
s#bin_path: /usr/bin/git#bin_path: $(which git)#; | |
" config/gitlab.yml | |
exec_as_git sed -i -r " | |
s#\# username: git#username: git#; | |
s#\# password:#password:#; | |
s#\# host: localhost#host: $POSTGRES_SOCKET_DIR#; | |
" config/database.yml | |
exec_as_git sed -i -r "s#production: unix:/var/run/redis/redis\.sock#production: unix:$REDIS_SOCKET#" config/resque.yml | |
exec_as_git sed -i -r " | |
s#/home/git#$GITLAB_HOME#; | |
s#worker_processes 3#worker_processes $NCORE#; | |
" config/unicorn.rb | |
exec_as_git bundle exec rake gitlab:setup | |
exec_as_git bundle exec rake assets:clean assets:precompile | |
exec_as_git mkdir -m 750 public/uploads | |
chmod -R ug+rwX,o-rwx $GITLAB_HOME/repositories/ | |
chmod -R ug-s $GITLAB_HOME/repositories/ | |
find $GITLAB_HOME/repositories/ -type d -print0 | xargs -0 chmod g+s | |
exec_as_git ./bin/web start | |
exec_as_git ./bin/background_jobs start | |
# init script https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment