2014-07-02 17:54:53 +05:30

152 lines
4.7 KiB
Bash
Executable File

#!/bin/bash
set -e
GITLAB_VERSION=7.0.0
SHELL_VERSION=1.9.6
# remove the host keys generated during openssh-server installation
rm -rf /etc/ssh/ssh_host_*_key /etc/ssh/ssh_host_*_key.pub
# add git user
adduser --disabled-login --gecos 'GitLab' git
passwd -d git
rm -rf /home/git/.ssh
sudo -u git -H mkdir -p /home/git/data/.ssh
sudo -u git -H ln -s /home/git/data/.ssh /home/git/.ssh
# create the data store
sudo -u git -H mkdir -p /home/git/data
# install gitlab-shell, use local copy if available
sudo -u git -H mkdir -p /home/git/gitlab-shell
if [ -f /app/setup/gitlab-shell-${SHELL_VERSION}.tar.gz ]; then
sudo -u git -H tar -zvxf /app/setup/gitlab-shell-${SHELL_VERSION}.tar.gz --strip=1 -C /home/git/gitlab-shell/
else
wget "https://github.com/gitlabhq/gitlab-shell/archive/v${SHELL_VERSION}.tar.gz" -O - | tar -zvxf - --strip=1 -C /home/git/gitlab-shell/
chown -R git:git /home/git/gitlab-shell/
fi
cd /home/git/gitlab-shell
sudo -u git -H cp -a config.yml.example config.yml
sudo -u git -H ./bin/install
# install gitlab, use local copy if available
sudo -u git -H mkdir -p /home/git/gitlab
if [ -f /app/setup/gitlabhq-${GITLAB_VERSION}.tar.gz ]; then
sudo -u git -H tar -zvxf /app/setup/gitlabhq-${GITLAB_VERSION}.tar.gz --strip=1 -C /home/git/gitlab/
else
wget "https://github.com/gitlabhq/gitlabhq/archive/v${GITLAB_VERSION}.tar.gz" -O - | tar -zvxf - --strip=1 -C /home/git/gitlab/
chown -R git:git /home/git/gitlab/
fi
cd /home/git/gitlab
# copy default configurations
cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
sudo -u git -H cp config/resque.yml.example config/resque.yml
sudo -u git -H cp config/database.yml.mysql config/database.yml
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u git -H cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb
# create required tmp and log directories
sudo -u git -H mkdir -p tmp/pids/ tmp/sockets/
chmod -R u+rwX log tmp
# create symlink to assets in tmp/cache
rm -rf tmp/cache
sudo -u git -H ln -s /home/git/data/tmp/cache tmp/cache
# create symlink to assets in public/assets
rm -rf public/assets
sudo -u git -H ln -s /home/git/data/tmp/public/assets public/assets
# create symlink to uploads directory
rm -rf public/uploads
sudo -u git -H ln -s /home/git/data/uploads public/uploads
# create production log
sudo -u git -H touch log/production.log
# install gems required by gitlab, use local cache if available
if [ -d "/app/setup/cache" ]; then
mv /app/setup/cache vendor/
chown -R git:git vendor/cache
fi
sudo -u git -H bundle install --deployment --without development test aws
# make sure everything in /home/git is owned by the git user
chown -R git:git /home/git/
# install gitlab bootscript
cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
# install logrotate configuration
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
# disable default nginx configuration and enable gitlab's nginx configuration
rm -f /etc/nginx/sites-enabled/default
ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
# silence setlocale message (#93)
cat > /etc/default/locale <<EOF
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
EOF
# configure supervisor to start sshd
mkdir -p /var/run/sshd
cat > /etc/supervisor/conf.d/sshd.conf <<EOF
[program:sshd]
directory=/
command=/usr/sbin/sshd -D
user=root
autostart=false
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s_error.log
EOF
# configure supervisord to start nginx
echo "daemon off;" >> /etc/nginx/nginx.conf
cat > /etc/supervisor/conf.d/nginx.conf <<EOF
[program:nginx]
priority=20
directory=/tmp
command=/usr/sbin/nginx
user=root
autostart=false
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
EOF
# configure supervisord to start mysql (manual)
cat > /etc/supervisor/conf.d/mysqld.conf <<EOF
[program:mysqld]
priority=20
directory=/tmp
command=/usr/bin/mysqld_safe
user=root
autostart=false
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
EOF
# configure supervisord to start redis (manual)
sed 's/daemonize yes/daemonize no/' -i /etc/redis/redis.conf
cat > /etc/supervisor/conf.d/redis-server.conf <<EOF
[program:redis-server]
priority=20
directory=/tmp
command=/usr/bin/redis-server /etc/redis/redis.conf
user=redis
autostart=false
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
EOF