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

144 lines
5.9 KiB
Bash
Raw Normal View History

#!/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
file=$(basename $1)
2023-06-30 10:48:19 +02:00
debian_versions=("buster" "bullseye" "bookworm")
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
2021-12-23 16:59:08 +01:00
for debian_version in "${debian_versions[@]}"
do
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
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-12-23 16:59:08 +01:00
echo url: $url
echo sha256: $new_sha256
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
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
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-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
if [[ "$(basename $file)" == upgrade.last.sh ]]; then
# Update manifest
2023-08-25 11:45:48 +02:00
sed -i -e "s/version = \"[^0-9.]*[0-9.]*[0-9.]~ynh[0-9.]\"/version = \"$version~ynh1\"/" $gitlab_directory/manifest.toml
# 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))'
2021-01-19 01:59:31 +01:00
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
2023-03-04 23:12:11 +01:00
sed -i "s/# puma\['port'\] = .*/puma['port'] = __PORT_PUMA__/" $conf_file
# Change sidekiq settings
2023-03-04 23:12:11 +01:00
sed -i "s/# sidekiq\['listen_port'\] = .*/sidekiq['listen_port'] = __PORT_SIDEKIQ__/" $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