diff --git a/README.md b/README.md index 8deb0e7..dcf374a 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,8 @@ https://example.com/odoo/ will NOT work What does not work ------------------ -- Automatic database creation (experimental) - Backup and restore via Odoo (works with a trick shared on the Github) - Backup and restore via YunoHost -- Automatic LDAP configuration Still to do ----------- @@ -37,18 +35,6 @@ Still to do Configuration ------------- -**Create the database manually** -- The database must be named "*subdomain-domain-tld*" (for example *erp-test-com* if you access the database via *erp.test.com* - -**Setup LDAP** -- Create a user named "template" with email "template". This user will give its permissions by default to YunoHost users so you can also give it appropriate permissions. -- In "Edit Company Data" (on the logo), go to "Configuration" and add a LDAP setting -- LDAP Address: localhost -- LDAP Port: 389 -- LDAP Base: ou=users, dc=yunohost,dc=org -- LDAP filter: uid=%s -- Template user: template -- Save **Backup via Odoo** - In YunoHost, open the port 8069 diff --git a/check_process b/check_process new file mode 100644 index 0000000..594f369 --- /dev/null +++ b/check_process @@ -0,0 +1,37 @@ +;; Test complet sans multisite + auto_remove=1 + ; Manifest + domain="domain.tld" (DOMAIN) + version="10.0" + oca=0 + admin_password="testpassw0rD" + lang="en_US" + tz="Europe/Paris" + ; Checks + pkg_linter=1 + setup_sub_dir=0 + setup_root=1 + setup_nourl=0 + setup_private=0 + setup_public=1 + upgrade=1 + backup_restore=1 + multi_instance=1 + wrong_user=0 + wrong_path=0 + incorrect_path=0 + corrupt_source=1 + fail_download_source=1 + port_already_use=1 + final_path_already_use=0 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto + Level 4=0 + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..e6ac2c2 --- /dev/null +++ b/conf/app.src @@ -0,0 +1,5 @@ +SOURCE_URL=http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz +SOURCE_SUM=049b2cdec9a8254f0ef8ac273afaf54f7e25459a273e27189591edc7d7cf29db +SOURCE_FILE=wkhtmltox-0.12.4_linux-generic-amd64.tar.xz +SOURCE_FORMAT=tar.xz +SOURCE_SUM_PRG=sha256sum diff --git a/conf/install_database.py b/conf/install_database.py deleted file mode 100644 index 80dd07d..0000000 --- a/conf/install_database.py +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/python -import oerplib -oerp = oerplib.OERP(server='localhost', protocol='xmlrpc', port=8069) -oerp.db.create_database('ADMIN_PASSWORD', 'DOMAIN_DATABASE', False, 'DATABASE_LANG', 'DATABASE_PASSWORD') \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf.j2 similarity index 82% rename from conf/nginx.conf rename to conf/nginx.conf.j2 index 90d828a..623dce2 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf.j2 @@ -2,10 +2,10 @@ location / { if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } - try_files $uri @#YNH_APP_INSTANCE_NAME#; + try_files $uri @{{ app }}; } -location @#YNH_APP_INSTANCE_NAME# { - proxy_pass http://127.0.0.1:8069; +location @{{ app }} { + proxy_pass http://127.0.0.1:{{ port }}; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_buffers 16 64k; proxy_buffer_size 128k; diff --git a/conf/openerp-server.conf b/conf/openerp-server.conf.j2 similarity index 56% rename from conf/openerp-server.conf rename to conf/openerp-server.conf.j2 index f6b8a4a..742a9e5 100644 --- a/conf/openerp-server.conf +++ b/conf/openerp-server.conf.j2 @@ -1,11 +1,11 @@ [options] ; This is the password that allows database operations: without_demo = all -admin_passwd = ADMIN_PASSWORD +admin_passwd = {{ admin_password }} db_host = false db_port = false db_user = odoo -db_password = DATABASE_PASSWORD -addons_path = /usr/lib/python2.7/dist-packages/openerp/addons +db_password = {{ dbpass }} +addons_path = {{ source_path }}addons proxy_mode = true dbfilter = %h diff --git a/manifest.json b/manifest.json index 2ce179b..e1e4fb1 100644 --- a/manifest.json +++ b/manifest.json @@ -10,10 +10,11 @@ "name": "scith, ljf", "email": "ljf+yunohost@grimaud.me" }, + "version": "10.0-1", "url": "https://www.odoo.com", - "license": "free", + "license": "LGPL-3.0", "requirements": { - "yunohost": ">= 2.4.0" + "yunohost": ">= 2.6.0" }, "multi_instance": true, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh index 7ca8ef5..2228359 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,113 +4,121 @@ APPNAME="odoo" - -# Package name for dependencies -DEPS_PKG_NAME="${APPNAME}-deps" - -# Remote URL to fetch tarball -SOURCE_URL="http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz" - -# Remote URL to fetch tarball checksum -SOURCE_SHA256="049b2cdec9a8254f0ef8ac273afaf54f7e25459a273e27189591edc7d7cf29db" - -# App package root directory should be the parent folder -PKGDIR=$(cd ../; pwd) - -# -# Common helpers -# - -# # Execute a command as root user -# -# usage: ynh_psql_execute_as_root sql [db] -# | arg: sql - the SQL command to execute -# | arg: db - the database to connect to -ynh_psql_execute_as_root () { - sudo su -c "psql" - postgres <<< ${1} -} - -# Create a user -# -# usage: ynh_psql_create_user user pwd [host] -# | arg: user - the user name to create -# | arg: pwd - the password to identify user by -ynh_psql_create_user() { - ynh_psql_execute_as_root \ - "CREATE USER ${1} WITH PASSWORD '${2}';" -} - -# Create a database and grant optionnaly privilegies to a user -# -# usage: ynh_psql_create_db db [user [pwd]] -# | arg: db - the database name to create -# | arg: user - the user to grant privilegies -# | arg: pwd - the password to identify user by -ynh_psql_create_db() { - db=$1 - # grant all privilegies to user - if [[ $# -gt 1 ]]; then - ynh_psql_create_user ${2} "${3}" - sudo su -c "createdb -O ${2} $db" - postgres +function define_paths() { + # In odoo 10 some file change + if [ $(echo "$odoo_version >= 10" | bc) -ne 0 ]; then + export source_path=/usr/lib/python2.7/dist-packages/odoo/ + conf_file=/etc/odoo/odoo.conf + bin_file=/usr/bin/odoo else - sudo su -c "createdb $db" - postgres + export source_path=/usr/lib/python2.7/dist-packages/openerp/ + conf_file=/etc/odoo/openerp-server.conf + bin_file=/usr/bin/openerp-server + fi +} + +function check_odoo_version () { + if [ $(echo "$odoo_version >= 10" | bc) -ne 0 ]; then + if [ -f /usr/bin/openerp-server ]; then + ynh_die "Another version of odoo is installed" + fi + else + if [ -f /usr/bin/odoo ]; then + ynh_die "Another version of odoo is installed" + fi + fi +} + +function define_is_master() { + if [ -f $bin_file ]; then + export is_master=false + else + export is_master=true + fi +} + +function define_port () { + if [ "$is_master" = true ]; then + export port=$(ynh_find_port 8069) + yunohost app checkport $port + if [[ ! $? -eq 0 ]]; then + ynh_die "Port 8069 unavailable" 1 + fi + else + # FIXME find master port + export port="8069" + fi +} + +function define_dbpass () { + # TODO set -x + if [ "$is_master" = true ]; then + # Generate random password + if [ "${1:-}" = "restore" ]; then + export dbpass=$(ynh_app_setting_get $app psqlpwd) + else + export dbpass=$(ynh_string_random) + fi + else + export dbpass=$(grep db_password /etc/odoo/odoo.conf | cut -d \= -f 2 | sed -e 's/^[ \t]*//') + fi + ynh_app_setting_set "$app" psqlpwd "$dbpass" +} + +# Install dependencies +function install_dependencies() { + if [ ! -f /etc/apt/sources.list.d/odoo.list ]; then + # Install Odoo + # Prepare installation + ynh_package_install curl + + # Install Odoo + curl -sS https://nightly.odoo.com/odoo.key | sudo apt-key add - + sh -c "echo 'deb http://nightly.odoo.com/${odoo_version}/nightly/deb/ ./' > /etc/apt/sources.list.d/odoo.list" + # TODO if 8.0 install https://www.odoo.com/apps/modules/8.0/shell/ fi -} + apt-get update -# Drop a database -# -# usage: ynh_psql_drop_db db -# | arg: db - the database name to drop -ynh_psql_drop_db() { - sudo su -c "dropdb ${1}" - postgres -} + ynh_install_app_dependencies curl postgresql odoo xfonts-75dpi xfonts-base wkhtmltopdf node-less python-xlrd -# Drop a user -# -# usage: ynh_psql_drop_user user -# | arg: user - the user name to drop -ynh_psql_drop_user() { - sudo su -c "dropuser ${1}" - postgres + if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then + # The debian package has a bug so we deploy a more recent version + ynh_setup_source /usr/ + fi } -# Download and extract sources to the given directory -# usage: extract_sources DESTDIR [AS_USER] -extract_sources() { - local DESTDIR=$1 - local AS_USER=${2:-admin} - - # retrieve and extract Roundcube tarball - tarball="/tmp/${APPNAME}.tar.xz" - rm -f "$tarball" - wget -q -O "$tarball" "$SOURCE_URL" \ - || ynh_die "Unable to download tarball" - echo "$SOURCE_SHA256 $tarball" | sha256sum -c >/dev/null \ - || ynh_die "Invalid checksum of downloaded tarball" - exec_as "$AS_USER" tar xJf "$tarball" -C "$DESTDIR" --strip-components 1 \ - || ynh_die "Unable to extract tarball" - rm -f "$tarball" - - # apply patches - if [[ -d "${PKGDIR}/patches" ]]; then - (cd "$DESTDIR" \ - && for p in ${PKGDIR}/patches/*.patch; do \ - exec_as "$AS_USER" patch -p1 < $p; done) \ - || ynh_die "Unable to apply patches" - fi +# Create db +function create_general_db() { + service postgresql reload + if ! su -c "psql -lqt | cut -d \| -f 1 " - postgres | grep $APPNAME; then + # Generate random password + ynh_psql_execute_as_root "ALTER USER $APPNAME WITH CREATEDB;" + ynh_psql_execute_as_root "ALTER USER $APPNAME WITH PASSWORD '$dbpass';" + su -c "createdb -O $APPNAME $APPNAME" - postgres + fi } -# Execute a command as another user -# usage: exec_as USER COMMAND [ARG ...] -exec_as() { - local USER=$1 - shift 1 - - if [[ $USER = $(whoami) ]]; then - eval "$@" - else - # use sudo twice to be root and be allowed to use another user - sudo sudo -u "$USER" "$@" - fi +# Add services +function add_services() { + if ! grep "^postgresql:$" /etc/yunohost/services.yml; then + yunohost service add postgresql + fi + if ! grep "^odoo:$" /etc/yunohost/services.yml; then + yunohost service add odoo --log /var/log/odoo/odoo-server.log + yunohost service stop odoo + yunohost service start odoo + fi +} + +function ssowat_and_restart() { + # Restart odoo service + service odoo restart + + # Configure SSOWat + ynh_sso_access "/web/database/manager" + + # Reload services + service nginx reload } diff --git a/scripts/_future.sh b/scripts/_future.sh new file mode 100644 index 0000000..d68da67 --- /dev/null +++ b/scripts/_future.sh @@ -0,0 +1,205 @@ + +log() { + echo "${1}" +} + +info() { + log "[INFO] ${1}" +} + +warn() { + log "[WARN] ${1}" +} + +err() { + log "[ERR] ${1}" +} +ynh_check_var () { + test -n "$1" || ynh_die "$2" +} + +ynh_exit_properly () { + exit_code=$? + if [ "$exit_code" -eq 0 ]; then + exit 0 + fi + trap '' EXIT + set +eu + echo -e "\e[91m \e[1m" + err "$app script has encountered an error." + + if type -t CLEAN_SETUP > /dev/null; then + CLEAN_SETUP + fi + + ynh_die +} + +# Activate signal capture +# Exit if a command fail, and if a variable is used unset. +# Capturing exit signals on shell script +# +# example: CLEAN_SETUP () { +# # Clean residual file un remove by remove script +# } +# ynh_trap_on +ynh_trap_on () { + set -eu + trap ynh_exit_properly EXIT # Capturing exit signals on shell script +} + +ynh_export () { + local ynh_arg="" + for var in $@; + do + ynh_arg=$(echo $var | awk '{print toupper($0)}') + ynh_arg="YNH_APP_ARG_$ynh_arg" + export $var=${!ynh_arg} + done +} + +# Save listed var in YunoHost app settings +# usage: ynh_save_args VARNAME1 [VARNAME2 [...]] +ynh_save_args () { + for var in $@; + do + ynh_app_setting_set $app $var ${!var} + done +} + +ynh_sso_access () { + ynh_app_setting_set $app unprotected_uris "/" + + if [[ $is_public -eq 0 ]]; then + ynh_app_setting_set $app protected_uris "$1" + fi + sudo yunohost app ssowatconf +} +ynh_configure () { + local TEMPLATE=$1 + local DEST=$2 + type j2 2>/dev/null || sudo pip install j2cli + j2 "${YNH_CWD}/../conf/$TEMPLATE.j2" > "${YNH_CWD}/../conf/$TEMPLATE" + sudo cp "${YNH_CWD}/../conf/$TEMPLATE" "$DEST" +} + +ynh_configure_nginx () { + ynh_configure nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf + sudo service nginx reload +} +# Find a free port and return it +# +# example: port=$(ynh_find_port 8080) +# +# usage: ynh_find_port begin_port +# | arg: begin_port - port to start to search +ynh_find_port () { + port=$1 + test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port." + while netcat -z 127.0.0.1 $port # Check if the port is free + do + port=$((port+1)) # Else, pass to next port + done + echo $port +} + +ynh_rm_nginx_conf () { + if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then + sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" + sudo service nginx reload + fi +} + + +ynh_secure_rm () { + [[ "/var/www /opt /home/yunohost.app" =~ $1 ]] \ + || (test -n "$1" && sudo rm -Rf $1 ) +} + +# Upgrade +ynh_read_json () { + python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" +} + +ynh_read_manifest () { + if [ -f '../manifest.json' ] ; then + ynh_read_json '../manifest.json' "$1" + else + ynh_read_json '../settings/manifest.json' "$1" + fi +} +ynh_exit_if_up_to_date () { + if [ "${version}" = "${last_version}" ]; then + info "Up-to-date, nothing to do" + exit 0 + fi +} + + +# # Execute a command as root user +# +# usage: ynh_psql_execute_as_root sql [db] +# | arg: sql - the SQL command to execute +# | arg: db - the database to connect to +ynh_psql_execute_as_root () { + sudo su -c "psql" - postgres <<< ${1} +} + +# Create a user +# +# usage: ynh_psql_create_user user pwd [host] +# | arg: user - the user name to create +# | arg: pwd - the password to identify user by +ynh_psql_create_user() { + ynh_psql_execute_as_root \ + "CREATE USER ${1} WITH PASSWORD '${2}';" +} + +# Create a database and grant optionnaly privilegies to a user +# +# usage: ynh_psql_create_db db [user [pwd]] +# | arg: db - the database name to create +# | arg: user - the user to grant privilegies +# | arg: pwd - the password to identify user by +ynh_psql_create_db() { + db=$1 + # grant all privilegies to user + if [[ $# -gt 1 ]]; then + ynh_psql_create_user ${2} "${3}" + sudo su -c "createdb -O ${2} $db" - postgres + else + sudo su -c "createdb $db" - postgres + fi + +} + +# Drop a database +# +# usage: ynh_psql_drop_db db +# | arg: db - the database name to drop +ynh_psql_drop_db() { + sudo su -c "dropdb ${1}" - postgres +} + +# Drop a user +# +# usage: ynh_psql_drop_user user +# | arg: user - the user name to drop +ynh_psql_drop_user() { + sudo su -c "dropuser ${1}" - postgres +} + + +# Execute a command as another user +# usage: exec_as USER COMMAND [ARG ...] +exec_as() { + local USER=$1 + shift 1 + + if [[ $USER = $(whoami) ]]; then + eval "$@" + else + # use sudo twice to be root and be allowed to use another user + sudo sudo -u "$USER" "$@" + fi +} diff --git a/scripts/backup b/scripts/backup index d0a137a..a97695a 100644 --- a/scripts/backup +++ b/scripts/backup @@ -3,22 +3,28 @@ # Exit on command errors and treat unset variables as an error set -eu -# See comments in install script -app=$YNH_APP_INSTANCE_NAME +source /usr/share/yunohost/helpers +#source _future.sh +source ../settings/scripts/_common.sh -# Source YunoHost helpers -. /usr/share/yunohost/helpers +app=$YNH_APP_INSTANCE_NAME +domain=$(ynh_app_setting_get "$app" domain) +odoo_version=$(ynh_app_setting_get "$app" odoo_version) + +define_paths # Backup sources & data -ynh_backup "/usr/lib/python2.7/dist-packages/openerp/" "sources" +ynh_backup "${source_path}addons" "$1${source_path}addons" + +# Backup configuration +ynh_backup "$conf_file" "$1$conf_file" # Copy NGINX configuration -domain=$(ynh_app_setting_get "$app" domain) -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" -ynh_backup "/etc/odoo/openerp-server.conf" "openerp-server.conf" +ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "etc/nginx/conf.d/${domain}.d/${app}.conf" + +# Save postgresql conf +ynh_backup "/etc/postgresql/9.4/main/pg_hba.conf" "etc/postgresql/9.4/main/pg_hba.conf" # Copy database database=${domain//./-} sudo su -c "pg_dump $database" postgres > ./dump.sql -pwd=`pwd` -ynh_backup "$pwd/dump.sql" "dump.sql" diff --git a/scripts/install b/scripts/install index 65091c9..7e68529 100644 --- a/scripts/install +++ b/scripts/install @@ -2,128 +2,66 @@ set -eu -app=$YNH_APP_INSTANCE_NAME +source /usr/share/yunohost/helpers +source _future.sh +source _common.sh -# Retrieve arguments -domain=$YNH_APP_ARG_DOMAIN -version=$YNH_APP_ARG_VERSION -oca=$YNH_APP_ARG_OCA -admin_password=$YNH_APP_ARG_ADMIN_PASSWORD -lang=$YNH_APP_ARG_LANG -tz=$YNH_APP_ARG_TZ +ynh_trap_on -# Load common variables -source ./_common.sh +# Arguments from manifest +export app=$YNH_APP_INSTANCE_NAME +export domain=$YNH_APP_ARG_DOMAIN +export odoo_version=$YNH_APP_ARG_VERSION +export oca=$YNH_APP_ARG_OCA +export admin_password=$YNH_APP_ARG_ADMIN_PASSWORD +export lang=$YNH_APP_ARG_LANG +export tz=$YNH_APP_ARG_TZ +export is_public=0 -# Source YunoHost helpers -. /usr/share/yunohost/helpers - -# Check domain/path availability -domain=${domain}"/" -sudo yunohost app checkurl $domain -a $app \ - || (ynh_die "Path not available: $domain" 1) - -# Remove trailing "/" for next commands -domain=${domain%/} - -# Generate random password -# Fix a bug on ynh_string_random https://github.com/YunoHost/yunohost/pull/205/commits/0d6cf499a0b858e7009245fd11a9210188047c13 -dbpass=$(ynh_string_random | sed "s/\[/e/g" | sed "s/\]/e/g") - -ynh_app_setting_set "$app" domain "$domain" -ynh_app_setting_set "$app" lang "$lang" -ynh_app_setting_set "$app" tz "$tz" -ynh_app_setting_set "$app" psqlpwd "$dbpass" +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS +#================================================= +ynh_check_var "$app" "app name not set" +ynh_webpath_available "$domain" "/" +check_odoo_version +define_paths +define_is_master +define_port +define_dbpass -if [ -f /usr/bin/openerp-server ]; then - echo "Odoo is already installed, switching to multi-instances" - ynh_app_setting_set "$app" instance "slave" - -else - sudo yunohost app checkport 8069 - if [[ ! $? -eq 0 ]]; then - ynh_die "Port 8069 unavailable" 1 - fi - - echo "Installing odoo" - - - ynh_app_setting_set "$app" version "$version" - ynh_app_setting_set "$app" instance "master" - - # Install Odoo - # Prepare installation - ynh_package_install curl - - # Install Odoo - sudo curl -sS https://nightly.odoo.com/odoo.key | sudo apt-key add - - sudo sh -c "echo 'deb http://nightly.odoo.com/${version}/nightly/deb/ ./' > /etc/apt/sources.list.d/odoo.list" - # TODO if 8.0 install https://www.odoo.com/apps/modules/8.0/shell/ - sudo apt-get update - - # Initialize installation - ynh_package_install postgresql - - ynh_package_install odoo - - # Install wkhtmltopdf to print PDF reports - ynh_package_install xfonts-75dpi xfonts-base wkhtmltopdf node-less python-xlrd - - # The debian package has a bug so we deploy a more recent version - DESTDIR="/tmp/wkhtmltox/" - sudo mkdir -p $DESTDIR - sudo chown -R $APPNAME: /tmp/wkhtmltox - extract_sources $DESTDIR "$APPNAME" - sudo cp -R "$DESTDIR." /usr/ - sudo rm -Rf $DESTDIR - - ynh_psql_execute_as_root "ALTER USER $APPNAME WITH CREATEDB;" - ynh_psql_execute_as_root "ALTER USER $APPNAME WITH PASSWORD '$dbpass';" - sudo su -c "createdb -O $APPNAME $APPNAME" - postgres - +#================================================= +# SETUP THE APP BY MODIFYING THE SYSTEM +#================================================= +function setup_files() { # Set admin password - # TODO Support @ in password - sudo sed -i "s@ADMIN_PASSWORD@$admin_password@g" ../conf/openerp-server.conf - sudo sed -i "s@DATABASE_PASSWORD@$dbpass@g" ../conf/openerp-server.conf - sudo cp ../conf/openerp-server.conf /etc/odoo/openerp-server.conf - sudo chown odoo:odoo /etc/odoo/openerp-server.conf + ynh_configure openerp-server.conf $conf_file + chown odoo:odoo $conf_file # Autoinstall the LDAP auth module - sudo sed -i "s@'auto_install': False@'auto_install': True@g" /usr/lib/python2.7/dist-packages/openerp/addons/auth_ldap/__openerp__.py + if [ $(echo "$odoo_version >= 10" | bc) -ne 0 ]; then + ynh_replace_string "^{$" "{'auto_install': True," ${source_path}addons/auth_ldap/__manifest__.py + else + ynh_replace_string "'auto_install': False" "'auto_install': True" ${source_path}addons/auth_ldap/__openerp__.py + fi - # Install oerplib to manage databases - #sudo pip install oerplib + # Fix peer authentification issue + sed -i '/local\s*all\s*all\s*peer/i \ + local all odoo password' /etc/postgresql/9.4/main/pg_hba.conf - # Add services - sudo yunohost service add postgresql - sudo yunohost service add odoo --log /var/log/odoo/odoo-server.log - sudo yunohost service stop odoo - sudo yunohost service start odoo -fi + ynh_configure_nginx +} -# Configure Nginx and reload -sed -i "s@#YNH_APP_INSTANCE_NAME#@${YNH_APP_INSTANCE_NAME}@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +function setup_database() { -# Make Odoo public -ynh_app_setting_set "$app" skipped_uris "/" + # Setup database: not working + database=${domain//./-} -sudo service nginx reload - -# Fix peer authentification issue -sudo sed -i '/local\s*all\s*all\s*peer/i \ -local all odoo password' /etc/postgresql/9.4/main/pg_hba.conf -sudo service postgresql reload - -# Setup database: not working -database=${domain//./-} - -# Load translation -sudo /usr/bin/openerp-server -c /etc/odoo/openerp-server.conf --stop-after-init -d $database -sudo /usr/bin/openerp-server -c /etc/odoo/openerp-server.conf --stop-after-init -d $database --load-language $lang -# Configure language, timezone and ldap -sudo /usr/bin/openerp-server shell -c /etc/odoo/openerp-server.conf -d $database <<< \ + # Load translation + $bin_file -c $conf_file --stop-after-init -i auth_ldap -d $database + $bin_file -c $conf_file --stop-after-init -d $database --load-language $lang + # Configure language, timezone and ldap + $bin_file shell -c $conf_file -d $database <<< \ " self.change_password('admin','$admin_password') self.env.cr.commit() @@ -149,5 +87,14 @@ self.company_id.ldaps.create({ }) self.env.cr.commit() " +} + +ynh_webpath_register "$app" "$domain" "/" +ynh_save_args domain odoo_version oca lang tz is_master port +install_dependencies +setup_files +create_general_db +add_services +setup_database +ssowat_and_restart -sudo service odoo restart diff --git a/scripts/remove b/scripts/remove index 2c3725a..59c84cf 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,42 +1,54 @@ #!/bin/bash -set -eu +set -u + +source /usr/share/yunohost/helpers +source _future.sh +source _common.sh app=$YNH_APP_INSTANCE_NAME -# Load common variables -source ./_common.sh - -# Source YunoHost helpers -. /usr/share/yunohost/helpers # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) - -database=${domain//./-} -instance=$(ynh_app_setting_get "$app" instance) - - -sudo yunohost service stop odoo | true -# If removing master instance, remove Odoo. -if [ "$instance" = "master" ]; then - sudo rm -f /etc/apt/sources.list.d/odoo.list - sudo apt-get update - sudo yunohost service remove odoo | true - ynh_package_remove odoo | true - sudo dpkg -P odoo | true - ynh_psql_drop_db $APPNAME | true +odoo_version=$(ynh_app_setting_get "$app" odoo_version) +if [ "$odoo_version" = "" ]; then + exit 0 fi +database=${domain//./-} +is_master=$(ynh_app_setting_get "$app" is_master) + +define_paths + +yunohost service stop odoo +list=$(yunohost app list --installed | grep odoo) +# If removing master instance, remove Odoo. +if [ $(echo $list | wc -l) = 1 ]; then + rm -f /etc/apt/sources.list.d/odoo.list + apt-get update + yunohost service remove odoo + ynh_psql_drop_db $APPNAME + #ynh_psql_drop_user $APPNAME +else + # Set another app as master + if [ "$is_master" = "true" ]; then + for instance in $list; do + if [ "$instance" != "$app" ]; then + ynh_app_setting_set "$instance" is_master "true" + break + fi + done + is_master="false" + fi +fi + +ynh_remove_app_dependencies # Remove database -ynh_psql_drop_db $database | true -ynh_psql_drop_user $database | true +ynh_psql_drop_db $database -if [ "$instance" = "slave" ]; then - sudo yunohost service start odoo | true +if [ "$is_master" = "false" ]; then + yunohost service start odoo fi -# Remove NGINX conf -sudo rm /etc/nginx/conf.d/$domain.d/$app.conf | true -# Reload -sudo service nginx reload -sudo yunohost app ssowatconf +# Remove NGINX conf +ynh_rm_nginx_conf diff --git a/scripts/restore b/scripts/restore index a47a836..1e4d71d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,3 +1,65 @@ #!/bin/bash -app=odoo -# TO BE DONE \ No newline at end of file +set -eu + +# Import helpers +source /usr/share/yunohost/helpers +source ../settings/scripts/_future.sh +source ../settings/scripts/_common.sh + +ynh_trap_on + +export app=$YNH_APP_INSTANCE_NAME +export domain=$(ynh_app_setting_get $app domain) +export odoo_version=$(ynh_app_setting_get $app odoo_version) +export oca=$(ynh_app_setting_get $app oca) +export port=$(ynh_app_setting_get $app port) +export is_public=0 + +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= +ynh_check_var "$app" "app name not set" +ynh_webpath_available "$domain" "/" +check_odoo_version +define_paths +define_is_master +define_port +define_dbpass restore + +#================================================= +# RESTORE THE APP BY MODIFYING THE SYSTEM +#================================================= +# Restore files +function restore_files () { + if [ "$is_master" = true ]; then + ynh_restore + else + # If odoo is already setup we just restore nginx and add some missing + # modules. Other files are already on system, and we don't want to + # erase it + + # Configure Nginx and reload + ynh_restore_file "/etc/nginx/conf.d/${domain}.d/${app}.conf" + + # TODO Restore plugin/addons + fi +} + +# Restore database +function restore_database () { + # Restore database + database=${domain//./-} + su -c "createdb -O $APPNAME $database" - postgres + su -c "psql $database" postgres < ./dump.sql +} + +ynh_save_args is_master port +install_dependencies +restore_files +create_general_db +add_services +restore_database +ssowat_and_restart + + + diff --git a/scripts/upgrade b/scripts/upgrade index a3df0a1..51aed46 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,14 +1,54 @@ #!/bin/bash + set -eu -app=$YNH_APP_INSTANCE_NAME # Source YunoHost helpers -. /usr/share/yunohost/helpers +source /usr/share/yunohost/helpers +source _future.sh +source _common.sh + +ynh_trap_on # Retrieve arguments -domain=$(ynh_app_setting_get "$app" domain) +export app=$YNH_APP_INSTANCE_NAME +export domain=$(ynh_app_setting_get "$app" domain) +export odoo_version=$(ynh_app_setting_get "$app" odoo_version) +export is_master=$(ynh_app_setting_get "$app" is_master) +export oca=$(ynh_app_setting_get "$app" oca) +export port=$(ynh_app_setting_get $app port) +export is_public=0 + +version=$(ynh_read_json "/etc/yunohost/apps/$app/manifest.json" 'version' 2> /dev/null || echo '9.0-0') +last_version=$(ynh_read_manifest 'version') + +#ynh_exit_if_up_to_date +ynh_check_var "$app" "app name not set" # Upgrade official package - sudo apt-get install odoo -y -qq +apt-get install odoo -y -qq + +# Zamentur version https://github.com/zamentur/odoo_ynh/commit/cdeb9afbf218431781f752dedfbf4247afbd5b44 +if [ "${version}" = "9.0-0" ]; then + # set new args + odoo_version=${odoo_version:-$(ynh_app_setting_get "$app" version)} + if [ "$is_master" = "" ]; then + if [ "$(ynh_app_setting_get "$app" instance)" = "master" ];then + is_master="true" + else + is_master="false" + fi + fi + port=${port:-8069} + oca=${oca:-false} + ynh_save_args odoo_version oca is_master port + + # Install official debian package + install_dependencies +fi + +if [ "${version}" = "10.0-1" ]; then + # Put here your migrations + echo "" +fi + -# TBD