Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Install GitLab 5.0 on Archlinux
#!/bin/bash
##########################
## Check if run as root ##
##########################
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
######################################################################
## Before running this script, make sure to fill in these variables ##
######################################################################
# Enable or disable ruby docs installation
RUBY_DOCS_ENABLED=False
# mysql or postgresql
DB=mysql
# database name
DB_NAME=gitlabhq_production
DB_ROOT_PASSWD=
DB_GITLAB_PASSWD=
DB_GITLAB_USERNAME=
# Set branch to pull from
BRANCH=master
# Fully-qualified domain name
FQDN=
##############################
## 1. Install prerequisites ##
##############################
pacman -Syu --noconfirm --needed sudo base-devel zlib libyaml openssl gdbm readline ncurses libffi curl git openssh redis postfix libxml2 libxslt icu python2 ruby
## Add ruby exec to PATH
echo "export PATH=/root/.gem/ruby/1.9.1/bin:$PATH" >> /root/.bash_profile
source /root/.bashrc
#####################################
## 3. Create a git user for Gitlab ##
#####################################
useradd --create-home --comment 'GitLab' git
#####################
## 3. GitLab shell ##
#####################
# Login as git
su - git
# Clone gitlab shell
git clone https://github.com/gitlabhq/gitlab-shell.git
# Setup
cd gitlab-shell
cp config.yml.example config.yml
# Change "localhost" to the fully-qualified domain name
sed -i "s/localhost/$FQDN/g" config.yml
./bin/install
exit
#################################################################
## 3 Install and configure GitLab. Check status configuration. ##
#################################################################
cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab/
# Checkout to stable release
sudo -u git -H git checkout $BRANCH
# Copy the example GitLab config
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
# Change "localhost" to the fully-qualified domain name
sed -i "s/localhost/$FQDN/g" config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/
# Create directory for satellites
sudo -u git -H mkdir /home/git/gitlab-satellites
# Create directories for sockets/pids and make sure GitLab can write to them
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
# Create public/uploads directory otherwise backup will fail
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX public/uploads
# Copy the example Puma config
sudo -u git -H cp config/puma.rb.example config/puma.rb
# Configure Git global settings for git user, useful when editing via web
# Edit user.email according to what is set in gitlab.yml
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
# Start redis server
systemctl enable redis
systemctl start redis
## Configure GitLab DB settings / Install Gems
if [ RUBY_DOCS_ENABLED -eq False ]; then
echo "gem: --no-rdoc --no-ri" >> /home/git/.gemrc
fi
gem install charlock_holmes --version '0.6.9.4'
if [[ $DB -eq 'mysql' ]]; then
pacman -S --needed --noconfirm mysql
sudo -u git cp config/database.yml.mysql config/database.yml
sed -i "s/gitlabhq_production/$DB_NAME/" config/database.yml
sed -i "s/root/$DB_GITLAB_USERNAME/" config/database.yml
sed -i "s/secure password/$DB_GITLAB_PASSWD/" config/database.yml
sudo -u git -H bundle install --deployment --without development test postgres
elif [[ $DB -eq 'postgresql' ]]; then
pacman -S --needed --noconfirm postgresql
sudo -u git cp config/database.yml.postgresql config/database.yml
sed -i "s/gitlabhq_production/$DB_NAME/" config/database.yml
sed -i "s/gitlab/$DB_GITLAB_USERNAME/" config/database.yml
sed -i 's/password:/password: $DB_GITLAB_PASSWD/' config/database.yml
sudo -u git -H bundle install --deployment --without development test mysql
fi
## Initialise Database and Activate Advanced Features
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
## Check Application Status
# Check if GitLab and its environment are configured correctly
# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
# To make sure you didn't miss anything run a more thorough check with
# sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
# 7. Nginx
## Installation
pacman -S nginx
# Download an example site config
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
# Edit the config file to match your setup
sed -i "s/YOUR_SERVER_IP:80/80/" /etc/nginx/sites-available/gitlab
sed -i "s/YOUR_SERVER_FQDN/$FQDN/" /etc/nginx/sites-available/gitlab
# Restart and enable on boot
systemctl restart nginx
systemctl enable nginx
echo "Done!"
echo "Visit $FQDN for your first GitLab login."
echo "The setup has created an admin account for you."
echo "Please go over to your profile page and immediately change the password."
echo "##################################"
echo "## Email.....: admin@local.host ##"
echo "## Password..: 5iveL!fe ##"
ehco "##################################"
Debian Archlinux Repository
--------------------------------------------------
sudo sudo core
build-essential base-devel core
zlib1g-dev zlib core
libyaml-dev libyaml community
libssl-dev openssl core
libgdbm-dev gdbm core
libreadline-dev readline core
libncurses5-dev ncurses core
libffi-dev libffi core
curl curl core
git-core git extra
openssh-server openssh core
redis-server redis community
postfix postfix extra
checkinstall checkinstall community
libxml2-dev libxml2 extra
libxslt-dev libxslt extra
libcurl4-openssl-dev curl core
libicu-dev icu extra
python python2 extra
# https://github.com/gitlabhq/gitlab-recipes/issues/14#issuecomment-9997442
#
# GITLAB
# Maintainer: @axilleas
# App Version: 5.0
#
[Unit]
Description=Self Hosted Git Management
Requires=mysql.service redis.service
After=mysql.service redis.service
Wants=postfix.service sidekiq.service
[Service]
Type=forking
User=git
WorkingDirectory=/home/git/gitlab
ExecStart=/home/git/gitlab/script/rails server -d -e production
PIDFile=/home/git/gitlab/tmp/pids/server.pid
[Install]
WantedBy=multi-user.target
# https://github.com/davispuh/gitlab-recipes/blob/0704f62d31573d9d3b4d2e1417e464e29d8c0d1b/systemd/sidekiq.service
#
# GITLAB
# Maintainer: @davispuh
# App Version: 5.0
#
[Unit]
Description=GitLab Sidekiq Service
After=syslog.target network.target remote-fs.target nss-lookup.target redis.service
Wants=redis.service
[Service]
Type=simple
PIDFile=/home/git/gitlab/tmp/pids/sidekiq.pid
User=git
WorkingDirectory=/home/git/gitlab/
ExecStart=/bin/su - git -c "bundle exec rake sidekiq:start RAILS_ENV=production"
ExecStop=/bin/su - git -c "bundle exec rake sidekiq:stop RAILS_ENV=production"
[Install]
WantedBy=multi-user.target
NARKOZ commented Sep 8, 2012

Hi, could you make a pull request with this to https://github.com/gitlabhq/gitlab-recipes? I think it would be useful for people and you can get credit for helping out. Thanks!

Owner
axilleas commented Oct 1, 2012

I just saw your comment... There are a couple of things changed since the last time I wrote this, so it must be rewritten at some points. I'll look into it during this week, thanks!

what's the current state? I've checked https://github.com/gitlabhq/gitlab-recipes, it looks like have not been merged.

Owner

I haven't sent a pull request yet as this is quite outdated. I will edit it to match the master branch (the upcoming 5.0 release which is scheduled on March 22nd).

why ruby things is installed in root directory? maybe we can install them into /home/git.

the nginx script link become invalid, and can you add some info for apache

Owner
axilleas commented Jul 5, 2013

Updated. Although I don't know if anyone is using it. It needs testing and I don't have time right now...

line 194 typo in "echo"
also in line 59, this just leaves the terminal open as the git user and doesn't really issue any commands

still testing ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment