diff --git a/conf/generate_password_hash.py b/conf/generate_password_hash.py new file mode 100644 index 0000000..6d45018 --- /dev/null +++ b/conf/generate_password_hash.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Permet de générer le hash pour le password +import sys +path=sys.argv[2] +sys.path.append(path) +from werkzeug.security import generate_password_hash +password=sys.argv[1] +print generate_password_hash(password) diff --git a/conf/nginx.conf b/conf/nginx.conf index 908219e..89aac79 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,5 +1,5 @@ location __PATH__ { - + client_max_body_size 20M; # Force usage of https if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; diff --git a/conf/systemd.service b/conf/systemd.service index 23b43e6..2fbfa40 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,5 +1,5 @@ [Unit] -Description=calibreweb +Description=__APP__ After=network.target [Service] @@ -7,7 +7,7 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=/usr/bin/python __FINALPATH__/cps.py +ExecStart=/bin/sh -c '/usr/bin/python __FINALPATH__/cps.py >> /var/log/__APP__/__APP__.log 2>&1' [Install] WantedBy=multi-user.target diff --git a/manifest.json b/manifest.json index ee799fa..8f8d653 100644 --- a/manifest.json +++ b/manifest.json @@ -41,6 +41,18 @@ "example": "/calibre", "default": "/calibre" }, + { + "name": "calibre_path", + "ask": { + "en": "Select the folder containing the library", + "fr": "Choisissez le répertoire contenant la bibliothèque" + }, + "help": { + "en": "This folder should have read write access. It will be created if it does not exist.", + "fr": "Le répertoire doit être accesible en lecture écriture, il sera créé s'il n'existe pas.." + }, + "example": "/home/johndoe/calibre" + }, { "name": "admin", "type": "user", @@ -50,6 +62,15 @@ }, "example": "johndoe" }, + { + "name": "language", + "ask": { + "en": "Select a default language (you may change it later in the app", + "fr": "Choisissez une langue par défaur (vous pourre la changer ultérieurement dans l'application" + }, + "choices": [ "fr", "en", "es", "de"], + "default": "fr" + }, { "name": "is_public", "type": "boolean", diff --git a/scripts/_common.sh b/scripts/_common.sh index bb04a03..18e1f75 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,13 +1,4 @@ #!/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 -} \ No newline at end of file +pkg_dependencies="sqlite3" + diff --git a/scripts/install b/scripts/install index 6e8b3aa..7ef6a73 100755 --- a/scripts/install +++ b/scripts/install @@ -27,6 +27,8 @@ is_public=$YNH_APP_ARG_IS_PUBLIC #language=$YNH_APP_ARG_LANGUAGE #password=$YNH_APP_ARG_PASSWORD app=$YNH_APP_INSTANCE_NAME +calibre_dir=$3 +lang=$5 #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS @@ -60,11 +62,6 @@ ynh_app_setting_set $app is_public $is_public # FIND AND OPEN A PORT #================================================= -### Use these lines if you have to open a port for the application -### `ynh_find_port` will find the first available port starting from the given port. -### If you're not using these lines: -### - Remove the section "CLOSE A PORT" in the remove script - # Find a free port port=$(ynh_find_port 8083) # Open this port @@ -75,10 +72,6 @@ ynh_app_setting_set $app port $port # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -### `ynh_setup_source` is used to install an app from a zip or tar.gz file, -### downloaded from an upstream source, like a git repository. -### `ynh_setup_source` use the file conf/app.src - 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" @@ -88,24 +81,14 @@ ynh_setup_source "$final_path" # INSTALL DEPENDENCIES #================================================= -### `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 -### - As well as the section "REINSTALL DEPENDENCIES" in the restore script -### - And the section "UPGRADE DEPENDENCIES" in the upgrade script - -#ynh_install_app_dependencies deb1 deb2 +ynh_install_app_dependencies $pkg_dependencies pip install --target $final_path/vendor -r $final_path/requirements.txt - #================================================= # NGINX CONFIGURATION #================================================= -### `ynh_add_nginx_config` will use the file conf/nginx.conf - # Create a dedicated nginx config ynh_add_nginx_config @@ -120,48 +103,21 @@ ynh_system_user_create $app #================================================= # SPECIFIC SETUP #================================================= -# ... +# SET SQLITE DATABASE SETTINGS #================================================= +sqlite3 $final_path/app.db "UPDATE settings SET config_calibre_dir=\"$calibre_path\" WHERE ID=1" +sqlite3 $final_path/app.db "UPDATE settings SET config_port=$port WHERE ID=1" +sqlite3 $final_path/app.db "UPDATE user SET nickname=\"$admin\" WHERE ID=1" +sqlite3 $final_path/app.db "UPDATE user SET default_language=\"$lang\" WHERE ID=1" +sqlite3 $final_path/app.db "UPDATE user SET password='$(python ../conf/generate_password_hash.py $password $final_path/vendor)' WHERE ID=1" #================================================= # SETUP SYSTEMD #================================================= -### `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 - -#================================================= -# MODIFY A CONFIG FILE -#================================================= - -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) - -#ynh_replace_string "match_string" "replace_string" "$final_path/CONFIG_FILE" - -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -### `ynh_store_file_checksum` is used to store the checksum of a file. -### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`, -### you can make a backup of this file before modifying it again if the admin had modified it. - -# Calculate and store the config file checksum into the app settings -#ynh_store_file_checksum "$final_path/CONFIG_FILE" - #================================================= # GENERIC FINALIZATION #================================================= @@ -173,36 +129,23 @@ ynh_add_systemd_config ### that really need such authorization. # Set permissions to app files -chown -R root: $final_path +chown -R $app:$app $final_path + #================================================= # SETUP LOGROTATE #================================================= -### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. -### Use this helper only if there is effectively a log file for this app. -### If you're not using this helper: -### - Remove the section "BACKUP LOGROTATE" in the backup script -### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script -### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script -### - And the section "SETUP LOGROTATE" in the upgrade script - # Use logrotate to manage application logfile(s) ynh_use_logrotate +chown -R $app:$app /var/log/$app + #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= -### `yunohost service add` is a CLI yunohost command to add a service in the admin panel. -### You'll find the service in the 'services' section of YunoHost admin panel. -### This CLI command would be useless if the app does not have any services (systemd or sysvinit) -### If you're not using these lines: -### - You can remove these files in conf/. -### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script -### - As well as the section ADVERTISE SERVICE IN ADMIN PANEL" in the restore script - -#yunohost service add NAME_INIT.D --log "/var/log/FILE.log" +yunohost service add $app --log "/var/log/$app/$app.log" #================================================= # SETUP SSOWAT @@ -220,3 +163,4 @@ fi #================================================= systemctl reload nginx +systemctl start $app \ No newline at end of file