#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= admin_mail=$(ynh_user_get_info $admin 'mail') #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." --weight=8 ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src tempdir="$(mktemp -d)" ynh_setup_source --dest_dir="$tempdir" mkdir -p $install_dir chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= # SPECIFIC SETUP #================================================= # PIP INSTALLATION #================================================= ynh_script_progression --message="Installing project via pip..." --weight=80 python3 -m venv "${install_dir}/venv" cp ../conf/requirements.txt "$install_dir/requirements.txt" chown -R "$app" "$install_dir" #run source in a 'sub shell' ( set +o nounset source "${install_dir}/venv/bin/activate" set -o nounset ynh_exec_as $app $install_dir/venv/bin/pip install --upgrade pip ynh_exec_as $app $install_dir/venv/bin/pip install -r "$install_dir/requirements.txt" ) # we use this virtualenv archivebox for further commands now archivebox_cmd="$install_dir/venv/bin/archivebox" #================================================= # INSTALL NODE DEPENDENCIES #================================================= ynh_script_progression --message="Installing node dependencies..." cp -f $tempdir/package.json "$install_dir/package.json" cp -f $tempdir/package-lock.json "$install_dir/package-lock.json" ynh_secure_remove --file="$tempdir" pushd $install_dir ynh_use_nodejs ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm ci popd #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_add_config --template="ArchiveBox.conf" --destination="$data_dir/ArchiveBox.conf" chmod 600 "$data_dir/ArchiveBox.conf" chown $app:$app "$data_dir/ArchiveBox.conf" #================================================= # INITIALIZE ARCHIVEBOX #================================================= ynh_script_progression --message="Initializing $app" --weight=1 pushd $data_dir ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $archivebox_cmd init ynh_script_progression --message="Checking if admin superuser already exists: $admin" --weight=1 USER_EXISTS=$(ynh_exec_as $app $archivebox_cmd 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" --weight=1 if [ $USER_EXISTS -eq 1 ] then ynh_script_progression --message="User already exists: setting admin password" --weight=1 ynh_exec_as $app /usr/bin/expect<