1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/retroarch_ynh.git synced 2024-09-03 20:16:12 +02:00
retroarch_ynh/scripts/install
2021-05-08 15:43:13 +02:00

150 lines
5.4 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
source _common.sh
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
#path_url=$YNH_APP_ARG_PATH
path_url="/"
#admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
#language=$YNH_APP_ARG_LANGUAGE
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=13
ynh_install_nodejs --nodejs_version=10
ynh_use_nodejs
ynh_npm install -g coffeescript
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=60
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
# uncompress and patch done manually as 7z format is not supported
ynh_setup_source --dest_dir="$final_path" --source_id=$app
#7z archive not handled by ynh and no way to strip component, have to move it manually
7zr x $final_path/retroarch.7z -o$final_path
mv $final_path/retroarch/* $final_path/
rm $final_path/retroarch.7z
rm -r $final_path/retroarch
#create additionnal folders & file #https://github.com/libretro/RetroArch/tree/master/pkg/emscripten
mkdir -p $final_path/assets/frontend/bundle
mkdir -p $final_path/assets/cores
touch $final_path/analytics.js #https://github.com/libretro/RetroArch/issues/4539#issuecomment-473345195
#Get the indexer as exe so that folder w/ ROMs can be indexed
chmod +x $final_path/indexer
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..." --weight=3
#backup & Update nginx MIME type so wasm mime type is recognized
if [ !$(grep wasm /etc/nginx/mime.types) ]; then
ynh_print_info "/etc/nginx/mime.types saved as /etc/nginx/mime.types.$app"
cp /etc/nginx/mime.types /etc/nginx/mime.types.$app
ynh_replace_string --match_string=" application/octet-stream bin exe dll;" --replace_string=" application/wasm wasm;\n\n application/octet-stream bin exe dll;" --target_file="/etc/nginx/mime.types"
ynh_store_file_checksum --file="/etc/nginx/mime.types"
fi
# Create a dedicated nginx config
ynh_add_nginx_config
### For security reason, any app should set the permissions to root: before anything else.
### Then, if write authorization is needed, any access should be given only to directories
### that really need such authorization.
# Set permissions to app files
chown -R root: $final_path
#=================================================
# SETUP INDEX
#=================================================
#indexer use the current directory to run #https://github.com/libretro/RetroArch/tree/master/pkg/emscripten
#Indexer will list the available ROM and cores for Retroarch
ynh_script_progression --message="Setup Indexer for content..." --weight=3
cd $final_path/assets/frontend/bundle/
../../../indexer > .index-xhr
cd $final_path/assets/cores
../../indexer > .index-xhr
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..." --weight=1
# Make app public if necessary
if [ $is_public -eq 1 ]
then
ynh_permission_update --permission "main" --add visitors
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last