├── docker └── .gitignore ├── src ├── scripts │ ├── env_ignore │ ├── postupgrade │ ├── preuninst │ ├── preupgrade │ ├── lib │ ├── lang │ │ └── enu │ ├── postuninst │ ├── preinst │ ├── start-stop-status │ ├── ini_val │ ├── gitea-ssl │ ├── postinst │ └── common ├── PACKAGE_ICON.PNG ├── PACKAGE_ICON_256.PNG ├── package │ ├── ui │ │ ├── images │ │ │ ├── Gitea_16.png │ │ │ ├── Gitea_24.png │ │ │ ├── Gitea_256.png │ │ │ ├── Gitea_32.png │ │ │ ├── Gitea_48.png │ │ │ ├── Gitea_64.png │ │ │ └── Gitea_72.png │ │ └── config │ └── config │ │ └── synology_gitea ├── WIZARD_UIFILES │ ├── uninstall_uifile │ ├── ui_common │ └── install_uifile.sh └── INFO ├── .gitignore ├── tools ├── save-docker-image-batch.sh └── save-docker-image.sh ├── .gitattributes ├── .editorconfig ├── LICENSE ├── rebuild-all.sh └── README.md /docker/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /src/scripts/env_ignore: -------------------------------------------------------------------------------- 1 | PATH 2 | USER 3 | GITEA_CUSTOM 4 | GODEBUG 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | .idea 3 | tmp 4 | -------------------------------------------------------------------------------- /tools/save-docker-image-batch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ./save-docker-image.sh --image\="gitea/gitea:1.4" -------------------------------------------------------------------------------- /src/PACKAGE_ICON.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboxberger/synology-gitea-jboxberger/HEAD/src/PACKAGE_ICON.PNG -------------------------------------------------------------------------------- /src/scripts/postupgrade: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2000-2015 Synology Inc. All rights reserved. 3 | 4 | exit 0 5 | -------------------------------------------------------------------------------- /src/scripts/preuninst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2000-2017 Synology Inc. All rights reserved. 3 | 4 | exit 0 5 | -------------------------------------------------------------------------------- /src/PACKAGE_ICON_256.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboxberger/synology-gitea-jboxberger/HEAD/src/PACKAGE_ICON_256.PNG -------------------------------------------------------------------------------- /src/package/ui/images/Gitea_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboxberger/synology-gitea-jboxberger/HEAD/src/package/ui/images/Gitea_16.png -------------------------------------------------------------------------------- /src/package/ui/images/Gitea_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboxberger/synology-gitea-jboxberger/HEAD/src/package/ui/images/Gitea_24.png -------------------------------------------------------------------------------- /src/package/ui/images/Gitea_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboxberger/synology-gitea-jboxberger/HEAD/src/package/ui/images/Gitea_256.png -------------------------------------------------------------------------------- /src/package/ui/images/Gitea_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboxberger/synology-gitea-jboxberger/HEAD/src/package/ui/images/Gitea_32.png -------------------------------------------------------------------------------- /src/package/ui/images/Gitea_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboxberger/synology-gitea-jboxberger/HEAD/src/package/ui/images/Gitea_48.png -------------------------------------------------------------------------------- /src/package/ui/images/Gitea_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboxberger/synology-gitea-jboxberger/HEAD/src/package/ui/images/Gitea_64.png -------------------------------------------------------------------------------- /src/package/ui/images/Gitea_72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jboxberger/synology-gitea-jboxberger/HEAD/src/package/ui/images/Gitea_72.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Default Unix Line Endings for the whole Project 2 | * text eol=lf 3 | 4 | # Windows Files 5 | *.bat text eol=crlf 6 | 7 | # Binary Files 8 | *.spk binary 9 | *.png binary -------------------------------------------------------------------------------- /src/scripts/preupgrade: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2000-2017 Synology Inc. All rights reserved. 3 | 4 | . "$(dirname "$0")"/common 5 | . "$(dirname "$0")"/../WIZARD_UIFILES/ui_common 6 | 7 | BackupCustomEnvironmentVariables 8 | BackupContainerPorts 9 | 10 | exit 0 11 | -------------------------------------------------------------------------------- /src/scripts/lib: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2000-2013 Synology Inc. All rights reserved. 3 | # This file is generated by synopkglib tool, don't modify by hand. 4 | 5 | LANG_FILE="$(dirname "$0")/lang/$SYNOPKG_DSM_LANGUAGE" 6 | if [ -f "${LANG_FILE}" ]; then 7 | . "${LANG_FILE}" 8 | else 9 | . "$(dirname "$0")/lang/default" 10 | fi 11 | -------------------------------------------------------------------------------- /src/WIZARD_UIFILES/uninstall_uifile: -------------------------------------------------------------------------------- 1 | [{ 2 | "step_title": "Remove Gitea data", 3 | "items": [{ 4 | "type": "multiselect", 5 | "desc": "If the Gitea data is removed, all the data will be deleted.", 6 | "subitems": [{ 7 | "key": "pkgwizard_remove_data", 8 | "desc": "Remove Gitea data (git repositories and database)" 9 | }] 10 | }] 11 | }] 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Drupal editor configuration normalization 2 | # @see http://editorconfig.org/ 3 | 4 | # This is the top-most .editorconfig file; do not search in parent directories. 5 | root = true 6 | 7 | # All files. 8 | [*] 9 | end_of_line = LF 10 | indent_style = space 11 | indent_size = 2 12 | charset = utf-8 13 | trim_trailing_whitespace = true 14 | insert_final_newline = true 15 | 16 | [*.json] 17 | indent_size = 4 18 | -------------------------------------------------------------------------------- /src/scripts/lang/enu: -------------------------------------------------------------------------------- 1 | failed_downloading_image="Downloading images, please enable this package later." 2 | failed_illegal_dir_name="The folder name contains illegal characters." 3 | failed_remove_db="Failed to remove the database {0}." 4 | failed_remove_db_user="Failed to remove the database user {0}." 5 | failed_remove_dir="Failed to remove the folder {0}." 6 | warning_all_data_lost="Warning: all data will be deleted after uninstallation." 7 | -------------------------------------------------------------------------------- /src/package/ui/config: -------------------------------------------------------------------------------- 1 | { 2 | ".url": { 3 | "SYNO.SDS.__PKG_NAME__": { 4 | "allUsers": true, 5 | "desc": "Docker Gitea", 6 | "icon": "images/Gitea_{0}.png", 7 | "port": "__HTTP_PORT__", 8 | "protocol": "__HTTP_PROTOCOL__", 9 | "texts": "texts", 10 | "title": "Docker Gitea", 11 | "type": "url", 12 | "url": "/" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/INFO: -------------------------------------------------------------------------------- 1 | package="synology-gitea-jboxberger" 2 | version="1.4" 3 | maintainer="gitea.io" 4 | distributor="Juri Boxberger" 5 | distributor_url="https://github.com/jboxberger/synology-gitea-jboxberger" 6 | arch="x86 avoton bromolow cedarview braswell kvmx64 broadwell apollolake denverton" 7 | firmware="6.0-7300" 8 | support_center="yes" 9 | install_dep_packages="Docker>=1.6.2-0035" 10 | silent_upgrade="yes" 11 | thirdparty="yes" 12 | description="Gitea is a web-based Git repository manager with wiki and issue tracking features." 13 | displayname="Gitea" 14 | extractsize="620549" 15 | toolkit_version="8685" 16 | create_time="20170928-18:41:27" 17 | -------------------------------------------------------------------------------- /src/scripts/postuninst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2000-2015 Synology Inc. All rights reserved. 3 | 4 | . "$(dirname $0)"/common 5 | . "$ETC_PATH"/config 6 | 7 | /usr/syno/bin/synowebapi --exec api=SYNO.Docker.Container version=1 method=delete name="$GITEA_NAME" force=true preserve_profile=false 8 | docker rmi "$GITEA_PACKAGE_NAME":"$GITEA_VERSION" 9 | 10 | if [ "$SYNOPKG_PKG_STATUS" != UPGRADE ] && [ "$pkgwizard_remove_data" = true ]; then 11 | if ! rm -Rf "$SHARE_PATH/$SHARE"; then 12 | logger -p 0 "$PKG_NAME: failed to remove the folder $SHARE" 13 | log "$failed_remove_dir" "$SHARE" 14 | fi 15 | 16 | rm "$ETC_PATH"/config 17 | rm "$ETC_PATH"/config_custom 18 | rm "$ETC_PATH"/config_container_ports 19 | fi 20 | 21 | exit 0 22 | -------------------------------------------------------------------------------- /src/scripts/preinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2000-2015 Synology Inc. All rights reserved. 3 | 4 | [ "$SYNOPKG_PKG_STATUS" = UPGRADE ] && exit 0 5 | 6 | . "$(dirname $0)"/common 7 | 8 | if [ -z "$pkgwizard_dataroot" ]; then 9 | log "$failed_illegal_dir_name" "$pkgwizard_dataroot" 10 | exit 1 11 | fi 12 | 13 | if [ false = "$restore_backup" ]; then 14 | . "$ETC_PATH"/config 15 | if ! rm -Rf "$SHARE_PATH/$SHARE"; then 16 | logger -p 0 "$PKG_NAME: failed to remove the folder $SHARE" 17 | fi 18 | fi 19 | 20 | # check mkdir 21 | dataPath="$SHARE_PATH/$pkgwizard_dataroot" 22 | if ! mkdir -p "$dataPath"; then 23 | log "$failed_illegal_dir_name" "$pkgwizard_dataroot" 24 | exit 1 25 | fi 26 | chmod 755 "$dataPath" 27 | 28 | exit 0 29 | -------------------------------------------------------------------------------- /src/WIZARD_UIFILES/ui_common: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2000-2016 Synology Inc. All rights reserved. 3 | 4 | PKG_NAME="Gitea" 5 | BACKUP_CONFIG="/usr/syno/etc/packages/__PKG_NAME__/config" 6 | 7 | NeedRestore() 8 | { 9 | if [ -f "$BACKUP_CONFIG" ]; then 10 | return 0 11 | else 12 | return 1 13 | fi 14 | } 15 | 16 | GetDBName() 17 | { 18 | get_key_value "$BACKUP_CONFIG" DB_NAME 19 | } 20 | 21 | GetDBUser() 22 | { 23 | #version < "9.4.4-0050" does not store db_user in config 24 | DB_USER=$(get_key_value "$BACKUP_CONFIG" DB_USER) 25 | DB_USER=${DB_USER:-gitea_user} 26 | echo "$DB_USER" 27 | } 28 | 29 | GetDBPass() 30 | { 31 | get_key_value "$BACKUP_CONFIG" DB_PASS 32 | } 33 | 34 | GetShare() 35 | { 36 | get_key_value "$BACKUP_CONFIG" SHARE 37 | } 38 | 39 | GetPkgVer() 40 | { 41 | get_key_value "$BACKUP_CONFIG" PKG_VER 42 | } 43 | -------------------------------------------------------------------------------- /src/package/config/synology_gitea: -------------------------------------------------------------------------------- 1 | { 2 | "cpu_priority": 0, 3 | "enable_publish_all_ports": false, 4 | "env_variables": [], 5 | "image": "__IMAGE__", 6 | "is_package": false, 7 | "links": [], 8 | "memory_limit": 0, 9 | "name": "synology_gitea", 10 | "port_bindings": [ 11 | { 12 | "container_port": "3000", 13 | "host_port": "__HTTP_PORT__", 14 | "type": "tcp" 15 | }, 16 | { 17 | "container_port": 22, 18 | "host_port": "__SSH_PORT__", 19 | "type": "tcp" 20 | } 21 | ], 22 | "privileged": false, 23 | "shortcut": { 24 | "enable_shortcut": false, 25 | "enable_status_page": false, 26 | "enable_web_page": false, 27 | "web_page_url": "" 28 | }, 29 | "volume_bindings": [ 30 | { 31 | "host_volume_file": "/docker/__SHARE__", 32 | "mount_point": "/data", 33 | "type": "rw" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /src/scripts/start-stop-status: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2000-2015 Synology Inc. All rights reserved. 3 | 4 | . "$(dirname $0)"/common 5 | UI_PATH="/usr/syno/synoman/webman/3rdparty/$PKG_NAME" 6 | 7 | case "$1" in 8 | start) 9 | [ -d "$TARGET_PATH"/ui ] && ln -s "$TARGET_PATH"/ui "$UI_PATH" 10 | "$SYNO_WEBAPI" --exec api=SYNO.Docker.Container version=1 method=start name="$GITEA_NAME" && exit 0 11 | exit 1 12 | ;; 13 | 14 | stop) 15 | rm "$UI_PATH" 16 | "$SYNO_WEBAPI" --exec api=SYNO.Docker.Container version=1 method=stop name="$GITEA_NAME" || exit 1 17 | exit 0 18 | ;; 19 | 20 | status) 21 | [ -e "$DOCKER_BIN" ] || exit 1 22 | docker_version=$(synopkg version Docker | cut -d '-' -f 2) 23 | if [ "$docker_version" -le 0344 ]; then 24 | "$DOCKER_BIN" inspect "$GITEA_NAME" | grep -q "\"SynoStatus\": \"running\"," || exit 1 25 | else 26 | "$DOCKER_BIN" inspect "$GITEA_NAME" | grep -q "\"Status\": \"running\"," || exit 1 27 | fi 28 | exit 0 29 | ;; 30 | 31 | *) 32 | exit 1 33 | ;; 34 | esac 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Juri Boxberger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rebuild-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | IS_DEBUG="" 3 | 4 | ######################################################################################################################## 5 | # PARAMETER HANDLING 6 | ######################################################################################################################## 7 | for i in "$@" 8 | do 9 | case $i in 10 | --debug) 11 | IS_DEBUG="--debug" 12 | ;; 13 | *) 14 | # unknown option 15 | ;; 16 | esac 17 | shift 18 | done 19 | 20 | spk_version=0101 21 | 22 | gitea_package_name="gitea/gitea" 23 | declare -A versions; declare -a orders; 24 | #versions["1.3"]="34"; orders+=( "1.3" ) 25 | #versions["1.4"]="34"; orders+=( "1.4" ) 26 | #versions["1.4.1"]="34"; orders+=( "1.4.1" ) 27 | #versions["1.4.2"]="34"; orders+=( "1.4.2" ) 28 | #versions["1.5.0"]="37"; orders+=( "1.5.0" ) 29 | #versions["1.5.1"]="37"; orders+=( "1.5.1" ) 30 | #versions["1.6"]="39"; orders+=( "1.6" ) 31 | #versions["1.7"]="42"; orders+=( "1.7" ) 32 | #versions["1.7.1"]="42"; orders+=( "1.7.1" ) 33 | #versions["1.7.3"]="42"; orders+=( "1.7.3" ) 34 | #versions["1.8"]="47"; orders+=( "1.8" ) 35 | #versions["1.8.2"]="47"; orders+=( "1.8.2" ) 36 | #versions["1.9"]="47"; orders+=( "1.9" ) 37 | #versions["1.9.3"]="45"; orders+=( "1.9.3" ) 38 | #versions["1.10.3"]="49"; orders+=( "1.10.3" ) 39 | versions["1.11.1"]="38"; orders+=( "1.11.1" ) 40 | 41 | for i in "${!orders[@]}" 42 | do 43 | gitea_version=${orders[$i]} 44 | gitea_size=${versions[${orders[$i]}]} 45 | gitea_package_fqn=$gitea_package_name:$gitea_version 46 | 47 | 48 | echo "building $gitea_package_fqn ("$gitea_size"MB)" 49 | ./build.sh --gitea-fqn=$gitea_package_fqn --gitea-download-size=$gitea_size \ 50 | --spk-version=$spk_version \ 51 | "$IS_DEBUG" 52 | done 53 | -------------------------------------------------------------------------------- /src/scripts/ini_val: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # BASH3 Boilerplate: ini_val 3 | # 4 | # This file: 5 | # 6 | # - Can read and write .ini files using pure bash 7 | # 8 | # Limitations: 9 | # 10 | # - All keys inside the .ini file must be unique, regardless of the use of sections 11 | # 12 | # Usage as a function: 13 | # 14 | # source ini_val.sh 15 | # ini_val data.ini connection.host 127.0.0.1 16 | # 17 | # Usage as a command: 18 | # 19 | # ini_val.sh data.ini connection.host 127.0.0.1 20 | # 21 | # Based on a template by BASH3 Boilerplate v2.1.0 22 | # http://bash3boilerplate.sh/#authors 23 | # 24 | # The MIT License (MIT) 25 | # Copyright (c) 2013 Kevin van Zonneveld and contributors 26 | # You are not obligated to bundle the LICENSE file with your b3bp projects as long 27 | # as you leave these references intact in the header comments of your source files. 28 | 29 | function ini_val() { 30 | local file="${1:-}" 31 | local sectionkey="${2:-}" 32 | local val="${3:-}" 33 | local delim="=" 34 | local section="" 35 | local key="" 36 | 37 | # Split on . for section. However, section is optional 38 | read section key <<<$(IFS="."; echo ${sectionkey}) 39 | if [ -z "${key}" ]; then 40 | key="${section}" 41 | section="" 42 | fi 43 | 44 | local current=$(awk -F "${delim}" "/^${key}\s*${delim}\s*/ {for (i=2; i> "${file}" 56 | else 57 | # add to section 58 | sed -i.bak -e "/\[${section}\]/a ${key}${delim}${val}" "${file}" 59 | # this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666 60 | rm -f "${file}.bak" 61 | fi 62 | else 63 | # replace existing 64 | sed -i.bak -e "/^${key}\s*${delim}\s*/s/${delim}.*/${delim}${val}/" "${file}" 65 | # this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666 66 | rm -f "${file}.bak" 67 | fi 68 | fi 69 | } 70 | 71 | if [ "${BASH_SOURCE[0]}" != "${0}" ]; then 72 | export -f ini_val 73 | else 74 | ini_val "${@}" 75 | exit ${?} 76 | fi 77 | -------------------------------------------------------------------------------- /tools/save-docker-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # save image from docker to tar.xz file for the AIO package 3 | 4 | ######################################################################################################################## 5 | # install dependencies 6 | ######################################################################################################################## 7 | if [ $(dpkg-query -W -f='${Status}' docker.io 2>/dev/null | grep -c "ok installed") -eq 0 ] || \ 8 | [ $(dpkg-query -W -f='${Status}' pxz 2>/dev/null | grep -c "ok installed") -eq 0 ]; then 9 | sudo apt-get update 10 | sudo apt-get install -y docker.io pxz 11 | fi 12 | 13 | ######################################################################################################################## 14 | # The command line help 15 | ######################################################################################################################## 16 | display_help() { 17 | echo "Usage: $0 [option...]" >&2 18 | echo 19 | echo " --image docker image you want to save :" 20 | echo " --target-dir image file destination directory" 21 | echo " --delete deletes pulled image after export" 22 | echo 23 | # echo some stuff here for the -a or --add-options 24 | exit 1 25 | } 26 | 27 | ######################################################################################################################## 28 | # PARAMETER HANDLING 29 | ######################################################################################################################## 30 | IMAGE="" 31 | KEEP_IMAGE=0 32 | TARGET_DIR="/home/$USER/docker-images" 33 | for i in "$@" 34 | do 35 | case $i in 36 | -i=*|--image=*) 37 | IMAGE="${i#*=}" 38 | ;; 39 | -t=*|--target-dir=*) 40 | TARGET_DIR="${i#*=}" 41 | ;; 42 | -k|--keep-image) 43 | KEEP_IMAGE=1 44 | ;; 45 | -h|--help) 46 | display_help # Call your function 47 | exit 0 48 | ;; 49 | *) 50 | # unknown option 51 | ;; 52 | esac 53 | shift 54 | done 55 | 56 | ######################################################################################################################## 57 | # VALIDATE PARAMETER DEPENDENCIES 58 | ######################################################################################################################## 59 | if [ -z "$IMAGE" ]; then 60 | echo "--image is not set!" 61 | display_help 62 | exit 1 63 | fi 64 | 65 | if ! [ -d "$TARGET_DIR" ]; then 66 | mkdir -p "$TARGET_DIR" 67 | if ! [ -d "$TARGET_DIR" ]; then 68 | exit 1 69 | fi 70 | fi 71 | 72 | image_array=($(echo "$IMAGE" | tr ":" " ")) 73 | image_name="${image_array[0]}" 74 | image_version="${image_array[1]}" 75 | 76 | if [ -z "$image_name" ]; then 77 | echo "--image $image do not contain image name" 78 | display_help 79 | exit 1 80 | fi 81 | 82 | if [ -z "$image_version" ]; then 83 | echo "--image $image do not contain image version" 84 | display_help 85 | exit 1 86 | fi 87 | 88 | #sudo docker rmi $(sudo docker images -q) 89 | 90 | echo "pull image $image_name:$image_version" 91 | sudo docker pull "$image_name:$image_version" 92 | 93 | echo "export image $image_name:$image_version" 94 | sudo docker save "$image_name" | pxz > "$TARGET_DIR/$(echo "$image_name" | tr '/' '-')-$image_version.tar.xz" 95 | 96 | if [ "$KEEP_IMAGE" == 0 ]; then 97 | echo "deleting image $image_name:$image_version" 98 | sudo docker rmi "$image_name:$image_version" 99 | fi 100 | -------------------------------------------------------------------------------- /src/scripts/gitea-ssl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname $0)"/common 3 | . "$(dirname $0)"/ini_val 4 | . "$ETC_PATH"/config 5 | 6 | ######################################################################################################################## 7 | # VARIABLES 8 | ######################################################################################################################## 9 | SYNO_CERT_DIR="/usr/syno/etc/certificate/_archive" 10 | GITEA_SHARE="$SHARE_PATH/$SHARE" 11 | GITEA_CERT_DIR="$GITEA_SHARE/certs" 12 | GITEA_CONFIG="$GITEA_SHARE/gitea/conf/app.ini" 13 | HOSTNAME=$(ini_val ${GITEA_CONFIG} server.DOMAIN) 14 | TIMESTAMP=$(date +%s) 15 | GITEA_UI="$TARGET_PATH/ui/config" 16 | 17 | ACTION="" 18 | FORCE_RENEW=0 19 | 20 | 21 | if [ -z "$HOSTNAME" ]; then 22 | echo "#############################################################################################################" 23 | echo "gitea setup is is not completed yet, please run setup first by opening the gitea web page " 24 | echo "http:\\: " 25 | echo "#############################################################################################################" 26 | exit 1 27 | fi 28 | 29 | ######################################################################################################################## 30 | # PARAMETER HANDLING 31 | ######################################################################################################################## 32 | case "$1" in 33 | enable|ENABLE) 34 | ACTION="enable" 35 | if ! [ -d "$GITEA_CERT_DIR" ]; then 36 | mkdir -p "$GITEA_CERT_DIR" 37 | fi 38 | 39 | if [ -f "$GITEA_CERT_DIR/cert.pem" ]; then 40 | mv "$GITEA_CERT_DIR/cert.pem" "$GITEA_CERT_DIR/cert.pem.$TIMESTAMP" 41 | fi 42 | 43 | if [ -f "$GITEA_CERT_DIR/key.pem" ]; then 44 | mv "$GITEA_CERT_DIR/key.pem" "$GITEA_CERT_DIR/key.pem.$TIMESTAMP" 45 | fi 46 | 47 | $DOCKER_BIN exec -it "$GITEA_NAME" bash -c "./app/gitea/gitea cert -ca=true -duration=8760h0m0s -host=$HOSTNAME" 48 | $DOCKER_BIN exec -it "$GITEA_NAME" bash -c "mv /cert.pem /data/certs/" 49 | $DOCKER_BIN exec -it "$GITEA_NAME" bash -c "mv /key.pem /data/certs/" 50 | $DOCKER_BIN exec -it "$GITEA_NAME" bash -c "chmod 644 /data/certs/key.pem" 51 | 52 | ini_val ${GITEA_CONFIG} server.PROTOCOL "https" 53 | ini_val ${GITEA_CONFIG} server.ROOT_URL "%(PROTOCOL)s:\/\/%(DOMAIN)s:%(HTTP_PORT)s\/" 54 | ini_val ${GITEA_CONFIG} server.SSH_DOMAIN "%(DOMAIN)s" 55 | ini_val ${GITEA_CONFIG} server.CERT_FILE "\/data\/certs\/cert.pem" 56 | ini_val ${GITEA_CONFIG} server.KEY_FILE "\/data\/certs\/key.pem" 57 | 58 | sed -i -e "s|\"http\"|\"https\"|g" "$TARGET_PATH/ui/config" 59 | ;; 60 | disable|DISABLE) 61 | ACTION="disable" 62 | ini_val ${GITEA_CONFIG} server.PROTOCOL "http" 63 | sed -i -e "s|\"https\"|\"http\"|g" "$TARGET_PATH/ui/config" 64 | ;; 65 | *) 66 | echo "Usage: $0 {enable|disable}" >&2 67 | exit 1 68 | ;; 69 | esac 70 | 71 | echo "restarting gitea container" 72 | x=$("/var/packages/$PKG_NAME/scripts/start-stop-status" stop 2> /dev/null) 73 | sleep 5 74 | x=$("/var/packages/$PKG_NAME/scripts/start-stop-status" start 2> /dev/null) 75 | 76 | echo "#############################################################################################################" 77 | echo "action completed, please keep in mind that you need to reload you DSM page in your browser to get the " 78 | echo "correct gitea url for the gitea icon in your main menu! " 79 | echo "#############################################################################################################" 80 | exit 0 81 | -------------------------------------------------------------------------------- /src/WIZARD_UIFILES/install_uifile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2000-2016 Synology Inc. All rights reserved. 3 | 4 | PKG_NAME="Gitea" 5 | BACKUP_CONFIG="/usr/syno/etc/packages/__PKG_NAME__/config" 6 | 7 | NeedRestore() 8 | { 9 | if [ -f "$BACKUP_CONFIG" ]; then 10 | return 0 11 | else 12 | return 1 13 | fi 14 | } 15 | 16 | GetDBName() 17 | { 18 | get_key_value "$BACKUP_CONFIG" DB_NAME 19 | } 20 | 21 | GetDBUser() 22 | { 23 | #version < "9.4.4-0050" does not store db_user in config 24 | DB_USER=$(get_key_value "$BACKUP_CONFIG" DB_USER) 25 | DB_USER=${DB_USER:-gitea_user} 26 | echo "$DB_USER" 27 | } 28 | 29 | GetDBPass() 30 | { 31 | get_key_value "$BACKUP_CONFIG" DB_PASS 32 | } 33 | 34 | GetShare() 35 | { 36 | get_key_value "$BACKUP_CONFIG" SHARE 37 | } 38 | 39 | GetPkgVer() 40 | { 41 | get_key_value "$BACKUP_CONFIG" PKG_VER 42 | } 43 | 44 | wizard_found_backup="Please select a method to import data." 45 | wizard_decide_restore="Gitea database already exists.
Please select either of the following actions:" 46 | wizard_restore="Use existing data" 47 | wizard_create_new="Clean install (All existing data, including configuration files and the database, will be removed.)" 48 | install_title="Install Gitea" 49 | install_data_root_desc="Create a shared folder to store the data of Gitea." 50 | install_data_root_label="Shared folder name" 51 | http_port_desc="Please enter the external HTTP port number for Gitea." 52 | http_port_label="HTTP port number" 53 | ssh_port_desc="Please enter the external SSH port number for Gitea." 54 | ssh_port_label="SSH port number" 55 | hostname_label="Domain name" 56 | 57 | PageRestore() 58 | { 59 | cat << EOF 60 | { 61 | "step_title": "$wizard_found_backup", 62 | "items": [{ 63 | "type": "singleselect", 64 | "desc": "$wizard_decide_restore", 65 | "subitems": [{ 66 | "key": "restore_backup", 67 | "desc": "$wizard_restore", 68 | "defaultValue": true 69 | }, { 70 | "desc": "$wizard_create_new", 71 | "defaultValue": false 72 | }] 73 | }, { 74 | "type": "textfield", 75 | "subitems": [{ 76 | "key": "worker_mode", 77 | "desc": "drop or skip", 78 | "defaultValue": "skip", 79 | "hidden": true 80 | }] 81 | }] 82 | } 83 | EOF 84 | } 85 | 86 | CheckRestore() 87 | { 88 | cat << EOF 89 | // find constructor contains restore page 90 | for (i = arguments[0].ownerCt.items.length-1; i >= 1; i--){ 91 | page = arguments[0].ownerCt.items.items[i]; 92 | if (page.headline === \"${wizard_found_backup}\"){ 93 | // check whether user wants to restore or not 94 | restore = page.items.items[1].checked; 95 | break; 96 | } 97 | } 98 | EOF 99 | } 100 | 101 | FindObj() 102 | { 103 | cat << EOF 104 | for (i = 0; i < arguments[0].items.length; i++) { 105 | item = arguments[0].items.items[i] 106 | if (\"${1}\" === item.itemId){ 107 | $2 = arguments[0].items.items[i]; 108 | break; 109 | } 110 | } 111 | EOF 112 | } 113 | 114 | 115 | PageInstallSetting() 116 | { 117 | cat << EOF 118 | { 119 | "step_title": "$install_title", 120 | "items": [{ 121 | "type": "textfield", 122 | "desc": "$install_data_root_desc", 123 | "subitems": [{ 124 | "key": "pkgwizard_dataroot", 125 | "desc": "$install_data_root_label", 126 | "defaultValue": "gitea", 127 | "validator": { 128 | "allowBlank": false 129 | } 130 | }] 131 | },{ 132 | "type": "textfield", 133 | "desc": "$http_port_desc", 134 | "subitems": [{ 135 | "key": "pkgwizard_http_port", 136 | "desc": "$http_port_label", 137 | "defaultValue": "3000", 138 | "validator": { 139 | "allowBlank": false, 140 | "regex": { 141 | "expr": "/^[1-9]\\\\d{0,4}$/" 142 | }, 143 | "fn": "{var port=arguments[0]; if (port == 80 || port == 443) return 'Ports 80 and 443 are reserved ports and can not be remapped by docker!';return true;}" 144 | } 145 | }] 146 | },{ 147 | "type": "textfield", 148 | "desc": "$ssh_port_desc", 149 | "subitems": [{ 150 | "key": "pkgwizard_ssh_port", 151 | "desc": "$ssh_port_label", 152 | "defaultValue": "3001", 153 | "validator": { 154 | "allowBlank": false, 155 | "regex": { 156 | "expr": "/^[1-9]\\\\d{0,4}$/" 157 | }, 158 | "fn": "{var port=arguments[0]; if (port == 22) return 'Port 22 is a reserved port and can not be remapped by docker!';return true;}" 159 | } 160 | }] 161 | }] 162 | }] 163 | } 164 | EOF 165 | } 166 | main() 167 | { 168 | local install_page="" 169 | 170 | DEFAULT_RESTORE=false 171 | DB_NAME="$(GetDBName)" 172 | DB_USER="$(GetDBUser)" 173 | OLD_DATAROOT="$(GetShare)" 174 | 175 | if NeedRestore; then 176 | install_page="$(PageRestore),$(PageInstallSetting)" 177 | else 178 | install_page="$(PageInstallSetting)" 179 | fi 180 | 181 | echo "[$install_page]" > "${SYNOPKG_TEMP_LOGFILE}" 182 | 183 | return 0 184 | } 185 | 186 | main "$@" 187 | 188 | -------------------------------------------------------------------------------- /src/scripts/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2000-2015 Synology Inc. All rights reserved. 3 | 4 | . "$(dirname $0)"/common 5 | 6 | UpdateConfig() 7 | { 8 | if [ -f "$ETC_PATH"/config ]; then 9 | . "$ETC_PATH"/config 10 | fi 11 | if [ "$SYNOPKG_PKG_STATUS" = INSTALL ]; then 12 | 13 | if [ "$pkgwizard_container_port" = "HTTPS_SELF_SIGNED" ]; then 14 | GITEA_HTTPS="true" 15 | SSL_SELF_SIGNED="true" 16 | 17 | GITEA_CERT_DIR="$SHARE_PATH/$pkgwizard_dataroot/certs" 18 | if ! [ -d "$GITEA_CERT_DIR" ]; then 19 | mkdir -p $GITEA_CERT_DIR 20 | fi 21 | 22 | if ! [ -f "$GITEA_CERT_DIR/gitea.key" ]; then 23 | openssl genrsa -out "$GITEA_CERT_DIR/gitea.key" 2048 24 | fi 25 | 26 | if ! [ -f "$GITEA_CERT_DIR/gitea.csr" ]; then 27 | openssl req -new -key "$GITEA_CERT_DIR/gitea.key" -subj "/C=DE/ST=Germany/L=Duisburg/O=jboxberger/CN=$pkgwizard_hostname" -out "$GITEA_CERT_DIR/gitea.csr" 28 | fi 29 | 30 | if ! [ -f "$GITEA_CERT_DIR/gitea.crt" ]; then 31 | openssl x509 -req -days 3650 -in "$GITEA_CERT_DIR/gitea.csr" -signkey "$GITEA_CERT_DIR/gitea.key" -out "$GITEA_CERT_DIR/gitea.crt" 32 | fi 33 | chmod 400 "$GITEA_CERT_DIR/gitea.key" 34 | 35 | if ! [ -f "$GITEA_CERT_DIR/dhparam.pem" ] && [ -f "/usr/syno/etc/ssl/dh2048.pem" ]; then 36 | cp "/usr/syno/etc/ssl/dh2048.pem" "$GITEA_CERT_DIR/dhparam.pem" 37 | fi 38 | 39 | elif [ "$pkgwizard_container_port" = "HTTPS" ]; then 40 | GITEA_HTTPS="true" 41 | SSL_SELF_SIGNED="false" 42 | else 43 | GITEA_HTTPS="false" 44 | SSL_SELF_SIGNED="false" 45 | fi 46 | 47 | SHARE="$pkgwizard_dataroot" 48 | HTTP_PORT="$pkgwizard_http_port" 49 | SSH_PORT="$pkgwizard_ssh_port" 50 | HOSTNAME="$pkgwizard_hostname" 51 | 52 | DB_NAME="$pkgwizard_db_name" 53 | DB_USER="$pkgwizard_db_user_account" 54 | DB_PASS="$pkgwizard_db_user_password" 55 | DB_ROOT_PASS="$pkgwizard_db_root_password" 56 | fi 57 | 58 | ( 59 | echo GITEA_HTTPS="\"$(echo "$GITEA_HTTPS" | quote_sh)\"" 60 | echo SSL_SELF_SIGNED="\"$(echo "$SSL_SELF_SIGNED" | quote_sh)\"" 61 | echo HTTP_PORT="\"$(echo "$HTTP_PORT" | quote_sh)\"" 62 | echo SSH_PORT="\"$(echo "$SSH_PORT" | quote_sh)\"" 63 | echo DB_NAME="\"$(echo "$DB_NAME" | quote_sh)\"" 64 | echo DB_USER="\"$(echo "$DB_USER" | quote_sh)\"" 65 | echo DB_PASS="\"$(echo "$DB_PASS" | quote_sh)\"" 66 | echo DB_ROOT_PASS="\"$(echo "$DB_ROOT_PASS" | quote_sh)\"" 67 | echo HOSTNAME="\"$(echo "$HOSTNAME" | quote_sh)\"" 68 | echo SHARE="\"$(echo "$SHARE" | quote_sh)\"" 69 | echo VERSION="\"$(echo "$SYNOPKG_PKGVER" | cut -d '-' -f 1 | quote_sh)\"" 70 | ) > "$ETC_PATH"/config 71 | } 72 | 73 | UpdateConfig 74 | . "$ETC_PATH"/config 75 | 76 | GITEA_HTTP_SCHEME="http" 77 | if [ $GITEA_HTTPS == true ]; then 78 | GITEA_HTTP_SCHEME="https" 79 | fi 80 | 81 | sed -i \ 82 | -e "s/__HTTP_PROTOCOL__/$(echo "$GITEA_HTTP_SCHEME" | quote_json | quote_sed)/g" \ 83 | "$TARGET_PATH"/ui/config 84 | 85 | sed -i \ 86 | -e "s/__HTTP_PORT__/$(echo "$HTTP_PORT" | quote_json | quote_sed)/g" \ 87 | "$TARGET_PATH"/ui/config \ 88 | "$GITEA_PROFILE" 89 | sed -i \ 90 | -e "s/__GITEA_HTTPS__/$(echo "$GITEA_HTTPS" | quote_json | quote_sed)/g" \ 91 | -e "s/__SSL_SELF_SIGNED__/$(echo "$SSL_SELF_SIGNED" | quote_json | quote_sed)/g" \ 92 | -e "s/__SSH_PORT__/$(echo "$SSH_PORT" | quote_json | quote_sed)/g" \ 93 | -e "s/__SHARE__/$(echo "$SHARE" | quote_json | quote_sed)/g" \ 94 | -e "s/__HOSTNAME__/$(echo "$HOSTNAME" | quote_sed | quote_json | quote_sed)/g" \ 95 | "$GITEA_PROFILE" 96 | 97 | ######################################################################################################################## 98 | # RESTORE CUSTOM CONFIGURATION 99 | ######################################################################################################################## 100 | RestoreCustomEnvironmentVariables 101 | RestoreContainerPorts 102 | 103 | ######################################################################################################################## 104 | # ADD IMAGES 105 | ######################################################################################################################## 106 | /var/packages/Docker/target/tool/helper \ 107 | "$GITEA_PACKAGE_NAME" "$GITEA_VERSION" "$TARGET_PATH"/docker/"$GITEA_PACKAGE_NAME_ESCAPED"-"$GITEA_VERSION".tar.xz $GITEA_SIZE \ 108 | || exit 1 109 | 110 | ######################################################################################################################## 111 | # GITEA 112 | ######################################################################################################################## 113 | $SYNO_WEBAPI --exec api=SYNO.Docker.Container version=1 method=delete name="$GITEA_NAME" force=true preserve_profile=false 114 | $SYNO_WEBAPI --exec api=SYNO.Docker.Container version=1 method=create is_run_instantly=false profile="$(cat "$GITEA_PROFILE")" || exit 1 115 | 116 | 117 | exit 0 118 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Gitea is a community managed fork of Gogs, lightweight code hosting solution written in Go and published under the MIT license. 2 | 3 | Project Page: [https://gitea.io](https://gitea.io) 4 | Documentation: [https://docs.gitea.io/en-us/](https://docs.gitea.io/en-us/) 5 | **Download Gitea 1.11.1 SPK**: [here](https://github.com/jboxberger/synology-gitea-jboxberger/releases) 6 | 7 | ## Packages: 8 | - https://hub.docker.com/r/gitea/gitea/ 9 | 10 | ## Supported Architectures 11 | **x86 avoton bromolow cedarview braswell kvmx64 broadwell apollolake** 12 | Since i can't test all architectures i had to make a choice which i can cover or which i expect to work. If your architecture is not in this list, please feel free to contact me and we can give it a try. 13 | 14 | You can check the architecture of your device [here](https://github.com/SynoCommunity/spksrc/wiki/Architecture-per-Synology-model) 15 | or [here](https://www.synology.com/en-us/knowledgebase/DSM/tutorial/General/What_kind_of_CPU_does_my_NAS_have). 16 | 17 | ## Version Enumeration 18 | ``` 19 | Gitea - (Gitea 1.4) 20 | Gitea-Version: as expected the GitLab version 21 | Package-Version: version of the application around GitLab, install backup an other scripts 22 | ``` 23 | 24 | ## Build instructions 25 | ``` 26 | ################################################################################################################ 27 | # Make shure docker is already installed and runnig 28 | # All in One Package: The docker image is in the .spk. This leads to a much bigger .spk file but on the other 29 | # hand you avoid all possible issues during docker pull and this package could be installed 30 | # offline. Harder to build but gives a more stable update process. 31 | # On Demand Package : (not recommended) Docker image is not in the .spk file an will be pulled during spk 32 | # installation. The benefit here is a smaller package size and easy to build .spk - May 33 | # cause problems during installtaion when the docker image pull not working properly or 34 | # connection breaks down. This may cause a half installed Package which should be cleaned 35 | # up and backup properly to be able to re-install. 36 | ################################################################################################################ 37 | 38 | # All in One Package 39 | ---------------------------------------------------------------------------------------------------------------- 40 | # 1) export the needed docker image version 41 | bash tools/save-docker-image.sh --image="gitea/gitea:1.9.5" --target-dir=./docker 42 | 43 | # 2) Execute all steps from 'On Demand Package'. The build script will automatically detect the exported image 44 | # in the docker directory and include it in the .spk 45 | 46 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 47 | 48 | # On Demand Package (docker image will be pulled during spk installation) 49 | ---------------------------------------------------------------------------------------------------------------- 50 | # 1) add an new line (or modify existing) in the rebuild-all.sh with the desired version 51 | # the value of '45' is just the expected container size in MB for Synology installer progressbar. 52 | versions["1.9.5"]="45"; orders+=( "1.9.5" ) 53 | 54 | # 2) execute the rebuild-all.sh script (required packages will be installed automatically) 55 | bash rebuild-all.sh 56 | 57 | # you will find the new .spk in the folder build// 58 | ``` 59 | 60 | ## Enable / Disable SSL 61 | After setup (install package and setup gitea) you can enable or disable self-signed-ssl connection 62 | ``` 63 | # enable 64 | sudo ./var/packages/synology-gitea-jboxberger/scripts/gitea-ssl enable 65 | ``` 66 | ``` 67 | # disable 68 | sudo ./var/packages/synology-gitea-jboxberger/scripts/gitea-ssl disable 69 | ``` 70 | 71 | ## Use MySQL/MariaDB instead of SQLite3 72 | By default you can use SQLite3, this is a fast and reliable one file database solution. If your Gitea serves a couple of developers this should be more than sufficient but if you run your environment for more than 10 developers then you might have better performance with MySQL/MariaDB. 73 | ``` 74 | 1. Install the official MairaDB10 Package from Synology repository and set the root password. 75 | 2. Create databse schema and user for gitea. If you're not familliar with mysql cli then you 76 | can install phpmyadmin from official synology repository. 77 | 78 | CREATE DATABASE `gitea` DEFAULT CHARACTER SET `utf8mb4` COLLATE `utf8mb4_general_ci`; 79 | CREATE USER `gitea`@'%' IDENTIFIED BY ''; 80 | GRANT ALL PRIVILEGES ON `gitea`.* TO `gitea`@`%`; 81 | 82 | CREATE USER `gitea`@'localhost' IDENTIFIED BY ''; 83 | GRANT ALL PRIVILEGES ON `gitea`.* TO `gitea`@`localhost`; 84 | 85 | 3. Now you can selecte MariaDB during the Gitea setup and the rest of the schema will be created automatically 86 | during the Gitea setup. 87 | 4. Don't forget to backup your database regulary, this schema will not be backuped in the included backup script. 88 | ``` 89 | 90 | ## Bash into your Gitea container 91 | ``` 92 | sudo docker exec -it synology_gitea bash 93 | ``` 94 | 95 | ## Backup 96 | ``` 97 | # create backup directory 98 | sudo mkdir -p /volume1/docker/gitea/backups 99 | sudo chown 1000:1000 /volume1/docker/gitea/backups 100 | 101 | # create backup 102 | sudo /usr/local/bin/docker exec -it -u git synology_gitea bash -c "cd /data/backups && gitea dump -c /data/gitea/conf/app.ini && chmod -R 777 /data/backups/*" 103 | ``` 104 | 105 | ## Restore 106 | ``` 107 | sudo docker exec -it synology_gitea bash 108 | cd /data/backups 109 | rm -rf gitea-dump && mkdir gitea-dump && unzip gitea-dump-1568411897.zip -d gitea-dump/ && cd gitea-dump/ 110 | rm -rf /data/gitea/* && mv data/* /data/gitea 111 | 112 | rm -rf gitea-repo && mkdir gitea-repo && unzip gitea-repo.zip -d gitea-repo/ 113 | rm -rf /data/git/repositories && mv gitea-repo/* /data/git/ 114 | 115 | # restore MYSQL (not required if use Sqlite3) 116 | mysql -u$USER -p$PASS $DATABASE > $SYNOPKG_TEMP_LOGFILE 35 | } 36 | fi 37 | 38 | quote_sed() { 39 | sed -e 's|\\|\\\\|g' -e 's|&|\\\&|g' -e 's|/|\\/|g' 40 | } 41 | 42 | quote_sql() { 43 | sed -e "s|\`|\`\`|g" 44 | } 45 | 46 | quote_sh() { 47 | sed -e 's|\\|\\\\|g' -e 's|\"|\\\"|g' -e 's|`|\\`|g' -e 's|\\$|\\$|g' 48 | } 49 | 50 | quote_json() { 51 | sed -e 's|\\|\\\\|g' -e 's|\"|\\\"|g' 52 | } 53 | 54 | #======================================================================================================================= 55 | # stringInArray 56 | #======================================================================================================================= 57 | stringInArray() { 58 | local e match="$1" 59 | shift 60 | for e; do [[ "$e" == "$match" ]] && return 1; done 61 | return 0 62 | } 63 | 64 | #======================================================================================================================= 65 | # BackupCustomEnvironmentVariablesOld 66 | #======================================================================================================================= 67 | BackupCustomEnvironmentVariables() 68 | { 69 | $SYNO_WEBAPI --exec api=SYNO.Docker.Container.Profile version=1 method=export outfile="$DOCKER_GITEA_CONFIG_FILE" name="$GITEA_NAME" 70 | if ! [ -s "$DOCKER_GITEA_CONFIG_FILE" ]; then 71 | return 0 72 | fi 73 | 74 | env_ignore_file=$(cd `dirname $0` && pwd)/env_ignore 75 | declare -A env_ignore_variables; declare -a keys; declare -a values; 76 | 77 | i=0 78 | while read line; 79 | do 80 | env_ignore_variables[$i]=$(echo "$line" | tr -d '\r') 81 | (( i++ )) 82 | done < $env_ignore_file 83 | 84 | # Rewrite File from new 85 | if [ -f "$DOCKER_GITEA_CONFIG_CUSTOM" ]; then 86 | rm "$DOCKER_GITEA_CONFIG_CUSTOM" 87 | fi 88 | 89 | i=0 90 | tmp_keys=$(jq '.env_variables[] | .key' <"$DOCKER_GITEA_CONFIG_FILE" | tr -d '"') 91 | while read line 92 | do 93 | keys[$i]="$line" 94 | (( i++ )) 95 | done <<< "${tmp_keys[@]}" 96 | 97 | i=0 98 | tmp_values=$(jq '.env_variables[] | .value' <"$DOCKER_GITEA_CONFIG_FILE" | tr -d '"') 99 | while read line 100 | do 101 | values[$i]="$line" 102 | (( i++ )) 103 | done <<< "${tmp_values[@]}" 104 | 105 | for i in "${!keys[@]}" 106 | do 107 | stringInArray "${keys[$i]}" "${env_ignore_variables[@]}" 108 | if [ $? == 0 ]; then 109 | echo "${keys[$i]}=${values[$i]}" >> "$DOCKER_GITEA_CONFIG_CUSTOM" 110 | fi 111 | done 112 | 113 | rm $DOCKER_GITEA_CONFIG_FILE 114 | return 1 115 | } 116 | 117 | #======================================================================================================================= 118 | # RestoreCustomEnvironmentVariables 119 | #======================================================================================================================= 120 | RestoreCustomEnvironmentVariables() 121 | { 122 | declare -a keys 123 | 124 | # if file exists and has a size greater than zero 125 | if ! [ -s $DOCKER_GITEA_CONFIG_CUSTOM ] 126 | then 127 | return 0 128 | fi 129 | 130 | cp $GITEA_PROFILE $GITEA_PROFILE"_backup" 131 | chmod 0644 $GITEA_PROFILE"_backup" 132 | 133 | i=0 134 | tmp_keys=$(jq '.env_variables[].key' <"$GITEA_PROFILE" | tr -d '"') 135 | while read line 136 | do 137 | keys[$i]="$line" 138 | (( i++ )) 139 | done <<< "${tmp_keys[@]}" 140 | 141 | while read LINE; 142 | do 143 | key=$(echo $LINE | cut -f1 -d=) 144 | value=$(echo $LINE | cut -f2 -d=) 145 | value=$(echo "$value" | tr -d '\r') # trim \r on line-end 146 | stringInArray "$key" "${keys[@]}" 147 | if [ $? == 1 ]; then 148 | index=$(echo ${keys[@]/$key//} | cut -d/ -f1 | wc -w | tr -d ' ') 149 | #echo "$key:$value:$index" 150 | jq -c ".env_variables[$index].value=\"$value\"" <$GITEA_PROFILE >$GITEA_PROFILE".out" && mv $GITEA_PROFILE".out" $GITEA_PROFILE 151 | else 152 | jq -c ".env_variables += [{\"key\" : \"$key\", \"value\" : \"$value\"}]" <$GITEA_PROFILE >$GITEA_PROFILE".out" && mv $GITEA_PROFILE".out" $GITEA_PROFILE 153 | fi 154 | done < $DOCKER_GITEA_CONFIG_CUSTOM 155 | } 156 | 157 | #======================================================================================================================= 158 | # BackupContainerPorts 159 | #======================================================================================================================= 160 | BackupContainerPorts() 161 | { 162 | declare -a container_ports; declare -a host_ports; declare -a types; 163 | 164 | $SYNO_WEBAPI --exec api=SYNO.Docker.Container.Profile version=1 method=export outfile="$DOCKER_GITEA_CONFIG_FILE" name="$GITEA_NAME" 165 | if ! [ -s "$DOCKER_GITEA_CONFIG_FILE" ]; then 166 | return 0 167 | fi 168 | 169 | # Rewrite File from new 170 | if [ -f "$DOCKER_GITEA_CONFIG_CONTAINER_PORTS" ]; then 171 | rm "$DOCKER_GITEA_CONFIG_CONTAINER_PORTS" 172 | fi 173 | 174 | i=0 175 | tmp_container_ports=$(jq '.port_bindings[].container_port' <"$DOCKER_GITEA_CONFIG_FILE" | tr -d '"') 176 | while read line 177 | do 178 | container_ports[$i]="$line" 179 | (( i++ )) 180 | done <<< "${tmp_container_ports[@]}" 181 | 182 | i=0 183 | tmp_host_ports=$(jq '.port_bindings[].host_port' <"$DOCKER_GITEA_CONFIG_FILE" | tr -d '"') 184 | while read line 185 | do 186 | host_ports[$i]="$line" 187 | (( i++ )) 188 | done <<< "${tmp_host_ports[@]}" 189 | 190 | i=0 191 | tmp_types=$(jq '.port_bindings[].type' <"$DOCKER_GITEA_CONFIG_FILE" | tr -d '"') 192 | while read line 193 | do 194 | types[$i]="$line" 195 | (( i++ )) 196 | done <<< "${tmp_types[@]}" 197 | 198 | for i in "${!container_ports[@]}" 199 | do 200 | echo "${container_ports[$i]}:${host_ports[$i]}:${types[$i]}" >> "$DOCKER_GITEA_CONFIG_CONTAINER_PORTS" 201 | done 202 | 203 | rm $DOCKER_GITEA_CONFIG_FILE 204 | return 1 205 | } 206 | 207 | #======================================================================================================================= 208 | # BackupContainerPorts 209 | #======================================================================================================================= 210 | RestoreContainerPorts() 211 | { 212 | # if file exists and has a size greater than zero 213 | if ! [ -s $DOCKER_GITEA_CONFIG_CONTAINER_PORTS ] 214 | then 215 | return 0 216 | fi 217 | 218 | cp $GITEA_PROFILE $GITEA_PROFILE"_backup_ports" 219 | chmod 0644 $GITEA_PROFILE"_backup_ports" 220 | 221 | json_content="" 222 | while read LINE; 223 | do 224 | container_port=$(echo $LINE | cut -f1 -d: | tr -d '\r') 225 | host_port=$(echo $LINE | cut -f2 -d: | tr -d '\r') 226 | type=$(echo $LINE | cut -f3 -d: | tr -d '\r') 227 | json_content="$json_content{\"container_port\" : $container_port, \"host_port\" : \"$host_port\", \"type\" : \"$type\"}," 228 | done < $DOCKER_GITEA_CONFIG_CONTAINER_PORTS 229 | 230 | jq -c ".port_bindings=[${json_content::-1}]" < $GITEA_PROFILE > $GITEA_PROFILE".out" && mv $GITEA_PROFILE".out" $GITEA_PROFILE 231 | } 232 | --------------------------------------------------------------------------------