GioMac

gitlab rpm script

Apr 19th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.24 KB | None | 0 0
  1. preinstall scriptlet (using /bin/sh):
  2. #!/bin/sh
  3. # GitLab pre-install script
  4.  
  5. DEST_DIR=/opt/gitlab
  6.  
  7. mkdir -p /var/log/gitlab/reconfigure
  8.  
  9. skip_migrations_file=/etc/gitlab/skip-auto-migrations
  10.  
  11. main() {
  12.   if [ -e "${skip_migrations_file}" ] ; then
  13.     # The user wants us to do nothing
  14.     return
  15.   fi
  16.  
  17.   if [ -d ${DEST_DIR}/service/unicorn ] ; then
  18.     notify "Automatically backing up only the GitLab SQL database (excluding everything else!)"
  19.     if ! ${DEST_DIR}/bin/gitlab-rake gitlab:backup:create SKIP=repositories,uploads,builds,artifacts,lfs ; then
  20.       notify
  21.       notify "Backup failed! If you want to skip this backup, run the following command and"
  22.       notify "try again:"
  23.       notify
  24.       notify "  sudo touch ${skip_migrations_file}"
  25.       notify
  26.       exit 1
  27.     fi
  28.   fi
  29. }
  30.  
  31. notify() {
  32.   echo "gitlab preinstall: $1"
  33. }
  34.  
  35. if [ -n "${GITLAB_DEBUG}" ] ; then
  36.   notify "debug: arguments: $@"
  37. fi
  38.  
  39. case "$1" in
  40.   2)
  41.     # Looks like an RPM upgrade
  42.     main
  43.     ;;
  44.   upgrade)
  45.     # Looks like a DEB upgrade
  46.     main
  47.     ;;
  48.   *)
  49.     # This is not an upgrade, nothing to do.
  50.     ;;
  51. esac
  52. postinstall scriptlet (using /bin/sh):
  53. #!/bin/sh
  54. #
  55. # Perform necessary gitlab setup steps
  56. # after package is installed.
  57. #
  58. DEST_DIR=/opt/gitlab
  59. EXTERNAL_URL="http://gitlab.example.com"
  60.  
  61. notify()
  62. {
  63.   echo "gitlab: $1"
  64. }
  65.  
  66. create_config_template()
  67. {
  68.   # Create a minimal gitlab.rb template if /etc/gitlab/gitlab.rb does not exist.
  69.   if ! [ -e /etc/gitlab/gitlab.rb ] ; then
  70.     mkdir -p /etc/gitlab
  71.     cp "${DEST_DIR}/etc/gitlab.rb.template" /etc/gitlab/gitlab.rb
  72.     sed -i 's!GENERATED_EXTERNAL_URL!'$EXTERNAL_URL'!g' /etc/gitlab/gitlab.rb
  73.     chmod 600 /etc/gitlab/gitlab.rb
  74.   else
  75.     EXTERNAL_URL=$(awk '/^external_url/ { print $2 }' /etc/gitlab/gitlab.rb | tr -d "'\"")
  76.   fi
  77. }
  78.  
  79. fix_directory_permissions()
  80. {
  81.   if [ -x /usr/bin/dpkg-query ] ; then
  82.     # We are in the land of .deb packages. We should fix package directory owners
  83.     # because of the faulty 7.2.0 / 7.2.1 .deb packages.
  84.     /usr/bin/dpkg-query -L gitlab-ce gitlab-ee 2>/dev/null | while read f ; do
  85.     if [ -d "$f" ] ; then
  86.       # This directory may have been created when installing omnibus-gitlab
  87.       # 7.2.0 / 7.2.1, so it could have the wrong owner.
  88.       chown root:root "$f"
  89.     fi
  90.   done
  91. fi
  92. }
  93.  
  94. print_welcome()
  95. {
  96.   notify "Thank you for installing GitLab!"
  97.   notify "To configure and start GitLab, RUN THE FOLLOWING COMMAND:"
  98.   echo ""
  99.   echo "sudo gitlab-ctl reconfigure"
  100.   echo ""
  101.   notify "GitLab should be reachable at ${EXTERNAL_URL}"
  102.   notify "Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file"
  103.   notify "And running reconfigure again."
  104.   notify
  105.   notify "For a comprehensive list of configuration options please see the Omnibus GitLab readme"
  106.   notify "https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md"
  107.   notify
  108. }
  109.  
  110. check_if_ec2()
  111. {
  112.   if [ -f /sys/hypervisor/uuid ] && [ `head -c 3 /sys/hypervisor/uuid` = 'ec2' ]; then
  113.     return 0
  114.   else
  115.     return 1
  116.   fi
  117. }
  118.  
  119. get_fqdn_from_hostname()
  120. {
  121.   # Try collecting fqdn if it is set correctly
  122.   fqdn=$(/bin/hostname -f)
  123.   if [ -n "${fqdn}" ]; then
  124.     EXTERNAL_URL="http://${fqdn}"
  125.   fi
  126. }
  127.  
  128. get_ec2_hostname()
  129. {
  130.   # Try collecting fqdn if it is set correctly
  131.   fqdn=$(/opt/gitlab/embedded/bin/curl -s http://169.254.169.254/latest/meta-data/public-hostname)
  132.   if [ -n "${fqdn}" ]; then
  133.     EXTERNAL_URL="http://${fqdn}"
  134.   fi
  135. }
  136.  
  137. if [ -n "${GITLAB_DEBUG}" ] ; then
  138.   notify "debug: arguments: $@"
  139. fi
  140.  
  141. check_if_ec2
  142. if [ $? -eq 0 ]  ; then
  143.   get_ec2_hostname
  144. else
  145.   get_fqdn_from_hostname
  146. fi
  147.  
  148. ${DEST_DIR}/embedded/bin/symlink_ctl_cmds ${DEST_DIR}
  149. create_config_template
  150. fix_directory_permissions
  151. print_welcome
  152.  
  153. case "$1" in
  154.   configure)
  155.     # Looks like a DEB install. We don't know if it is a fresh install or an
  156.     # upgrade.
  157.     ${DEST_DIR}/bin/gitlab-ctl upgrade
  158.     ;;
  159.   *)
  160.     # No op.
  161.     ;;
  162. esac
  163. postuninstall scriptlet (using /bin/sh):
  164. #!/bin/sh
  165. # WARNING: REQUIRES /bin/sh
  166. #
  167. # - must run on /bin/sh on solaris 9
  168. # - must run on /bin/sh on AIX 6.x
  169. # - if you think you are a bash wizard, you probably do not understand
  170. #   this programming language.  do not touch.
  171. # - if you are under 40, get peer review from your elders.
  172.  
  173. is_smartos() {
  174.   uname -v | grep "^joyent" 2>&1 >/dev/null
  175. }
  176.  
  177. if is_smartos; then
  178.     PREFIX="/opt/local"
  179. else
  180.     PREFIX="/usr"
  181. fi
  182.  
  183. cleanup_symlinks() {
  184.   binaries="gitlab-ctl gitlab-rake gitlab-rails gitlab-ci-rake gitlab-ci-rails"
  185.   for binary in $binaries; do
  186.     rm -f $PREFIX/bin/$binary
  187.   done
  188. }
  189.  
  190. # Clean up binary symlinks if they exist
  191. # see: http://tickets.opscode.com/browse/CHEF-3022
  192. if [ ! -f /etc/redhat-release -a ! -f /etc/fedora-release -a ! -f /etc/system-release ]; then
  193.   # not a redhat-ish RPM-based system
  194.   cleanup_symlinks
  195. elif [ "x$1" = "x0" ]; then
  196.   # RPM-based system and we're deinstalling rather than upgrading
  197.   cleanup_symlinks
  198. fi
  199. posttrans scriptlet (using /bin/sh):
  200. #!/bin/sh
  201. # GitLab post-transition script
  202. # RPM only
  203. DEST_DIR=/opt/gitlab
  204.  
  205. case "$1" in
  206.   0)
  207.     # RPM install/upgrade
  208.     ${DEST_DIR}/embedded/bin/symlink_ctl_cmds ${DEST_DIR}
  209.     ${DEST_DIR}/bin/gitlab-ctl upgrade
  210.     ;;
  211.   *)
  212.     # Noop.
  213.     ;;
  214. esac
Advertisement
Add Comment
Please, Sign In to add comment