1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/archivebox_ynh.git synced 2024-09-03 18:15:54 +02:00

Working ynh

This commit is contained in:
mhfowler 2021-08-18 12:15:22 +02:00
parent 346cfbf3bb
commit b22cb373fc
9 changed files with 61 additions and 179 deletions

View file

@ -1,7 +0,0 @@
SOURCE_URL=url of app's source
SOURCE_SUM=sha256 checksum
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

View file

@ -1,33 +1,24 @@
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ {
# Path to source
alias __FINALPATH__/ ;
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
rewrite ^ https://$server_name$request_uri? permanent;
}
### Example PHP configuration (remove it if not used)
index index.php;
# Common parameter to increase upload size limit in conjunction with dedicated php-fpm file
#client_max_body_size 50M;
try_files $uri $uri/ index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
### End of PHP configuration part
proxy_set_header Accept-Encoding "";
try_files $uri @proxy;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}
location @proxy {
proxy_pass http://127.0.0.1:__PORT__;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Proxy "";
proxy_pass_header Server;
}

View file

@ -1,3 +1,3 @@
#!/usr/bin/env bash
/var/www/example/venv/bin/activate
archivebox server
__FINALPATH__/venv/bin/activate
archivebox server __PORT__

View file

@ -5,7 +5,7 @@
#=================================================
# dependencies used by the app
pkg_dependencies="python3-venv"
pkg_dependencies="python3-venv expect"
#=================================================
# PERSONAL HELPERS

View file

@ -31,7 +31,6 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
@ -62,12 +61,6 @@ ynh_backup --src_path="$datadir" --is_big
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#=================================================
# BACKUP FAIL2BAN CONFIGURATION
#=================================================
@ -93,20 +86,8 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/cron.d/$app"
ynh_backup --src_path="/etc/$app/"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
### (However, things like MySQL dumps *do* take some time to run, though the
### copy of the generated dump to the archive still happens later)
ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -29,10 +29,6 @@ ynh_script_progression --message="Loading installation settings..." --time --wei
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Add settings here as needed by your application
#db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#db_user=$db_name
#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
@ -105,12 +101,6 @@ then
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# ...
#=================================================
#=================================================
# GENERIC FINALISATION
#=================================================

View file

@ -31,6 +31,8 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
password=$YNH_APP_ARG_PASSWORD
admin_mail=$(ynh_user_get_info $admin 'mail')
### If it's 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"...)
@ -95,7 +97,7 @@ ynh_app_setting_set --app=$app --key=port --value=$port
# Optional: Expose this port publicly
# (N.B.: you only need to do this if the app actually needs to expose the port publicly.
# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
# TODO: test without this line
# Open the port
ynh_script_progression --message="Configuring firewall..." --time --weight=1
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
@ -105,14 +107,6 @@ ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
#=================================================
ynh_script_progression --message="Installing dependencies..." --time --weight=1
### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package.
### Those deb packages will be installed as dependencies of this package.
### If you're not using this helper:
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
### - Remove the variable "pkg_dependencies" in _common.sh
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
ynh_install_app_dependencies $pkg_dependencies
#=================================================
@ -123,26 +117,6 @@ ynh_script_progression --message="Configuring system user..." --time --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
# TODO: remove mysql section
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
#ynh_script_progression --message="Creating a MySQL database..." --time --weight=1
### Use these lines if you need a database for the application.
### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password.
### The password will be stored as 'mysqlpwd' into the app settings,
### and will be available as $db_pwd
### If you're not using these lines:
### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script
### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script
### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script
#db_name=$(ynh_sanitize_dbid --db_name=$app)
#db_user=$db_name
#ynh_app_setting_set --app=$app --key=db_name --value=$db_name
#ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@ -180,9 +154,6 @@ ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# ...
#=================================================
#=================================================
# PIP INSTALLATION
#=================================================
@ -191,6 +162,8 @@ ynh_script_progression --message="Install project via pip..." --weight=80
python3 -m venv "${final_path}/venv"
cp ../conf/requirements.txt "$final_path/requirements.txt"
cp ../conf/start.sh "$final_path/start.sh"
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/start.sh"
ynh_replace_string "__PORT__" "$port" "$final_path/start.sh"
chmod 760 "$final_path/start.sh"
chown -R "$app" "$final_path"
@ -201,7 +174,6 @@ chown -R "$app" "$final_path"
set -o nounset
ynh_exec_as $app $final_path/venv/bin/pip install --upgrade pip
ynh_exec_as $app $final_path/venv/bin/pip install -r "$final_path/requirements.txt"
# ynh_exec_as $app $final_path/venv/bin/pip install --upgrade "$pip_install_string"
)
#=================================================
@ -209,24 +181,12 @@ chown -R "$app" "$final_path"
#=================================================
ynh_script_progression --message="Creating a data directory..." --time --weight=1
### Use these lines if you need to create a directory to store "persistent files" for the application.
### Usually this directory is used to store uploaded files or any file that won't be updated during
### an upgrade and that won't be deleted during app removal
### If you're not using these lines:
### - Remove the section "BACKUP THE DATA DIR" in the backup script
### - As well as the section "RESTORE THE DATA DIRECTORY" in the restore script
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir
# FIXME: this should be managed by the core in the future
# Here, as a packager, you may have to tweak the ownerhsip/permissions
# such that the appropriate users (e.g. maybe www-data) can access
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
# permissions
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
@ -235,7 +195,43 @@ chown -R $app:www-data "$datadir"
#=================================================
# INITIALIZE ARCHIVEBOX
#=================================================
#cd $datadir && ynh_exec_as $app archivebox manage createsuperuser --noinput --username archivebox2 --email max@mfowler.info
ynh_script_progression --message="Initializing Archivebox" --time --weight=1
cd $datadir && ynh_exec_as $app archivebox init
ynh_script_progression --message="Checking if admin superuser already exists: $admin" --time --weight=1
USER_EXISTS=$(cd $datadir && ynh_exec_as $app archivebox manage shell -c "from django.contrib.auth.models import User; print(User.objects.filter(username='$admin').count())")
ynh_script_progression --message="Found users: $USER_EXISTS" --time --weight=1
if [ $USER_EXISTS -eq 1 ]
then
ynh_script_progression --message="User already exists: setting admin password" --time --weight=1
ynh_exec_as $app /usr/bin/expect<<EOF
set force_conservative 0 ;
set timeout -1
spawn sh -c "cd $datadir && archivebox manage changepassword $admin"
match_max 100000
expect "*?assword: "
send -- "$password\r"
expect "*?assword (again): "
send -- "$password\r"
expect eof
EOF
else
ynh_script_progression --message="Creating new archivebox superuser: $admin" --time --weight=1
ynh_exec_as $app /usr/bin/expect<<EOF
set force_conservative 0 ;
set timeout -1
spawn sh -c "cd $datadir && archivebox manage createsuperuser --username $admin --email $admin_mail"
match_max 100000
expect "*?assword: "
send -- "$password\r"
expect "*?assword (again): "
send -- "$password\r"
expect eof
EOF
fi
ynh_script_progression --message="Finishing Archivebox Setup" --time --weight=1
cd $datadir && ynh_exec_as $app archivebox init --setup
#=================================================
@ -275,41 +271,9 @@ ynh_script_progression --message="Adding a configuration file..." --time --weigh
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --time --weight=1
### `ynh_systemd_config` is used to configure a systemd script for an app.
### It can be used for apps that use sysvinit (with adaptation) or systemd.
### Have a look at the app to be sure this app needs a systemd script.
### `ynh_systemd_config` will use the file conf/systemd.service
### If you're not using these lines:
### - You can remove those files in conf/.
### - Remove the section "BACKUP SYSTEMD" in the backup script
### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script
### - As well as the section "RESTORE SYSTEMD" in the restore script
### - And the section "SETUP SYSTEMD" in the upgrade script
# Create a dedicated systemd config
ynh_add_systemd_config
##=================================================
## SETUP APPLICATION WITH CURL
##=================================================
#
#### Use these lines only if the app installation needs to be finalized through
#### web forms. We generally don't want to ask the final user,
#### so we're going to use curl to automatically fill the fields and submit the
#### forms.
#
## Set the app as temporarily public for curl call
#ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
## Making the app public for curl
#ynh_permission_update --permission="main" --add="visitors"
#
## Installation with curl
#ynh_script_progression --message="Finalizing installation..." --time --weight=1
#ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
#
## Remove the public access
#ynh_permission_update --permission="main" --remove="visitors"
#=================================================
# GENERIC FINALIZATION
#=================================================

View file

@ -31,9 +31,6 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
@ -99,13 +96,6 @@ chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the PHP-FPM configuration..." --time --weight=1
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
@ -125,24 +115,6 @@ ynh_script_progression --message="Reinstalling dependencies..." --time --weight=
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --time --weight=1
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..." --time --weight=1
ynh_restore_file --origin_path="/etc/cron.d/$app"
ynh_restore_file --origin_path="/etc/$app/"
#=================================================
# RESTORE SYSTEMD
#=================================================
@ -179,7 +151,6 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --time --weight=1
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload
#=================================================

View file

@ -146,19 +146,11 @@ ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --time --weight=1
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
#=================================================
# TODO: how do we upgrade archivebox?
#=================================================
# UPDATE A CONFIG FILE