Skip to content

Instantly share code, notes, and snippets.

@Leopere
Last active August 29, 2015 14:09
Show Gist options
  • Save Leopere/4d2ae3b2e47a6a7bb3d4 to your computer and use it in GitHub Desktop.
Save Leopere/4d2ae3b2e47a6a7bb3d4 to your computer and use it in GitHub Desktop.
KwRuby very rough bash script for demo'ing the installation from source process.
#!/bin/bash
## Source for this script was from https://github.com/gitlabhq/gitlabhq/blob/7-4-stable/doc/install/installation.md#initialize-database-and-activate-advanced-features
clear
echo "First step is we need to update our apt cache and install upgrades."
echo "apt-get update -y && apt-get upgrade -y && apt-get autoremove"
apt-get update -y && apt-get upgrade -y && apt-get autoremove
read
## Install required Packages needed for compiling ruby.
clear
echo "Next we need to install dependencies for compiling ruby and extensions "
echo "like Ruby Gems"
echo "sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils pkg-config cmake"
read
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils pkg-config cmake
read
## make sure you have the right version of Git installed
clear
echo "Install a newer version of git-core than 1.7.10"
echo "apt-get install -y git-core"
apt-get install -y git-core
read
echo "run git --version and if this is lower then 1.7.10 compile git from "
echo "source"
git --version
read
## Installing mail so people can get GitLab Spam! *er I mean Notifications!
clear
echo "Hosting mail services is irritating but we still have to send mail in "
echo "these dern webapps."
echo "make sure to select internet site during configuration"
read
echo "run apt-get install -y postfix"
apt-get install -y postfix
read
## Step two compiling the correct Ruby version
echo "RVM, rbenf and chruby is NOT reccomended!"
echo ""
apt-get remove ruby1.8 -y >/dev/null
read
## Download and Compile Ruby
clear
echo "download ruby and compile it."
echo "mkdir /tmp/ruby && cd /tmp/ruby"
read
mkdir /tmp/ruby && cd /tmp/ruby
echo "Use curl to download and extract the ruby tar into our /tmp/ruby dir"
echo "curl -L --progress ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xz"
read
curl -L --progress ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xz
cd ruby-2.1.2
read
clear
echo "configure and make then make install"
echo "./configure --disable-install-rdoc"
./configure --disable-install-rdoc
echo "make"
make
echo "make install"
make install
echo "Done installing ruby"
read
## gem install bundler
clear
echo "Now to gem install bundler --no-ri --no-rdoc"
read
gem install bundler --no-ri --no-rdoc
read
## Creating passwordless users that cant login just for compartmentalization
clear
echo "Creating passwordless users that cant login just for compartmentalization"
echo "adduser --disabled-login --gecos 'GitLab' git"
adduser --disabled-login --gecos 'GitLab' git
read
## Databases!!!
clear
echo "Now we have to run through installing a PostgreSQL server and database"
echo "For this we refer to the web because I don't have time to learn how"
echo "to query posgresql from the CLI for the sake of this script"
echo "http://goo.gl/qrzSFl"
echo "open a new ssh session for this"
read
## Redis
clear
echo "apt-get install redis-server"
apt-get install -y redis-server
echo "Next back up your original redis config"
echo "sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.orig"
read
cp /etc/redis/redis.conf /etc/redis/redis.conf.orig
clear
echo "sed your way to success by running this aweful thing"
echo "sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf"
read
echo "echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf"
echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf
read
echo "activate changes to redis.conf"
echo "service redis-server restart"
service redis-server restart
read
echo "add git to the redis group"
echo "sudo usermod -aG redis git"
usermod -aG redis git
read
## The goods, installing GitLab
clear
echo "Now to actually install GitLab itself! Hurray!"
echo "We will install GitLab into the home directory of the user "git""
read
echo "cd /home/git"
cd /home/git
echo "Clone the GitLab repository"
echo "sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-4-stable gitlab"
read
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-4-stable gitlab
echo "You CAN clone the master branch if you want bleeding edge builds"
echo "bleeding edge can be pretty fine but its not reccomended to install"
echo "into production"
read
## Configuring things.
clear
echo "copy the example config to the correct directory."
echo "cd /home/git/gitlab"
cd /home/git/gitlab
echo "sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml"
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
echo "sudo -u git -H nano config/gitlab.yml"
sudo -u git -H nano config/gitlab.yml
echo "Changing ownerships of log/ and tmp/ to git"
echo "chown -R git log/ tmp/"
chown -R git log/ tmp/
echo "chown -R u+rwX log/ tmp/"
chown -R u+rwX log/ tmp/
read
## creating directory for satellites.
clear
echo "Create directory for satellites"
echo "sudo -u git -H mkdir /home/git/gitlab-satellites"
sudo -u git -H mkdir /home/git/gitlab-satellites
echo "sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites"
sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
read
clear
echo "Make sure gitlab can write to the public/uploads/ directory"
echo "sudo chmod -R u+rwX public/uploads"
sudo chmod -R u+rwX public/uploads
read
clear
echo "Copy the example Unicorn config"
echo "sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb"
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
read
clear
echo "At this point you should consider your usage case and the kind of "
echo "load you expect in your environment."
echo "running nproc to see how many cores are available on this rig"
echo "nproc"
nproc
read
echo "at this point you could use sed -i to replace the config entry in"
echo "config/unicorn.rb, but for this demo I will skip this."
read
clear
echo "copying rack-attack example config."
echo "sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb"
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
read
clear
echo "Configuring git global settings for git user, if you want to edit"
echo "via the web. Edit user.email according to what is set in gitlab.yml"
echo "sudo -u git -H git config --global user.name "GitLab""
sudo -u git -H git config --global user.name "GitLab"
echo "sudo -u git -H git config --global user.email "example@example.com""
sudo -u git -H git config --global user.email "example@example.com"
echo "sudo -u git -H git config --global core.autocrlf input"
read
clear
echo "Change the Redis socket path if you are not using the default Debian"
echo "or ubuntu configuration"
echo "This would ask you to run the following."
echo "sudo -u git -H cp config/resque.yml.example config/resque.yml"
read
clear
echo "Configure GitLab DB Settings"
echo "PostgreSQL only:"
echo "sudo -u git cp config/database.yml.postgresql config/database.yml"
sudo -u git cp config/database.yml.postgresql config/database.yml
read
clear
echo "Install Gems"
echo "as of bundler 1.5.2 you can invoke "bundle install -jN""
echo "where N is the number of processor cores and enjoy parallel gem"
echo "installation with measurable difference in completion time ~60% faster."
echo ""
echo ""
echo "For our install we used PostgreSQL so we will use the following"
echo "sudo -u git -H bundle install --deployment --without development test mysql aws"
sudo -u git -H bundle install --deployment --without development test mysql aws
read
clear
echo "Install GitLab Shell"
echo "Run the installation task for gitlab-shell (replace REDIS_URL if needed):"
echo "sudo -u git -H bundle exec rake gitlab:shell:install[v2.0.1] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production"
sudo -u git -H bundle exec rake gitlab:shell:install[v2.0.1] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
read
clear
echo "Initilaize Database and Activate Advanced Features"
echo "sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production"
echo "Type yes to create the database tables."
echo "When done you see Administrator account created:"
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
read
clear
echo "Install Init Script"
sudo "Download the init script (will be /etc/init.d/gitlab):"
echo "sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab"
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
read
clear
echo "Make GitLab start on boot:"
echo "sudo update-rc.d gitlab defaults 21"
read
clear
echo "Setup Logrotate"
echo "sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab"
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
read
clear
echo "Check Application Status"
echo "Check if GitLab and its environment are configured correctly:"
echo "sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production"
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
read
clear
echo "Compile Assets"
echo "sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production"
read
clear
echo "Start Your GitLab Instance"
echo "sudo service gitlab start"
sudo service gitlab start
read
clear
echo "Nginx"
echo "sudo apt-get install -y nginx"
sudo apt-get install -y nginx
read
clear
echo "Disable any default websites that nginx creates to prevent conflicts"
echo "rm -R /etc/nginx/sites-enabled/"
rm -R /etc/nginx/sites-enabled/
read
clear
echo "Copy the example site config:"
echo "sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab"
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
echo "sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab"
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
read
clear
echo "Make sure to edit the config to match your setup:"
echo "Change YOUR_SERVER_FQDN to the fully-qualified domain name for your GitLab host."
echo "sudo nano /etc/nginx/sites-available/gitlab"
sudo nano /etc/nginx/sites-available/gitlab
sed -i "s/YOUR_SERVER_FQDN/gl.nixc.us/g" /etc/nginx/sites-available/gitlab
read
clear
echo "Test Configuration"
echo "sudo nginx -t"
sudo nginx -t
read
clear
echo "Your new gitlab by restarting nginx."
echo "sudo service nginx restart"
sudo service nginx restart
read
clear
echo "You have managed to endure the whole process congrats!"
echo "You're finished enjoy!"
echo "Celebrate or something, probably just get to committing..."
read
clear
echo "I guess you could probably test the configuration"
echo "sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production"
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
echo "Initial Login will be at your servers IP or domain you defined."
echo "default Username: root"
echo "default Password: 5iveL!fe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment