1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gitlab_ynh.git synced 2024-09-03 18:36:35 +02:00
gitlab_ynh/upgrade-versions.sh

139 lines
6 KiB
Bash
Executable file

#!/bin/bash
# /!\ This is a quick and dirty bash script, which does not respect the YNH format.
# This script will upgrade sha256sum, manifest, readme and config template
# /!\ before committing the modifications, check if nothing is broken if files
# Usage: ./upgrade-versions.sh path_to_upgrade_file version
# Example: ./upgrade-versions.sh scripts/upgrade.d/upgrade.last.sh 13.3.1
file=$(basename $1)
version=$2
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
gitlab_directory="$( cd "$( dirname "$current_dir/$1" )/../../" >/dev/null 2>&1 && pwd )"
sed -i -e "s/gitlab_version=\"[^0-9.]*[0-9.]*[0-9.]\"/gitlab_version=\"$version\"/" $gitlab_directory/scripts/upgrade.d/$file
# x86_64
url=https://packages.gitlab.com/gitlab/gitlab-ce/packages/debian/buster/gitlab-ce_$version-ce.0_amd64.deb
new_sha256=$(curl -s $url | sed -n '/SHA256$/,/<\/tr>$/{ /SHA256$/d; /<\/tr>$/d; p; }' | cut -d$'\n' -f3 | xargs)
echo url: $url
echo sha256: $new_sha256
sed -i -e "s/gitlab_x86_64_buster_source_sha256=\".*\"/gitlab_x86_64_buster_source_sha256=\"$new_sha256\"/" $gitlab_directory/scripts/upgrade.d/$file
# arm64
url=https://packages.gitlab.com/gitlab/gitlab-ce/packages/debian/buster/gitlab-ce_$version-ce.0_arm64.deb
new_sha256=$(curl -s $url | sed -n '/SHA256$/,/<\/tr>$/{ /SHA256$/d; /<\/tr>$/d; p; }' | cut -d$'\n' -f3 | xargs)
echo url: $url
echo sha256: $new_sha256
sed -i -e "s/gitlab_arm64_buster_source_sha256=\".*\"/gitlab_arm64_buster_source_sha256=\"$new_sha256\"/" $gitlab_directory/scripts/upgrade.d/$file
# arm
url=https://packages.gitlab.com/gitlab/raspberry-pi2/packages/raspbian/buster/gitlab-ce_$version-ce.0_armhf.deb
new_sha256=$(curl -s $url | sed -n '/SHA256$/,/<\/tr>$/{ /SHA256$/d; /<\/tr>$/d; p; }' | cut -d$'\n' -f3 | xargs)
echo url: $url
echo sha256: $new_sha256
sed -i -e "s/gitlab_arm_buster_source_sha256=\".*\"/gitlab_arm_buster_source_sha256=\"$new_sha256\"/" $gitlab_directory/scripts/upgrade.d/$file
if [[ "$(basename $file)" == upgrade.last.sh ]]; then
# Update manifest
sed -i -e "s/\"version\": \"[^0-9.]*[0-9.]*[0-9.]~ynh[0-9.]\"/\"version\": \"$version~ynh1\"/" $gitlab_directory/manifest.json
# Don't, it's autogenerated now
## Update readme
#sed -i -e "s/\*\*Shipped version:\*\* [^0-9.]*[0-9.]*[0-9.]/**Shipped version:** $version/" $gitlab_directory/README.md
#sed -i -e "s/\*\*Version incluse :\*\* [^0-9.]*[0-9.]*[0-9.]/**Version incluse :** $version/" $gitlab_directory/README_fr.md
# Update gitlab.rb
conf_file=$gitlab_directory/conf/gitlab.rb
url=https://gitlab.com/gitlab-org/omnibus-gitlab/-/raw/$version+ce.0/files/gitlab-config-template/gitlab.rb.template
header="################################################################################
################################################################################
## FOR YUNOHOST USERS ##
################################################################################
################################################################################
# Please do not modify this file, it will be reset with the next update.
# You can create or modify the file:
# /etc/gitlab/gitlab-persistent.rb
# and add all the configuration you want.
# Options you add in gitlab-presistent.rb will overide these one,
# but you can use options and documentations in this file to know what
# is it possible to do.
################################################################################
################################################################################
"
footer="
from_file '/etc/gitlab/gitlab-persistent.rb'"
echo "$header" > $conf_file
curl -s "$url" >> $conf_file
echo "$footer" >> $conf_file
# Change external url
sed -i "s/external_url 'GENERATED_EXTERNAL_URL'/external_url '__GENERATED_EXTERNAL_URL__'/" $conf_file
# Activate ldap
sed -i "s/# gitlab_rails\['ldap_enabled'\] = .*/gitlab_rails['ldap_enabled'] = true/" $conf_file
ldap_conf="
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS' # remember to close this block with 'EOS' below
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: 'YunoHost LDAP'
host: 'localhost'
port: 389
uid: 'uid'
encryption: 'plain' # 'start_tls' or 'simple_tls' or 'plain'
bind_dn: 'ou=users,dc=yunohost,dc=org'
password: ''
active_directory: false
allow_username_or_email_login: false
block_auto_created_users: false
base: 'dc=yunohost,dc=org'
user_filter: '(&(objectClass=posixAccount)(permission=cn=gitlab.main,ou=permission,dc=yunohost,dc=org))'
timeout: 10
attributes: {
username: ['uid', 'sAMAccountName'],
name: 'cn',
first_name: 'givenName',
last_name: 'sn'
}
EOS"
# Add ldap conf
sed -i "/^# EOS/r "<(echo "$ldap_conf") $conf_file
# Change ssh port
sed -i "s/# gitlab_rails\['gitlab_shell_ssh_port'\] = 22/gitlab_rails['gitlab_shell_ssh_port'] = __SSH_PORT__/" $conf_file
# Change puma settings
sed -i "s/# puma\['worker_processes'\] = .*/puma['worker_processes'] = __PUMA_WORKER_PROCESSES__/" $conf_file
sed -i "s/# puma\['min_threads'\] = .*/puma['min_threads'] = __PUMA_MIN_THREADS__/" $conf_file
sed -i "s/# puma\['max_threads'\] = .*/puma['max_threads'] = __PUMA_MAX_THREADS__/" $conf_file
sed -i "s/# puma\['port'\] = .*/puma['port'] = __PUMA_PORT__/" $conf_file
# Change sidekiq settings
sed -i "s/# sidekiq\['listen_port'\] = .*/sidekiq['listen_port'] = __SIDEKIQ_PORT__/" $conf_file
# Change nginx settings
sed -i "s/# nginx\['client_max_body_size'\] = .*/nginx['client_max_body_size'] = '__CLIENT_MAX_BODY_SIZE__'/" $conf_file
sed -i "s/# nginx\['listen_port'\] = .*/nginx['listen_port'] = __PORT__/" $conf_file
sed -i "s/# nginx\['listen_https'\] = .*/nginx['listen_https'] = false/" $conf_file
# Change modify kernel parameters settings
sed -i "s/# package\['modify_kernel_parameters'\] = .*/package['modify_kernel_parameters'] = __MODIFY_KERNEL_PARAMETERS__/" $conf_file
fi