Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Added check_process, improved install,remove scripts,nginx.conf,manif…
Browse files Browse the repository at this point in the history
…est.json
  • Loading branch information
anmol26s committed Nov 16, 2017
1 parent 5bac40b commit e1efec3
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 76 deletions.
41 changes: 41 additions & 0 deletions check_process
@@ -0,0 +1,41 @@
# See here for more informations
# https://github.com/YunoHost/package_check#syntax-check_process-file

# Move this file from check_process.default to check_process when you have filled it.

;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
admin="john" (USER)
password="pass"
is_public=1 (PUBLIC|public=1|private=0)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=0
backup_restore=0
multi_instance=1
incorrect_path=1
port_already_use=0
change_url=0
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
# Level 4:
Level 4=0
# Level 5:
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=anmol@datamol.org
Notification=yes
6 changes: 6 additions & 0 deletions conf/app.src
@@ -0,0 +1,6 @@
SOURCE_URL=https://github.com/fkooman/php-remote-storage/archive/1.0.5.zip
SOURCE_SUM=e7966a6820782e3937659c490690ae2b
SOURCE_SUM_PRG=md5sum
SOURCE_FORMAT=zip
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
24 changes: 16 additions & 8 deletions conf/nginx.conf
@@ -1,19 +1,27 @@
location YNH_WWW_PATH {
location __PATH__ {

# Path to source
alias YNH_WWW_ALIAS ;
alias __FINALPATH__/ ;

if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}

# Example PHP configuration (remove if not used)
index index.php;
index index.html index.htm index.php;

# Common parameter to increase upload size limit in conjuction with dedicated php-fpm file
#client_max_body_size 50M;
client_max_body_size 30M;

try_files $uri $uri/ index.php;
if (!-e $request_filename)
{
rewrite ^(.+)$ //index.php$1 last;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;

# Filename to be changed if dedicated php-fpm process is required
# This is to be used INSTEAD of line above
# Don't forget to adjust scripts install/upgrade/remove/backup accordingly
Expand All @@ -23,11 +31,11 @@ location YNH_WWW_PATH {
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_INFO /$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
# PHP configuration end

# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
# include conf.d/yunohost_panel.conf.inc;
}
10 changes: 10 additions & 0 deletions conf/php-fpm.ini
@@ -0,0 +1,10 @@
; Common values to change to increase file upload limit
; upload_max_filesize = 50M
; post_max_size = 50M
; mail.add_x_header = Off

; Other common parameters
; max_execution_time = 600
; max_input_time = 300
; memory_limit = 256M
; short_open_tag = On
42 changes: 24 additions & 18 deletions manifest.json
@@ -1,57 +1,63 @@
{
"name": "remoteStorage",
"id": "remotestorage",
"id": "Remotestorage",
"packaging_format": 1,
"description": {
"en": "Laverna is a JavaScript note taking application with Markdown editor and encryption support. Consider it like open source alternative to Evernote.",
"fr": "Laverna is a JavaScript note taking application with Markdown editor and encryption support. Consider it like open source alternative to Evernote."
"en": "This is a remoteStorage server implementation written in PHP."
},
"url": "https://laverna.cc/index.html",
"url": "https://github.com/fkooman/php-remote-storage",
"license": "free",
"maintainer": {
"name": "Alex",
"email": "apulido@free.fr",
"url": "https://github.com/likeitneverwentaway/laverna_ynh"
"name": "Anmol Sharma",
"email": "anmol@datamol.org",
"url": ""
},
"requirements": {
"yunohost": ">> 2.4.0"
},
"multi_instance": true,
"services": [
"nginx",
"php5-fpm",
"mysql"
"php5-fpm"
],
"license": "free",
"arguments": {
"install" : [
{
"name": "domain",
"type": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain name for Laverna",
"fr": "Choisissez un nom de domaine pour Laverna"
"en": "Choose a domain name for Remotestorage",
"fr": "Choisissez un nom de domaine pour Remotestorage"
},
"example": "example.com"
},
{
"name": "path",
"type": "path",
"type": "path",
"ask": {
"en": "Choose a path for Laverna",
"fr": "Choisissez un chemin pour Laverna"
"en": "Choose a path for Remotestorage",
"fr": "Choisissez un chemin pour Remotestorage"
},
"example": "/remoteStorage",
"default": "/remoteStorage"
},
{
"name": "admin",
"type": "user",
"type": "user",
"ask": {
"en": "Choose an admin user",
"fr": "Choisissez l’administrateur"
"en": "Choose an user (Not a LDAP User)",
"fr": "Choisissez l’user (Not a LDAP User)"
},
"example": "johndoe"
},
{
"name": "password",
"type": "password",
"ask": {
"en": "Password for the user account (At least 6 characters long)",
"fr": "Password for the user account (At least 6 characters long)"
},
{
"name": "is_public",
"type": "boolean",
Expand Down
14 changes: 14 additions & 0 deletions scripts/_common.sh
@@ -0,0 +1,14 @@
#!/bin/bash

# ============= FUTURE YUNOHOST HELPER =============
# Delete a file checksum from the app settings
#
# $app should be defined when calling this helper
# DEPENDENCIES
pkg_dependencies="php php-mbstring php-curl libapache2-mod-xsendfile php-sqlite3 php5-sqlite"
# usage: ynh_remove_file_checksum file
# | arg: file - The file for which the checksum will be deleted
ynh_delete_file_checksum () {
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_delete $app $checksum_setting_name
}
160 changes: 121 additions & 39 deletions scripts/install
@@ -1,8 +1,32 @@
#!/bin/bash

# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# MANAGE SCRIPT FAILURE
#=================================================

# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================

domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
admin_password=$YNH_APP_ARG_PASSWORD
is_public=$YNH_APP_ARG_IS_PUBLIC

# This is a multi-instance app, meaning it can be installed several times independently
# The id of the app as stated in the manifest is available as $YNH_APP_ID
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# The app instance name is available as $YNH_APP_INSTANCE_NAME
Expand All @@ -14,54 +38,112 @@ set -eu
# db names, ...
app=$YNH_APP_INSTANCE_NAME

# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC

# Source YunoHost helpers
source /usr/share/yunohost/helpers

# Save app settings
ynh_app_setting_set "$app" admin "$admin"
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}"
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================

final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"

# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)

# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url

# Copy source files
src_path=/var/www/$app
path_temp=/var/www
#sudo mkdir -p $src_path
# Check password strength
[[ ${#admin_password} -gt 6 ]] || ynh_die \
"The password is too weak, it must be longer than 6 characters"

#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================

sudo wget -P "$path_temp" https://github.com/fkooman/php-remote-storage/releases/download/1.0.3/php-remote-storage-1.0.3.tar.xz
sudo tar -xJf "$path_temp"/php-remote-storage-1.0.3.tar.xz -C "$path_temp"
sudo rm "$path_temp"/php-remote-storage-1.0.3.tar.xz
sudo mv "$path_temp"/php-remote-storage-1.0.3 "$src_path"
sudo cp "$src_path"/config/server.yaml.example "$src_path"/config/server.yaml
sudo "$src_path"/bin/add-user alex alex
sudo mkdir "$src_path"/data
sudo chown www-data.www-data "$src_path"/data
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app language $language

#=================================================
# INSTALL DEPENDENCIES
#=================================================

# Set permissions to app files
sudo chown -R root: $src_path
ynh_install_app_dependencies $pkg_dependencies


# Modify Nginx configuration file and copy it to Nginx conf directory
nginx_conf=../conf/nginx.conf
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
sed -i "s@YNH_WWW_ALIAS@$src_path/web/@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================

# 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 "/"
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"

#=================================================
# SPECIFIC SETUP
#=================================================

# Create a directory data
mkdir -p $final_path/data

# Create config/server.yaml
sudo cp $final_path/config/server.yaml.example $final_path/config/server.yaml

# Create first user
sudo php $final_path/bin/add-user.php $admin $admin_password

# Install and initialize Composer
init_composer $final_path

#=================================================
# NGINX CONFIGURATION
#=================================================

# Create a dedicated nginx config
ynh_add_nginx_config


#=================================================
# CREATE DEDICATED USER
#=================================================

# Create a system user
ynh_system_user_create $app

#=================================================
# PHP-FPM CONFIGURATION
#=================================================

# Create a dedicated php-fpm config
ynh_add_fpm_config

# Set right permissions for curl install
chown -R $app: $final_path

#=================================================
# SETUP SSOWAT
#=================================================

if [ $is_public -eq 0 ]
then # Remove the public access
ynh_app_setting_delete $app skipped_uris
fi
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
fi

#=================================================
# RELOAD NGINX
#=================================================

# Reload services
sudo service nginx reload
systemctl reload nginx

0 comments on commit e1efec3

Please sign in to comment.