From 045ba29953831083375a2ae00d4d9df29a2d8b86 Mon Sep 17 00:00:00 2001 From: mbugeia Date: Tue, 25 Oct 2016 00:00:01 +0200 Subject: [PATCH] first commit --- .gitignore | 2 ++ LICENSE | 21 ++++++++++++++ README.md | 37 ++++++++++++++++++++++++ conf/config.js | 44 ++++++++++++++++++++++++++++ conf/haste.service | 16 +++++++++++ conf/nginx.conf | 11 +++++++ manifest.json | 55 +++++++++++++++++++++++++++++++++++ scripts/_common.sh | 38 +++++++++++++++++++++++++ scripts/install | 71 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/remove | 37 ++++++++++++++++++++++++ 10 files changed, 332 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 conf/config.js create mode 100644 conf/haste.service create mode 100644 conf/nginx.conf create mode 100644 manifest.json create mode 100644 scripts/_common.sh create mode 100755 scripts/install create mode 100755 scripts/remove diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..783a4ae --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +*.sw[op] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..745c7c4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 mbugeia + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d07035 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# Work In Progress : do not install in production +## TODO +- find a way to let user edit the hook and not overwrite it +- better check if gogs is installed and on the repo format +- backup/restore + + +# Gogs web hosting for YunoHost + +This Yunohost App take an existing gogs repository and serve it with nginx + +Gogs is a self-hosted Git service written in Go. Alternative to Github. +- [Gogs website](http://gogs.io) +- [Gogs package for YunoHost](https://github.com/YunoHost-Apps/gogs_ynh) + +## Requirements +- Functionnal instance of [YunoHost](https://yunohost.org) +- [Gogs package must](https://github.com/YunoHost-Apps/gogs_ynh) be installed +- The repository that you want to serve must exist in Gogs + +## Installation +From command line: + +`sudo yunohost app install -l MySite https://github.com/YunoHost-Apps/gogs_webhost_ynh` + +## Upgrade +From command line: + +`sudo yunohost app upgrade -u https://github.com/YunoHost-Apps/gogs_webhost_ynh gogswebhost` + +## Infos + +- [YunoHost forum thread](https://forum.yunohost.org/) + +## License + +This package is published under MIT License diff --git a/conf/config.js b/conf/config.js new file mode 100644 index 0000000..00e98c5 --- /dev/null +++ b/conf/config.js @@ -0,0 +1,44 @@ +{ + + "host": "127.0.0.1", + "port": 7777, + + "keyLength": 10, + + "maxLength": 400000, + + "staticMaxAge": 86400, + + "recompressStaticAssets": true, + + "logging": [ + { + "level": "info", + "type": "Console", + "colorize": true + } + ], + + "keyGenerator": { + "type": "phonetic" + }, + + "rateLimits": { + "categories": { + "normal": { + "totalRequests": 500, + "every": 60000 + } + } + }, + + "storage": { + "type": "file", + "file": "YNH_DATA_PATH" + }, + + "documents": { + "about": "./about.md" + } + +} diff --git a/conf/haste.service b/conf/haste.service new file mode 100644 index 0000000..fdbfa69 --- /dev/null +++ b/conf/haste.service @@ -0,0 +1,16 @@ +[Unit] +Description=Haste is an open-source pastebin software written in node.js +After=syslog.target +After=network.target + +[Service] +Type=simple +User=haste +Group=haste +WorkingDirectory=/opt/haste +ExecStart=npm start +Restart=always +Environment=USER=haste HOME=/opt/haste + +[Install] +WantedBy=multi-user.target diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..e4be067 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,11 @@ +location PATHTOCHANGE/ { + COMMENT_IF_ROOTrewrite ^PATHTOCHANGE$ PATHTOCHANGE/ permanent; + proxy_pass http://localhost:7777/; + proxy_set_header Host $host; + proxy_buffering off; + fastcgi_param REMOTE_USER $remote_user; + client_max_body_size 50M; + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +}% diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..c165399 --- /dev/null +++ b/manifest.json @@ -0,0 +1,55 @@ +{ + "name": "Haste", + "id": "haste", + "packaging_format": 1, + "description": { + "en": "Haste is an open-source pastebin software written in node.js", + "fr": "Haste is an open-source pastebin software written in node.js" + }, + "url": "https://example.com", + "license": "free", + "maintainer": { + "name": "mbugeia", + "email": "maxime.bugeia@gmail.com", + "url": "http://example.com" + }, + "requirements": { + "yunohost": ">> 2.4.0" + }, + "multi_instance": false, + "services": [ + "nginx" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "type": "domain", + "ask": { + "en": "Choose a domain name for Haste", + "fr": "Choisissez un nom de domaine pour Haste" + }, + "example": "example.com" + }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for Haste", + "fr": "Choisissez un chemin pour Haste" + }, + "example": "/example", + "default": "/example" + }, + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public site?", + "fr": "Est-ce un site publique ?" + }, + "default": true + } + ] + } +} diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..3e02b90 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,38 @@ +# +# Common variables +# + +APPNAME="haste" + +# Gogs version +VERSION="master" + +# Remote URL to fetch Haste tarball +HASTE_URL="https://github.com/seejohnrun/haste-server/archive/"${VERSION}".zip" + +# +# Common helpers +# + +# Download, extract and install Haste to the given directory +# usage: install_haste DESTDIR +install_haste() { + local DESTDIR=$1 + local TMPDIR=$(mktemp -d) + + # retrieve, extract, install haste + haste_tarball="/tmp/haste.zip" + rm -f "$haste_tarball" + wget -q -O "$haste_tarball" "$HASTE_URL" \ + || ynh_die "Unable to download haste" + unzip -q "$haste_tarball" -d "$TMPDIR" \ + || ynh_die "Unable to extract haste" + sudo rsync -a "$TMPDIR"/haste-server-master/* "$DESTDIR" + rm -rf "$haste_tarball" "$TMPDIR" + + # install haste + current_dir=$(pwd) + cd "$DESTDIR" + sudo npm install + cd $current_dir +} diff --git a/scripts/install b/scripts/install new file mode 100755 index 0000000..1c74eec --- /dev/null +++ b/scripts/install @@ -0,0 +1,71 @@ +#!/bin/bash + +# Exit on command errors and treat unset variables as an error +set -eu + +app=${YNH_APP_INSTANCE_NAME:-haste} + +# Retrieve arguments +domain=$YNH_APP_ARG_DOMAIN +path=$YNH_APP_ARG_PATH +is_public=$YNH_APP_ARG_IS_PUBLIC + +DATA_PATH="/home/yunohost.app/"$app + +# Load common variables +source ./_common.sh + +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Save app settings +ynh_app_setting_set "$app" is_public "$is_public" + +# Check domain/path availability +sudo yunohost app checkurl "${domain}${path}" -a "$app" \ + || ynh_die "Path not available: ${domain}${path}" + +# Add user +id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet +id -u "$app" &>/dev/null || sudo adduser "$app" \ + --ingroup "$app" --system --quiet --shell /bin/bash + +# Install the app +DESTDIR="/opt/"${app} +install_haste $DESTDIR +mkdir -p $DATA_PATH +sudo chown -R "$app":"$app" $DESTDIR $DATA_PATH + +# Configure haste with config.js file +sudo cp ../conf/config.js "$DESTDIR"/config.js +sudo sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$DESTDIR"/config.js + +# Configure init script +sudo cp ../conf/haste.service /etc/systemd/system/ +sudo systemctl daemon-reload +sudo systemctl enable "$app".service + +# Start Haste +sudo systemctl start "$app".service + +# Add Haste to YunoHost's monitored services +sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log + +# Modify Nginx configuration file and copy it to Nginx conf directory +sed -i "s@PATHTOCHANGE@${path%/}@g" ../conf/nginx.conf +if [ "$path" = "/" ] +then + sed -i "s@COMMENT_IF_ROOT@#@g" ../conf/nginx.conf +else + sed -i "s@COMMENT_IF_ROOT@@g" ../conf/nginx.conf +fi +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/"$app".conf + +# If app is public, add url to SSOWat conf as skipped_uris +if [[ $is_public -eq 1 ]]; then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set "$app" unprotected_uris "/" +fi + +# Reload services +sudo systemctl reload nginx.service diff --git a/scripts/remove b/scripts/remove new file mode 100755 index 0000000..107c5c8 --- /dev/null +++ b/scripts/remove @@ -0,0 +1,37 @@ +#!/bin/bash + +# See comments in install script +app=${YNH_APP_INSTANCE_NAME:-haste} + +# Source YunoHost helpers +source /usr/share/yunohost/helpers + +# Retrieve app settings +domain=$(ynh_app_setting_get "$app" domain) + +# Stop haste +sudo systemctl stop "$app".service + +# Remove sources +sudo rm -rf "/opt/"${app} + +# Remove post-receive hook +repo_path="/home/gogs/repositories/"$gogsrepo".git" +sudo rm -f $repo_path"/hooks/post-receive" + +# Remove nginx configuration file +[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" + +# Remove haste user and data +sudo userdel -r "$app" + +# Remove init script +sudo systemctl disable "$app".service +sudo rm -f /etc/systemd/system/"$app".service +sudo systemctl daemon-reload + +# Remove monitor +sudo yunohost service remove "$app" + +# Reload nginx service +sudo systemctl reload nginx.service