mirror of
https://github.com/YunoHost-Apps/haste_ynh.git
synced 2024-09-03 20:36:28 +02:00
first commit
This commit is contained in:
commit
045ba29953
10 changed files with 332 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*~
|
||||
*.sw[op]
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -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.
|
37
README.md
Normal file
37
README.md
Normal file
|
@ -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
|
44
conf/config.js
Normal file
44
conf/config.js
Normal file
|
@ -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"
|
||||
}
|
||||
|
||||
}
|
16
conf/haste.service
Normal file
16
conf/haste.service
Normal file
|
@ -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
|
11
conf/nginx.conf
Normal file
11
conf/nginx.conf
Normal file
|
@ -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;
|
||||
}%
|
55
manifest.json
Normal file
55
manifest.json
Normal file
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
38
scripts/_common.sh
Normal file
38
scripts/_common.sh
Normal file
|
@ -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
|
||||
}
|
71
scripts/install
Executable file
71
scripts/install
Executable file
|
@ -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
|
37
scripts/remove
Executable file
37
scripts/remove
Executable file
|
@ -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
|
Loading…
Reference in a new issue