summaryrefslogtreecommitdiffstats
path: root/snap/helpers
diff options
context:
space:
mode:
authorThorben <tbraeutigam@users.noreply.github.com>2018-05-09 16:52:51 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2018-05-09 22:52:51 +0800
commit14f16d6c2e8db1d99268c44a59aa86132c00eca3 (patch)
treef5d7a1076890bbbe6abdfea6f58b1c0ef3dae0af /snap/helpers
parent02ecc03d6df8956075d151104e0e07f0d858d578 (diff)
downloadgitea-14f16d6c2e8db1d99268c44a59aa86132c00eca3.tar.gz
gitea-14f16d6c2e8db1d99268c44a59aa86132c00eca3.zip
snap-packaging for gitea (#2568)
* Modify tbraeutigam/gogs-snap for gitea * Fix building on 16.04 (manually build go-bindata). -> add _source.tar.bz2 to .gitignore (used by snapcraft cleanbuild) * Streamline Snap packaging: - Take advantage of install-hooks (snapd 2.27) - Use snapctl configuration storage for unchanging values * Move to using Snap Hooks for configuration * Missed re-adding daemon statement * Fix two warnings from Codacy.
Diffstat (limited to 'snap/helpers')
-rw-r--r--snap/helpers/app.ini66
-rwxr-xr-xsnap/helpers/configuration.sh126
-rwxr-xr-xsnap/helpers/simple_launcher.sh23
3 files changed, 215 insertions, 0 deletions
diff --git a/snap/helpers/app.ini b/snap/helpers/app.ini
new file mode 100644
index 0000000000..dd7fa3c88f
--- /dev/null
+++ b/snap/helpers/app.ini
@@ -0,0 +1,66 @@
+APP_NAME = Gitea: Go Git Service
+RUN_USER = root
+RUN_MODE = prod
+CUSTOM_PATH = SNAP_DIR_DATA/custom
+
+[server]
+DOMAIN = localhost
+PROTOCOL = http
+HTTP_PORT = 3001
+ROOT_URL = http://localhost:3001/
+DISABLE_SSH = false
+SSH_PORT = 22
+STATIC_ROOT_PATH = SNAP_DIR_DATA/static
+APP_DATA_PATH = SNAP_DIR_COMMON/data
+SSH_ROOT = SNAP_DIR_COMMON/ssh
+SSH_KEY_TEST_PATH = SNAP_DIR_DATA/sshkeytest
+
+[database]
+DB_TYPE = sqlite3
+PATH = SNAP_DIR_COMMON/gitea.db
+
+[repository]
+ROOT = SNAP_DIR_COMMON/repositories/data
+
+[repository.upload]
+ENABLED = true
+ALLOWED_TYPES = "image/jpeg|image/png"
+FILE_MAX_SIZE = 10
+MAX_FILES = 5
+TEMP_PATH = SNAP_DIR_COMMON/repositories/tmp
+
+[release.attachment]
+PATH = SNAP_DIR_COMMON/releases/attachments
+
+[smartypants]
+ENABLED = true
+
+[indexer]
+ISSUE_INDEXER_PATH = SNAP_DIR_COMMON/indexers/issues.bleve
+
+
+[mailer]
+ENABLED = false
+
+[service]
+REGISTER_EMAIL_CONFIRM = false
+ENABLE_NOTIFY_MAIL = false
+DISABLE_REGISTRATION = false
+ENABLE_CAPTCHA = false
+REQUIRE_SIGNIN_VIEW = false
+
+[picture]
+AVATAR_UPLOAD_PATH = SNAP_DIR_COMMON/pictures/avatars
+DISABLE_GRAVATAR = true
+ENABLE_FEDERATED_AVATAR = false
+
+[attachment]
+PATH = SNAP_DIR_COMMON/attachments
+
+[session]
+PROVIDER = memory
+
+[log]
+MODE = file
+LEVEL = Trace
+ROOT_PATH = SNAP_DIR_COMMON/log
diff --git a/snap/helpers/configuration.sh b/snap/helpers/configuration.sh
new file mode 100755
index 0000000000..34b7fc7af4
--- /dev/null
+++ b/snap/helpers/configuration.sh
@@ -0,0 +1,126 @@
+#!/bin/bash
+if snapctl get gitea.snap.custom; then
+ cdir=$(snapctl get gitea.snap.custom)
+else
+ cdir=$SNAP_COMMON
+fi
+
+cfg="$cdir/conf/app.ini"
+bak="$cdir/conf/app.ini.bak-$(date -Ins)"
+basecfg="$SNAP/snap/helpers/app.ini"
+smp="$SNAP/gitea/custom/conf/app.ini.sample"
+
+function toSnap() {
+OIFS=$IFS
+IFS='
+'
+ category="none"
+ src="$cfg"
+ [[ "$1" = "init" ]] && src="$smp"
+ [[ "$1" = "snap" ]] && src="$basecfg"
+
+ for l in $(sed 's_;\([A-Z]*\)_\1_g' $src | grep -v -e '^;' -e '^$'); do
+ if echo $l | grep -q '^[[]'; then
+ category=$(CatToSnap "$l")
+ elif echo $l | grep -q '^[A-Z]'; then
+ option=$(OptToSnap "$l")
+ value=$(ValToSnap "$l")
+ if [[ $category = "none" ]]; then
+ snapctl set "$option=$value"
+ else
+ snapctl set "$category.$option=$value"
+ fi
+ fi
+ done
+IFS=$OIFS
+}
+
+function toIni() {
+OIFS=$IFS
+IFS='
+'
+ category="none"; option="none"; catUnset=true
+ src=$smp
+ [[ -f $cfg ]] && src="$cfg"
+ tmpIni="$cfg.tmp"
+ [[ -f $src ]] && cp "$src" "$tmpIni"
+ cp $tmpIni $bak
+ echo '' > $cfg
+ for l in $(grep -v -e '^;' -e '^$' $tmpIni); do
+ if echo $l | grep -q '^[[]'; then
+ category=$(CatToSnap "$l")
+ catUnset=true
+ elif echo $l | grep -q '^[A-Z]'; then
+ option=$(OptToSnap "$l")
+ if [[ $category = "none" ]]; then
+ value=$(snapctl get $option)
+ echo $(OptToIni "$option") = $value >> $cfg
+ else
+ value=$(snapctl get $category.$option)
+ if $catUnset; then
+ echo "" >> $cfg
+ echo "[$(CatToIni "$category")]" >> $cfg
+ catUnset=false
+ fi
+ echo $(OptToIni "$option") = $value >> $cfg
+ fi
+ fi
+ done;
+ IFS=$OIFS
+}
+
+function CatToSnap {
+ ret=$(echo "$1" \
+ | grep -oP '[A-Za-z0-9._]+' \
+ | sed 's|\.|-|g' \
+ | sed 's|_|99|g')
+ echo $ret
+}
+function OptToSnap {
+ ret=$(echo "$1" \
+ | grep -oP '^[A-Z_]+' \
+ | tr '[:upper:]' '[:lower:]' \
+ | sed 's|_|-|g')
+ echo $ret
+}
+function ValToSnap {
+ ret=$(echo "$1" \
+ | grep -oP '=.*$' \
+ | sed 's_^= __g' \
+ | sed 's_^=__g' \
+ | sed "s|SNAP_DIR_DATA|$SDATA|g" \
+ | sed "s|SNAP_DIR_COMMON|$SCOMMON|g" \
+ | sed 's|{}||g')
+ echo $ret
+}
+
+function CatToIni {
+ ret=$(echo "$1" \
+ | sed 's|-|.|g' \
+ | sed 's|\ |_|g' \
+ | sed 's|99|_|g')
+ echo $ret
+}
+function OptToIni {
+ ret=$(echo "$1" \
+ | tr '[:lower:]' '[:upper:]' \
+ | sed 's|-|_|g')
+ echo $ret
+}
+
+[[ "$1" = "configure" ]] \
+ && toIni \
+ && exit 0
+
+[[ "$1" = "install" ]] \
+ && echo "Initial Configuration..." \
+ && mkdir -p $SNAP_COMMON/conf \
+ && toSnap init \
+ && toSnap snap \
+ && toIni sample \
+ && exit 0
+
+[[ "$1" = "save" ]] \
+ && echo "Saving current config..." \
+ && toSnap \
+ && exit 0
diff --git a/snap/helpers/simple_launcher.sh b/snap/helpers/simple_launcher.sh
new file mode 100755
index 0000000000..8a12e3b8dd
--- /dev/null
+++ b/snap/helpers/simple_launcher.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+if ! env | grep -q root; then
+ echo "
+ +----------------------------------------+
+ | You are not running gitea as root. |
+ | This is required for the snap package. |
+ | Please re-run as root. |
+ +----------------------------------------+
+"
+ $SNAP/gitea/gitea --help
+ exit 1
+fi
+
+# Set usernames for gitea
+export USERNAME=root
+export USER=root
+
+export GITEA_WORK_DIR=$(snapctl get gitea.snap.workdir)
+export GITEA_CUSTOM=$(snapctl get gitea.snap.custom)
+
+$SNAP/bin/gconfig save
+cd $SNAP/gitea; ./gitea $@