2020-08-27 13:50:05 +02:00
#!/bin/bash
2020-08-27 13:55:16 +02:00
# /!\ 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
2020-08-27 13:50:05 +02:00
file = $( basename $1 )
2021-12-23 16:59:08 +01:00
debian_versions = ( "buster" "bullseye" )
2020-08-27 13:50:05 +02:00
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 ) "
2021-07-08 17:16:07 +02:00
# Only replace the first occurrence
sed -i -e " 0,/gitlab_version=\"[^0-9.]*[0-9.]*[0-9.]\"/s//gitlab_version=\" $version \"/ " $gitlab_directory /scripts/upgrade.d/$file
2020-08-27 13:50:05 +02:00
2021-12-23 16:59:08 +01:00
for debian_version in " ${ debian_versions [@] } "
do
2020-08-27 13:50:05 +02:00
2021-12-23 16:59:08 +01:00
# x86_64
url = https://packages.gitlab.com/gitlab/gitlab-ce/packages/debian/${ debian_version } /gitlab-ce_$version -ce.0_amd64.deb
2020-08-27 13:50:05 +02:00
2021-12-23 16:59:08 +01:00
new_sha256 = $( curl -s $url | sed -n '/SHA256$/,/<\/tr>$/{ /SHA256$/d; /<\/tr>$/d; p; }' | cut -d$'\n' -f3 | xargs)
2020-08-27 13:50:05 +02:00
2021-12-23 16:59:08 +01:00
echo url: $url
echo sha256: $new_sha256
2020-08-27 13:50:05 +02:00
2021-12-23 16:59:08 +01:00
sed -i -e " s/gitlab_x86_64_ ${ debian_version } _source_sha256=\".*\"/gitlab_x86_64_ ${ debian_version } _source_sha256=\" $new_sha256 \"/ " $gitlab_directory /scripts/upgrade.d/$file
2021-03-29 11:46:48 +02:00
2021-12-23 16:59:08 +01:00
# arm64
url = https://packages.gitlab.com/gitlab/gitlab-ce/packages/debian/${ debian_version } /gitlab-ce_$version -ce.0_arm64.deb
2021-03-29 11:46:48 +02:00
2021-12-23 16:59:08 +01:00
new_sha256 = $( curl -s $url | sed -n '/SHA256$/,/<\/tr>$/{ /SHA256$/d; /<\/tr>$/d; p; }' | cut -d$'\n' -f3 | xargs)
2021-03-29 11:46:48 +02:00
2021-12-23 16:59:08 +01:00
echo url: $url
echo sha256: $new_sha256
2021-03-29 11:46:48 +02:00
2021-12-23 16:59:08 +01:00
sed -i -e " s/gitlab_arm64_ ${ debian_version } _source_sha256=\".*\"/gitlab_arm64_ ${ debian_version } _source_sha256=\" $new_sha256 \"/ " $gitlab_directory /scripts/upgrade.d/$file
2020-08-27 13:50:05 +02:00
2021-12-23 16:59:08 +01:00
# arm
url = https://packages.gitlab.com/gitlab/raspberry-pi2/packages/raspbian/${ debian_version } /gitlab-ce_$version -ce.0_armhf.deb
2020-08-27 13:50:05 +02:00
2021-12-23 16:59:08 +01:00
new_sha256 = $( curl -s $url | sed -n '/SHA256$/,/<\/tr>$/{ /SHA256$/d; /<\/tr>$/d; p; }' | cut -d$'\n' -f3 | xargs)
2020-08-27 13:50:05 +02:00
2021-12-23 16:59:08 +01:00
echo url: $url
echo sha256: $new_sha256
2023-03-30 10:41:18 +02:00
sed -i -e " s/gitlab_arm_ ${ debian_version } _source_sha256=\".*\"/gitlab_arm_ ${ debian_version } _source_sha256=\" $new_sha256 \"/ " $gitlab_directory /scripts/upgrade.d/$file
2021-12-23 16:59:08 +01:00
done
2021-07-08 17:16:07 +02:00
2020-08-27 13:50:05 +02:00
if [ [ " $( basename $file ) " = = upgrade.last.sh ] ] ; then
# Update manifest
2020-09-08 14:13:01 +02:00
sed -i -e " s/\"version\": \"[^0-9.]*[0-9.]*[0-9.]~ynh[0-9.]\"/\"version\": \" $version ~ynh1\"/ " $gitlab_directory /manifest.json
2020-08-27 13:50:05 +02:00
2021-06-08 17:41:34 +02:00
# 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
2020-08-27 13:50:05 +02:00
# 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
2021-01-19 01:13:42 +01:00
label: 'YunoHost LDAP'
2020-08-27 13:50:05 +02:00
host: 'localhost'
port: 389
uid: 'uid'
2021-01-19 01:13:42 +01:00
encryption: 'plain' # 'start_tls' or 'simple_tls' or 'plain'
bind_dn: 'ou=users,dc=yunohost,dc=org'
2020-08-27 13:50:05 +02:00
password: ''
active_directory: false
allow_username_or_email_login: false
block_auto_created_users: false
2021-01-19 01:13:42 +01:00
base: 'dc=yunohost,dc=org'
user_filter: '(&(objectClass=posixAccount)(permission=cn=gitlab.main,ou=permission,dc=yunohost,dc=org))'
2021-01-19 01:59:31 +01:00
timeout: 10
attributes: {
username: [ 'uid' , 'sAMAccountName' ] ,
name: 'cn' ,
first_name: 'givenName' ,
last_name: 'sn'
}
2020-08-27 13:50:05 +02:00
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
2023-03-04 23:12:11 +01:00
sed -i "s/# puma\['port'\] = .*/puma['port'] = __PORT_PUMA__/" $conf_file
2020-08-27 13:50:05 +02:00
# Change sidekiq settings
2023-03-04 23:12:11 +01:00
sed -i "s/# sidekiq\['listen_port'\] = .*/sidekiq['listen_port'] = __PORT_SIDEKIQ__/" $conf_file
2020-08-27 13:50:05 +02:00
# 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
2021-02-24 15:09:16 +01:00
# Change modify kernel parameters settings
sed -i "s/# package\['modify_kernel_parameters'\] = .*/package['modify_kernel_parameters'] = __MODIFY_KERNEL_PARAMETERS__/" $conf_file
2020-08-27 13:50:05 +02:00
fi