diff --git a/conf/systemd.service b/conf/systemd.service index b73e479..541af5e 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,14 +7,8 @@ Type=simple User=__APP__ Group=__APP__ -Environment="APP_BASE_URL=https://__DOMAIN__" -Environment="APP_PORT=__PORT__" -Environment="DB_CLIENT=pg" -Environment="POSTGRES_PASSWORD=__DB_PWD__" -Environment="POSTGRES_DATABASE=__DB_NAME__" -Environment="POSTGRES_USER=__DB_USER__" -Environment="POSTGRES_PORT=5432" -Environment="POSTGRES_HOST=localhost" +Environment="__YNH_NODE_LOAD_PATH__" +EnvironmentFile=__INSTALL_DIR__/.env WorkingDirectory=__INSTALL_DIR__/ ExecStart=/usr/bin/yarn __INSTALL_DIR__/packages/server start diff --git a/doc/POST_INSTALL.md b/doc/POST_INSTALL.md index 8601988..f3db3c7 100644 --- a/doc/POST_INSTALL.md +++ b/doc/POST_INSTALL.md @@ -1,4 +1,8 @@ -Default credentials: +Now login to Joplin + - Url: https://__DOMAIN____PATH__ + - Email: __ADMIN_MAIL__ + - Password: __ADMIN_PASS__ -Email: admin@localhost -Password: admin \ No newline at end of file +Then you may change the default password at this page: https://__DOMAIN____PATH__/admin/users + +Then download one of these Joplin apps and configure the synchronisation with your server: https://joplinapp.org/help/install/ diff --git a/manifest.toml b/manifest.toml index feea726..223996d 100644 --- a/manifest.toml +++ b/manifest.toml @@ -38,6 +38,9 @@ ram.runtime = "50M" type = "group" default = "visitors" + [install.admin] + type = "user" + [resources] [resources.sources] @@ -63,7 +66,7 @@ ram.runtime = "50M" main.default = 22300 [resources.apt] - packages = "postgresql, postgresql-client" + packages = "postgresql, postgresql-client, python3-bcrypt" extras.yarn.repo = "deb https://dl.yarnpkg.com/debian/ stable main" extras.yarn.key = "https://dl.yarnpkg.com/debian/pubkey.gpg" extras.yarn.packages = "yarn" diff --git a/scripts/_common.sh b/scripts/_common.sh index 9195d57..c661840 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,6 +10,11 @@ nodejs_version=18 # PERSONAL HELPERS #================================================= +function bcrypt_password() { + echo -n "$1" | \ + python3 -c "import bcrypt; import sys; print(bcrypt.hashpw(bytes(sys.stdin.read(), 'ascii'), bcrypt.gensalt(rounds=10)).decode('ascii'))" +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 59c90ce..f11e868 100755 --- a/scripts/backup +++ b/scripts/backup @@ -34,7 +34,7 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= -# BACKUP THE MYSQL DATABASE +# BACKUP THE PostgreSQL DATABASE #================================================= ynh_print_info --message="Backing up the PostgreSQL database..." diff --git a/scripts/change_url b/scripts/change_url index ecb9a84..4f8a5e1 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -25,8 +25,12 @@ ynh_script_progression --message="Updating NGINX web server configuration..." -- ynh_change_url_nginx_config +ynh_use_nodejs + ynh_add_systemd_config +ynh_add_config --template=".env" --destination="$install_dir/.env" + #================================================= # GENERIC FINALISATION #================================================= diff --git a/scripts/install b/scripts/install index 2a06a84..4e03f33 100755 --- a/scripts/install +++ b/scripts/install @@ -9,6 +9,14 @@ source _common.sh source /usr/share/yunohost/helpers +admin_pass=$(ynh_string_random --length=24) +admin_mail=$(ynh_user_get_info --username=$admin --key="mail") +admin_name=$(ynh_user_get_info --username=$admin --key="fullname") + +# Store these values even if we don't need them, so they are printed in the post-install message +ynh_app_setting_set --app=$app --key=admin_pass --value=$admin_pass +ynh_app_setting_set --app=$app --key=admin_mail --value=$admin_mail + #================================================= # INSTALL DEPENDENCIES #================================================= @@ -57,11 +65,12 @@ chown $app:$app "$install_dir/.env" #================================================= # INSTALL JOPLIN #================================================= -ynh_script_progression --message="Installing $app..." --weight=10 +ynh_script_progression --message="Building $app..." --weight=10 -pushd $install_dir +pushd $install_dir/packages/server ynh_use_nodejs sudo -u $app env $ynh_node_load_PATH BUILD_SEQUENCIAL=1 yarn install --inline-builds + sudo -u $app env $ynh_node_load_PATH yarn build sudo -u $app env $ynh_node_load_PATH yarn cache clean ynh_secure_remove .yarn/berry popd @@ -74,7 +83,20 @@ popd ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Starting services..." + +#================================================= +# CHANGING DEFAULT ADMIN PASSWORD +#================================================= +ynh_script_progression --message="Changing default admin password..." --weight=1 + +hashed_pwd=$(bcrypt_password "$admin_pass") + +ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" <<< " + UPDATE users + SET password='$hashed_pwd', email='$admin_mail', full_name='$admin_name' + WHERE email='admin@localhost' +" #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index e89b8f0..c9b4674 100755 --- a/scripts/restore +++ b/scripts/restore @@ -20,7 +20,7 @@ ynh_restore_file --origin_path="$install_dir" chown -R $app:www-data "$install_dir" #================================================= -# RESTORE THE MYSQL DATABASE +# RESTORE THE PostgreSQL DATABASE #================================================= ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 diff --git a/scripts/upgrade b/scripts/upgrade index c95d7e8..57185a6 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -42,6 +42,22 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=5 # Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +#================================================= +# BUILD +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Building $app..." --weight=10 + pushd $install_dir/packages/server + ynh_use_nodejs + sudo -u $app env $ynh_node_load_PATH BUILD_SEQUENCIAL=1 yarn install --inline-builds + sudo -u $app env $ynh_node_load_PATH yarn build + sudo -u $app env $ynh_node_load_PATH yarn cache clean + ynh_secure_remove .yarn/berry + popd +fi + #================================================= # REAPPLY SYSTEM CONFIGURATIONS #=================================================