1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ghost_ynh.git synced 2024-09-03 19:16:02 +02:00

Revamp of the app acc to YunoHost 3

This commit is contained in:
anmol26s 2018-07-23 19:40:35 +05:30
parent 1524baf37e
commit d381bdbab3
19 changed files with 724 additions and 1545 deletions

View file

@ -1,24 +1,40 @@
# 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 ;; Test complet
auto_remove=1
; Manifest ; Manifest
domain="domain.tld" (DOMAIN) domain="domain.tld" (DOMAIN)
path="/path" (PATH) path="/path" (PATH)
admin="john" (USER) is_public=1 (PUBLIC|public=1|private=0)
password="password" (PASSWORD)
; Checks ; Checks
pkg_linter=1 pkg_linter=1
setup_sub_dir=1 setup_sub_dir=1
setup_root=1 setup_root=1
setup_nourl=0 setup_nourl=0
setup_private=0 setup_private=1
setup_public=0 setup_public=1
upgrade=1 upgrade=1
backup_restore=1 backup_restore=1
multi_instance=0 multi_instance=1
wrong_user=1 incorrect_path=1
wrong_path=1 port_already_use=1
incorrect_path=1 change_url=0
corrupt_source=0 ;;; Levels
fail_download_source=0 Level 1=auto
port_already_use=0 Level 2=auto
final_path_already_use=0 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=
Notification=none

6
conf/app.src Normal file
View file

@ -0,0 +1,6 @@
SOURCE_URL=https://github.com/TryGhost/Ghost/archive/1.24.9.zip
SOURCE_SUM=9560f0f54cbbfd412e6d37245ac82178f704df2707f156012373c60381235a49
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=zip
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=

View file

@ -1,40 +0,0 @@
// # Ghost Configuration
// Setup your Ghost install for various environments
var path = require('path'),
config;
config = {
production: {
url: 'http://YNH_DOMAINYNH_LOCATION',
mail: {
transport: 'SMTP',
options : {
host : 'localhost',
port : '25'
}
},
database: {
client: 'mysql',
connection: {
host : 'localhost',
user : 'YNH_DBUSER',
password : 'YNH_DBPWD',
database : 'YNH_DBNAME',
charset : 'utf8'
}
},
server: {
// Host to be passed to node's `net.Server#listen()`
host: '0.0.0.0',
// Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
port: '2368'
}
}
};
// Export config
module.exports = config;

View file

@ -0,0 +1,29 @@
{
"url": "https://__DOMAIN__/__PATH__",
"server": {
"host": "127.0.0.1",
"port": __PORT__
},
"database": {
"client": "mysql",
"connection": {
"host" : "127.0.0.1",
"user" : "__DBNAME__",
"password" : "__DBPWD__",
"database" : "__DBNAME__"
}
},
"auth": {
"type": "password"
},
"paths": {
"contentPath": "content/"
},
"logging": {
"level": "info",
"rotation": {
"enabled": true
},
"transports": ["file", "stdout"]
}
}

View file

@ -1,193 +0,0 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: ghost
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Ghost Blogging Platform
# Description: Ghost: Just a blogging platform
### END INIT INFO
# Kindly stolen from http://docs.ghost.org/pl/installation/deploy/
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Ghost"
NAME=ynh-ghostblog
GHOST_ROOT=YNH_FINALPATH/ghost
GHOST_GROUP=ghostblog
GHOST_USER=ghostblog
DAEMON=/usr/bin/node
DAEMON_ARGS="$GHOST_ROOT/index.js"
PIDFILEDIR=/var/run/yunohost/ghostblog
PIDFILE=$PIDFILEDIR/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
LOGFILE="YNH_LOGFILE"
export NODE_ENV=production
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# I like to know what is going on
VERBOSE=yes
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Set up folder structure
mkdir -p $PIDFILEDIR
chown -R $GHOST_USER:$GHOST_GROUP $PIDFILEDIR
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet \
--chuid $GHOST_USER:$GHOST_GROUP --chdir $GHOST_ROOT --background \
--pidfile $PIDFILE --make-pidfile --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet \
--chuid $GHOST_USER:$GHOST_GROUP --chdir $GHOST_ROOT --background \
--pidfile $PIDFILE --make-pidfile --exec /bin/bash -- -c "exec $DAEMON $DAEMON_ARGS >> $LOGFILE 2>&1" \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some dime.
ghost_http_request_result=1
ghost_path=$(yunohost app setting ghostblog path)
count=0
max_count=60
while [ "$ghost_http_request_result" != "0" ]
do
[ "$VERBOSE" != no ] && log_action_cont_msg "."
if [ "$count" -ge $max_count ]; then
[ "$VERBOSE" != no ] && log_action_cont_msg "Timeout"
return 3
fi
curl -kL -X GET http://localhost:2368${ghost_path} > /dev/null 2>&1
ghost_http_request_result=$?
sleep 1
count=$(expr $count + 1)
done
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
--pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/3/KILL/5 \
--exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
# #
# # Function that sends a SIGHUP to the daemon/service
# #
# do_reload() {
# #
# # If the daemon can reload its configuration without
# # restarting (for example, when it is sent a SIGHUP),
# # then implement that here.
# #
# start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE \
# --name $NAME
# return 0
# }
case "$1" in
start)
[ "$VERBOSE" != no ] && log_action_begin_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_action_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_action_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
exit 0

View file

@ -1,10 +0,0 @@
YNH_LOGFILE
{
weekly
missingok
rotate 12
notifempty
compress
delaycompress
copytruncate
}

View file

@ -1,10 +1,10 @@
location YNH_LOCATION { location __PATH__/ {
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true; proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:2368; proxy_pass http://127.0.0.1:__PORT__;
proxy_redirect off; proxy_redirect off;
client_max_body_size 100M; client_max_body_size 100M;

1036
conf/npm-shrinkwrap.json generated

File diff suppressed because it is too large Load diff

15
conf/systemd.service Normal file
View file

@ -0,0 +1,15 @@
[Unit]
Description=__APP__ systemd service
Documentation=https://docs.ghost.org
[Service]
Type=simple
WorkingDirectory=__FINALPATH__
User=__APP__
Group=__APP__
Environment="NODE_ENV=production"
ExecStart=/usr/bin/node index.js run
Restart=always
[Install]
WantedBy=multi-user.target

View file

@ -1,4 +0,0 @@
import sys, json
for i in json.loads(sys.stdin.readlines()[0])["users"]:
if i["username"] == sys.argv[1]:
print i["mail"]

View file

@ -1,4 +0,0 @@
import sys, json
for i in json.loads(sys.stdin.readlines()[0])["users"]:
if i["username"] == sys.argv[1]:
print i["fullname"]

View file

@ -1,3 +0,0 @@
import sys, json
userlist=json.loads(sys.stdin.readlines()[0])["Users"]
print "{0}".format("\n".join(i["Username"] for i in userlist))

View file

@ -1,16 +1,27 @@
{ {
"name": "Ghost", "name": "Ghost",
"id": "ghostblog", "id": "ghost",
"packaging_format": 1,
"description": { "description": {
"en": "Just a blogging platform", "en": "Just a blogging platform",
"fr": "Plateforme de blogging" "fr": "Plateforme de blogging"
}, },
"version": "1.0",
"url": "https://ghost.org/",
"license": "free",
"developer": { "developer": {
"name": "Julien Malik", "name": "Julien Malik",
"email": "julien.malik@paraiso.me", "email": "julien.malik@paraiso.me"
"url": "https://ghost.org/"
}, },
"multi_instance": "false", "requirements": {
"yunohost": ">= 2.7.2"
},
"multi_instance": true,
"services": [
"nginx",
"nodjs",
"mysql"
],
"arguments": { "arguments": {
"install" : [ "install" : [
{ {
@ -31,19 +42,13 @@
"default": "/blog" "default": "/blog"
}, },
{ {
"name": "admin", "name": "is_public",
"type": "boolean",
"ask": { "ask": {
"en": "Admin user (must be an existing Yunohost user login)", "en": "Is it a public application?",
"fr": "Administrateur du site (doit être un utilisateur Yunohost existant)" "fr": "Est-ce une application publique ?"
}, },
"default": "homer" "default": true
},
{
"name": "password",
"ask": {
"en": "Admin user password (8 characters minimum)",
"fr": "Mot de passe de l'administrateur (8 caractères minimum)"
}
} }
] ]
} }

13
scripts/_common.sh Normal file
View file

@ -0,0 +1,13 @@
#!/bin/bash
# ============= FUTURE YUNOHOST HELPER =============
# Delete a file checksum from the app settings
#
# $app should be defined when calling this helper
#
# 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
}

58
scripts/backup Executable file
View file

@ -0,0 +1,58 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_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
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_mysql_dump_db "$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/systemd/system/$app.service"

View file

@ -1,136 +1,201 @@
#!/bin/bash #!/bin/bash
# Retrieve arguments #=================================================
domain=$1 # GENERIC START
path=$2 #=================================================
admin=$3 # IMPORT GENERIC HELPERS
password=$4 #=================================================
# '/ghost' is refused by the application itself. This is used as the route to the admin section source _common.sh
if [[ "$path" = "/ghost" ]]; then source /usr/share/yunohost/helpers
echo "Error : the path cannot be '/ghost', please choose another location"
exit 1 #=================================================
# 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
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
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
# The app instance name is probably what you are interested the most, since this is
# guaranteed to be unique. This is a good unique identifier to define installation path,
# db names, ...
app=$YNH_APP_INSTANCE_NAME
#=================================================
# 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
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app is_public $is_public
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
# Find a free port
port=$(ynh_find_port 4010)
# Open this port
yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
# install nodejs
ynh_install_nodejs 8
# add yarn repo for Debian
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
ynh_package_update
ynh_install_app_dependencies mailutils yarn
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
# If your app uses a MySQL database, you can use these lines to bootstrap
# a database, an associated user and save the password in app settings
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $db_name $db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
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"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
if [ "$path_url" != "/" ]
then
ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
fi
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
# Copy configuration file
cp ../conf/config.production.json "$final_path/config.production.json"
# Install the dependencies with yarn
(
cd "$final_path"
yarn install
yarn global add knex-migrator
)
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/config.production.json"
ynh_replace_string "__PATH__" "path_url" "$final_path/config.production.json"
ynh_replace_string "__DBNAME__" "$db_name" "$final_path/config.production.json"
ynh_replace_string "__DBPWD__" "$db_pwd" "$final_path/config.production.json"
ynh_replace_string "__PORT__" "$port" "$final_path/config.production.json"
# Create tables in database
(
cd "$final_path"
NODE_ENV=production knex-migrator init
)
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.production.json"
#=================================================
# SET WRITE PERMISSION
#=================================================
# Set right permissions for curl install
chown -R $app: $final_path
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config
systemctl start "$app"
#=================================================
# 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 fi
# Check that admin user is an existing account #=================================================
sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" # RELOAD NGINX
if [[ ! $? -eq 0 ]]; then #=================================================
echo "Error : the chosen admin user does not exist"
exit 1
fi
# 'password' must be >= 8 characters systemctl reload nginx
if [[ $(expr length $password) -lt "8" ]]; then
echo "Error : the password must be >= 8 characters"
exit 1
fi
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a ghostblog
if [[ ! $? -eq 0 ]]; then
exit 1
fi
echo "Install dependencies..."
sudo apt-get update
sudo apt-get install nodejs-legacy npm -y
version=0.5.1
echo "Downloading Ghost $version..."
mkdir ../tmp
sudo wget -O ../tmp/ghost-$version.zip "https://en.ghost.org/zip/ghost-$version.zip"
echo "Deploying source files..."
unzip ../tmp/ghost-$version.zip -d ../tmp/ghost
final_path=/var/www/ghostblog
sudo mkdir -p $final_path
sudo useradd -d $final_path ghostblog
sudo cp -r ../tmp/ghost $final_path
#sudo cp ../conf/npm-shrinkwrap.json $final_path/ghost
sudo chown -R ghostblog: $final_path
echo "Installing Ghost with NPM..."
#sudo su --shell /bin/bash --command "cd $final_path/ghost && npm install --production --registry http://registry.npmjs.eu" ghostblog
sudo su --shell /bin/bash --command "cd $final_path/ghost && npm install --production --registry http://registry.npmjs.org" ghostblog
echo "Cleaning up install tree..."
sudo rm -rf $final_path/.npm
find $final_path -type d | grep "test$" | xargs sudo rm -rf
find $final_path -type d | grep "tests$" | xargs sudo rm -rf
sudo rm -rf $final_path/ghost/node_modules/sqlite3/build
sudo rm -rf $final_path/tmp
echo "Patching sources to remove calls to googleapis..."
# patches to core
sudo cp $final_path/ghost/core/server/views/user-error.hbs $final_path/ghost/core/server/views/user-error.hbs.orig
sudo cp $final_path/ghost/core/server/views/default.hbs $final_path/ghost/core/server/views/default.hbs.orig
sudo cp $final_path/ghost/core/client/assets/css/fonts.css $final_path/ghost/core/client/assets/css/fonts.css.orig
sudo sed -i '/googleapis/c\ <link rel="stylesheet" type="text/css" href="{{asset "css/fonts.css" ghost="true"}}">' $final_path/ghost/core/server/views/user-error.hbs
sudo sed -i '/googleapis/c\ <link rel="stylesheet" type="text/css" href="{{asset "css/fonts.css" ghost="true"}}">' $final_path/ghost/core/server/views/default.hbs
sudo cp ../patches/core/fonts.css $final_path/ghost/core/client/assets/css
sudo cp ../patches/core/*.woff $final_path/ghost/core/client/assets/fonts
# patches to casper theme
sudo cp $final_path/ghost/content/themes/casper/default.hbs $final_path/ghost/content/themes/casper/default.hbs.orig
sudo cp $final_path/ghost/content/themes/casper/assets/css/fonts.css $final_path/ghost/content/themes/casper/assets/css/fonts.css.orig
sudo sed -i '/googleapis/c\ <link rel="stylesheet" type="text/css" href="{{asset "css/fonts.css"}}">' $final_path/ghost/content/themes/casper/default.hbs
sudo cp ../patches/theme/fonts.css $final_path/ghost/content/themes/casper/assets/css
sudo cp ../patches/theme/*.woff $final_path/ghost/content/themes/casper/assets/fonts
echo "Setting up permissions"
sudo chown -R ghostblog: $final_path/ghost
echo "Setting up database..."
db_name=ghostblog
db_user=ghostblog
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
sudo yunohost app initdb $db_user -d $db_name -p $db_pwd
sudo yunohost app setting ghostblog mysqlpwd -v $db_pwd
echo "Deploying configuration..."
sed -i "s@YNH_DOMAIN@$domain@g" ../conf/config.js
sed -i "s@YNH_LOCATION@${path%/}@g" ../conf/config.js
sed -i "s@YNH_DBNAME@$db_name@g" ../conf/config.js
sed -i "s@YNH_DBUSER@$db_user@g" ../conf/config.js
sed -i "s@YNH_DBPWD@$db_pwd@g" ../conf/config.js
sudo cp ../conf/config.js $final_path/ghost
sudo chown ghostblog: $final_path/ghost/config.js
sudo chmod 644 $final_path/ghost/config.js
echo "Setting up init script..."
logfile=/var/log/ynh-ghostblog.log
sudo touch $logfile
sudo chown ghostblog: $logfile
sed -i "s@YNH_FINALPATH@$final_path@g" ../conf/init-script
sed -i "s@YNH_LOGFILE@$logfile@g" ../conf/init-script
sudo cp ../conf/init-script /etc/init.d/ynh-ghostblog
sudo chmod +x /etc/init.d/ynh-ghostblog
sudo update-rc.d ynh-ghostblog defaults
sudo service ynh-ghostblog start
sudo yunohost service add ynh-ghostblog -l $logfile
echo "Setting up logrotate configuration..."
sed -i "s@YNH_LOGFILE@$logfile@g" ../conf/logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/ynh-ghostblog
echo "Nginx configuration (sso disabled)..."
sed -i "s@YNH_LOCATION@$path@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/ghostblog.conf
sudo yunohost app setting ghostblog skipped_uris -v "/"
echo "Reloading Nginx (sso disabled)..."
sudo service nginx reload
sudo yunohost app ssowatconf
echo "Registering admin..."
admin_name=$(sudo yunohost user list --json | python ../conf/user_getname.py $admin)
admin_mail=$(sudo yunohost user list --json | python ../conf/user_getmail.py $admin)
curl -kL -X POST http://localhost:2368${path%/}/ghost/api/v0.1/authentication/setup/ \
--data-urlencode "setup[0][name]=$admin_name" \
--data-urlencode "setup[0][email]=$admin_mail" \
--data-urlencode "setup[0][password]=$password" \
--data-urlencode "setup[0][blogTitle]=My Yunohost blog"
sudo yunohost app setting ghostblog admin -v $admin
sudo yunohost app setting ghostblog password -v $password
echo "Success ! You can go to https://$domain$path/ghost to write your posts"

View file

@ -1,21 +1,89 @@
#!/bin/bash #!/bin/bash
domain=$(sudo yunohost app setting ghostblog domain) #=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
sudo service ynh-ghostblog stop source _common.sh
sudo update-rc.d ynh-ghostblog remove source /usr/share/yunohost/helpers
sudo rm /etc/init.d/ynh-ghostblog
sudo yunohost service remove ynh-ghostblog
sudo rm -f /etc/nginx/conf.d/$domain.d/ghostblog.conf
sudo rm -f /var/log/ynh-ghostblog.log*
sudo rm -rf /var/run/yunohost/ghostblog
sudo rm -f /etc/logrotate.d/ynh-ghostblog
db_user=ghostblog #=================================================
db_name=ghostblog # LOAD SETTINGS
root_pwd=$(sudo cat /etc/yunohost/mysql) #=================================================
mysql -u root -p$root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;" app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================
if yunohost service status | grep -q $app
then
echo "Remove $app service"
yunohost service remove $app
fi
#=================================================
# REMOVE DEPENDENCIES
#=================================================
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db $db_user $db_name
#=================================================
# REMOVE APP MAIN DIR
#=================================================
# Remove the app directory securely
ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# CLOSE A PORT
#=================================================
if yunohost firewall list | grep -q "\- $port$"
then
echo "Close port $port"
yunohost firewall disallow TCP $port 2>&1
fi
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete a system user
ynh_system_user_delete $app
# remove user so that it does not hold resource
sudo userdel --remove ghostblog

111
scripts/restore Executable file
View file

@ -0,0 +1,111 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_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
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
port=$(ynh_app_setting_get "$app" port)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "$final_path"
# Open this port
yunohost firewall allow Both "$port" 2>&1
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_name $db_name $db_pwd
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R $app: $final_path
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# install nodejs
ynh_install_nodejs 8
# add yarn repo for Debian
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
ynh_package_update
ynh_install_app_dependencies mailutils yarn
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service
systemctl start "$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
systemctl reload nginx

View file

@ -1,95 +1,178 @@
#!/bin/bash #!/bin/bash
# Retrieve arguments #=================================================
domain=$(sudo yunohost app setting ghostblog domain) # GENERIC START
path=$(sudo yunohost app setting ghostblog path) #=================================================
path=${path%/} # IMPORT GENERIC HELPERS
admin=$(sudo yunohost app setting ghostblog admin) #=================================================
password=$(sudo yunohost app setting ghostblog password)
sudo service ynh-ghostblog stop source _common.sh
source /usr/share/yunohost/helpers
final_path=/var/www/ghostblog #=================================================
# LOAD SETTINGS
#=================================================
version=0.5.1 app=$YNH_APP_INSTANCE_NAME
echo "Downloading Ghost $version..."
mkdir ../tmp
sudo wget -O ../tmp/ghost-$version.zip "https://en.ghost.org/zip/ghost-$version.zip"
unzip ../tmp/ghost-$version.zip -d ../tmp/ghost
echo "Saving content folder..." domain=$(ynh_app_setting_get $app domain)
sudo cp -ar $final_path/ghost/content ../tmp path_url=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
echo "Deploying source files..." #=================================================
sudo rm -rf $final_path/ghost # ENSURE DOWNWARD COMPATIBILITY
sudo cp -r ../tmp/ghost $final_path #=================================================
sudo cp -ar ../tmp/content $final_path/ghost
#sudo cp ../conf/npm-shrinkwrap.json $final_path/ghost
sudo chown -R ghostblog: $final_path
echo "Installing Ghost with NPM..." # Fix is_public as a boolean value
#sudo su --shell /bin/bash --command "cd $final_path/ghost && npm install --production --registry http://registry.npmjs.eu" ghostblog if [ "$is_public" = "Yes" ]; then
sudo su --shell /bin/bash --command "cd $final_path/ghost && npm install --production --registry http://registry.npmjs.org" ghostblog ynh_app_setting_set $app is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
echo "Cleaning up install tree..." # If db_name doesn't exist, create it
sudo rm -rf $final_path/.npm if [ -z $db_name ]; then
find $final_path -type d | grep "test$" | xargs sudo rm -rf db_name=$(ynh_sanitize_dbid $app)
find $final_path -type d | grep "tests$" | xargs sudo rm -rf ynh_app_setting_set $app db_name $db_name
sudo rm -rf $final_path/ghost/node_modules/sqlite3/build fi
sudo rm -rf $final_path/tmp
echo "Patching sources to remove calls to googleapis..." # If final_path doesn't exist, create it
# patches to core if [ -z $final_path ]; then
sudo cp $final_path/ghost/core/server/views/user-error.hbs $final_path/ghost/core/server/views/user-error.hbs.orig final_path=/var/www/$app
sudo cp $final_path/ghost/core/server/views/default.hbs $final_path/ghost/core/server/views/default.hbs.orig ynh_app_setting_set $app final_path $final_path
sudo cp $final_path/ghost/core/client/assets/css/fonts.css $final_path/ghost/core/client/assets/css/fonts.css.orig fi
sudo sed -i '/googleapis/c\ <link rel="stylesheet" type="text/css" href="{{asset "css/fonts.css" ghost="true"}}">' $final_path/ghost/core/server/views/user-error.hbs
sudo sed -i '/googleapis/c\ <link rel="stylesheet" type="text/css" href="{{asset "css/fonts.css" ghost="true"}}">' $final_path/ghost/core/server/views/default.hbs
sudo cp ../patches/core/fonts.css $final_path/ghost/core/client/assets/css
sudo cp ../patches/core/*.woff $final_path/ghost/core/client/assets/fonts
echo "Setting up permissions" #=================================================
sudo chown -R ghostblog: $final_path/ghost # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
echo "Setting up database..." # Backup the current version of the app
db_name=ghostblog ynh_backup_before_upgrade
db_user=ghostblog ynh_clean_setup () {
db_pwd=$(sudo yunohost app setting ghostblog mysqlpwd) # restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
echo "Deploying configuration..." #=================================================
sed -i "s@YNH_DOMAIN@$domain@g" ../conf/config.js # CHECK THE PATH
sed -i "s@YNH_LOCATION@${path%/}@g" ../conf/config.js #=================================================
sed -i "s@YNH_DBNAME@$db_name@g" ../conf/config.js
sed -i "s@YNH_DBUSER@$db_user@g" ../conf/config.js
sed -i "s@YNH_DBPWD@$db_pwd@g" ../conf/config.js
sudo cp ../conf/config.js $final_path/ghost
sudo chown ghostblog: $final_path/ghost/config.js
sudo chmod 644 $final_path/ghost/config.js
echo "Setting up init script..." # Normalize the URL path syntax
logfile=/var/log/ynh-ghostblog.log path_url=$(ynh_normalize_url_path $path_url)
sudo touch $logfile
sudo chown ghostblog: $logfile
sed -i "s@YNH_FINALPATH@$final_path@g" ../conf/init-script #=================================================
sed -i "s@YNH_LOGFILE@$logfile@g" ../conf/init-script # STANDARD UPGRADE STEPS
sudo cp ../conf/init-script /etc/init.d/ynh-ghostblog #=================================================
sudo chmod +x /etc/init.d/ynh-ghostblog # DOWNLOAD, CHECK AND UNPACK SOURCE
sudo update-rc.d ynh-ghostblog defaults #=================================================
sudo service ynh-ghostblog start
sudo yunohost service add ynh-ghostblog -l $logfile
echo "Setting up logrotate configuration..." # Create a temporary directory
sed -i "s@YNH_LOGFILE@$logfile@g" ../conf/logrotate tmpdir="$(mktemp -d)"
sudo cp ../conf/logrotate /etc/logrotate.d/ynh-ghostblog # Backup the content folder to the temp dir
cp -ar "$final_path/ghost/content" "$tmpdir"
echo "Nginx configuration (sso disabled)..." # Download, check integrity, uncompress and patch the source from app.src
sed -i "s@YNH_LOCATION@$path@g" ../conf/nginx.conf ynh_setup_source "$final_path"
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/ghostblog.conf
sudo yunohost app setting ghostblog skipped_uris -v "/"
echo "Reloading Nginx (sso disabled)..." # copy content folder back to the final_path
sudo service nginx reload sudo cp -ar "$tmpdir/content" "${final_path}"
sudo yunohost app ssowatconf
echo "Success ! You can go to https://$domain$path/ghost to write your posts" #=================================================
# SPECIFIC SETUP
#=================================================
# Copy configuration file
cp ../conf/config.production.json "$final_path/config.production.json"
# Install the dependencies with yarn
(
cd "$final_path"
yarn install
yarn global add knex-migrator
)
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/config.production.json"
ynh_replace_string "__PATH__" "path_url" "$final_path/config.production.json"
ynh_replace_string "__DBNAME__" "$db_name" "$final_path/config.production.json"
ynh_replace_string "__DBPWD__" "$db_pwd" "$final_path/config.production.json"
ynh_replace_string "__PORT__" "$port" "$final_path/config.production.json"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
if [ "$path_url" != "/" ]
then
ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
fi
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# SPECIFIC UPGRADE
#=================================================
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different "$final_path/config.production.json"
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.production.json"
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config
systemctl start "$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set right permissions for curl installation
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
#=================================================
systemctl reload nginx