mirror of
https://github.com/YunoHost-Apps/ampache_ynh.git
synced 2024-09-03 18:15:55 +02:00
apply recommandations YunoHost-Apps/ampache_ynh#21
This commit is contained in:
parent
a8c53c080e
commit
9acff9df8d
8 changed files with 98 additions and 90 deletions
|
@ -14,7 +14,7 @@
|
|||
},
|
||||
"multi_instance": true,
|
||||
"requirements": {
|
||||
"yunohost": ">> 2.3.12.1"
|
||||
"yunohost": ">= 2.7.2"
|
||||
},
|
||||
"services" : [
|
||||
"nginx",
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copy files to the right place
|
||||
ampache_ynh_getsources () {
|
||||
version=$(cat upstream_version)
|
||||
|
||||
final_path=/var/www/$app
|
||||
sudo mkdir -p $final_path/log
|
||||
|
||||
sudo wget -O ../ampache.tar.gz https://github.com/ampache/ampache/archive/$version.tar.gz > /dev/null 2>&1
|
||||
sudo tar xvzf ../ampache.tar.gz -C .. > /dev/null 2>&1
|
||||
sudo cp -ar ../ampache-$version/. $final_path
|
||||
|
||||
sudo cp ../conf/ampache.cfg.php $final_path/config/ampache.cfg.php
|
||||
}
|
||||
|
||||
# Change variables in Ampache configuration
|
||||
ampache_ynh_prepareconfig () {
|
||||
sudo sed -i "s/yunouser/$app/g" $final_path/config/ampache.cfg.php
|
||||
sudo sed -i "s/yunopass/$db_pwd/g" $final_path/config/ampache.cfg.php
|
||||
sudo sed -i "s/yunobase/$app/g" $final_path/config/ampache.cfg.php
|
||||
sudo sed -i "s@PATHTOCHANGE@${path}@g" $final_path/config/ampache.cfg.php
|
||||
sudo sed -i "s@DOMAINTOCHANGE@$domain@g" $final_path/config/ampache.cfg.php
|
||||
}
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
ampache_ynh_preparenginx () {
|
||||
path2=$(if [ "$path" == "/" ] ; then echo "" ; else echo "$path" ; fi)
|
||||
sed -i "s@PATHTOCHANGE@${path}@g" ../conf/nginx.conf*
|
||||
sed -i "s@PATH2TOCHANGE@${path2}@g" ../conf/nginx.conf*
|
||||
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf*
|
||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
}
|
||||
|
||||
# Ampache installation
|
||||
ampache_ynh_install () {
|
||||
ORIPATH=$(pwd)
|
||||
cd $final_path
|
||||
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
||||
sudo php composer-setup.php
|
||||
sudo php composer.phar install --prefer-source --no-interaction
|
||||
# Set permissions to ampache directory
|
||||
sudo chown -R www-data: $final_path
|
||||
cd $ORIPATH
|
||||
}
|
||||
|
||||
# Reload Nginx and regenerate SSOwat conf
|
||||
ampache_ynh_reloadservices () {
|
||||
sudo service nginx reload
|
||||
ynh_app_setting_set $app skipped_uris "/"
|
||||
sudo yunohost app ssowatconf
|
||||
}
|
||||
|
||||
# Pre config ampache
|
||||
ampache_ynh_doconfig () {
|
||||
echo "127.0.0.1 $domain #yunoampache" | sudo tee -a /etc/hosts
|
||||
sleep 1
|
||||
curl -kL -X POST http://$domain${path%/}/update.php?action=update > /dev/null 2>&1
|
||||
sleep 5
|
||||
sudo sed '/yunoampache/d' /etc/hosts > /tmp/hosts.tmp
|
||||
sudo cp /tmp/hosts.tmp /etc/hosts ; sudo rm -f /tmp/hosts.tmp
|
||||
}
|
62
scripts/_common.sh
Normal file
62
scripts/_common.sh
Normal file
|
@ -0,0 +1,62 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copy files to the right place
|
||||
ampache_ynh_getsources () {
|
||||
version=$(cat upstream_version)
|
||||
|
||||
final_path=/var/www/$app
|
||||
mkdir -p $final_path/log
|
||||
|
||||
wget -O ../ampache.tar.gz https://github.com/ampache/ampache/archive/$version.tar.gz > /dev/null 2>&1
|
||||
tar xvzf ../ampache.tar.gz -C .. > /dev/null 2>&1
|
||||
cp -ar ../ampache-$version/. $final_path
|
||||
|
||||
cp ../conf/ampache.cfg.php $final_path/config/ampache.cfg.php
|
||||
}
|
||||
|
||||
# Change variables in Ampache configuration
|
||||
ampache_ynh_prepareconfig () {
|
||||
ynh_replace_string "yunouser" "$app" $final_path/config/ampache.cfg.php
|
||||
ynh_replace_string "yunopass" "$db_pwd" $final_path/config/ampache.cfg.php
|
||||
ynh_replace_string "yunobase" "$app" $final_path/config/ampache.cfg.php
|
||||
ynh_replace_string "PATHTOCHANGE" "${path}" $final_path/config/ampache.cfg.php
|
||||
ynh_replace_string "DOMAINTOCHANGE" "$domain" $final_path/config/ampache.cfg.php
|
||||
}
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
ampache_ynh_preparenginx () {
|
||||
path2=$(if [ "$path" == "/" ] ; then echo "" ; else echo "$path" ; fi)
|
||||
ynh_replace_string "PATHTOCHANGE" "${path}" ../conf/nginx.conf*
|
||||
ynh_replace_string "PATH2TOCHANGE" "${path2}" ../conf/nginx.conf*
|
||||
ynh_replace_string "ALIASTOCHANGE" "$final_path/" ../conf/nginx.conf*
|
||||
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
}
|
||||
|
||||
# Ampache installation
|
||||
ampache_ynh_install () {
|
||||
ORIPATH=$(pwd)
|
||||
cd $final_path
|
||||
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
||||
php composer-setup.php
|
||||
php composer.phar install --prefer-source --no-interaction
|
||||
# Set permissions to ampache directory
|
||||
chown -R www-data: $final_path
|
||||
cd $ORIPATH
|
||||
}
|
||||
|
||||
# Reload Nginx and regenerate SSOwat conf
|
||||
ampache_ynh_reloadservices () {
|
||||
systemctl reload nginx
|
||||
ynh_app_setting_set $app skipped_uris "/"
|
||||
yunohost app ssowatconf
|
||||
}
|
||||
|
||||
# Pre config ampache
|
||||
ampache_ynh_doconfig () {
|
||||
echo "127.0.0.1 $domain #yunoampache" | tee -a /etc/hosts
|
||||
sleep 1
|
||||
curl -kL -X POST http://$domain${path%/}/update.php?action=update > /dev/null 2>&1
|
||||
sleep 5
|
||||
sed '/yunoampache/d' /etc/hosts > /tmp/hosts.tmp
|
||||
cp /tmp/hosts.tmp /etc/hosts ; ynh_secure_remove /tmp/hosts.tmp
|
||||
}
|
6
scripts/backup
Executable file → Normal file
6
scripts/backup
Executable file → Normal file
|
@ -23,17 +23,19 @@ domain=$(ynh_app_setting_get "$app" domain)
|
|||
path=$(ynh_app_setting_get "$app" path)
|
||||
admin=$(ynh_app_setting_get "$app" admin)
|
||||
|
||||
final_path=/var/www/$app
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/var/www/$app" "sources" 1
|
||||
ynh_backup "$final_path"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE MYSQL DATABASE
|
||||
|
|
|
@ -18,7 +18,7 @@ admin_ampache=$YNH_APP_ARG_ADMIN
|
|||
|
||||
# Source helpers
|
||||
. /usr/share/yunohost/helpers
|
||||
. _common
|
||||
. _common.sh
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
|
@ -30,9 +30,6 @@ ynh_abort_if_errors
|
|||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||
#=================================================
|
||||
|
||||
# Check if admin exists
|
||||
sudo yunohost user list --json | grep -qi "\"username\": \"$admin_ampache\"" || ynh_die "wrong admin username"
|
||||
|
||||
# Check domain/path availability
|
||||
path=$(ynh_normalize_url_path $path)
|
||||
ynh_webpath_available $domain $path
|
||||
|
@ -50,14 +47,14 @@ ynh_app_setting_set $app admin $admin_ampache
|
|||
|
||||
# get sources and copy files to the right place
|
||||
ampache_ynh_getsources
|
||||
sudo cp ../conf/admin.sql /tmp/
|
||||
cp ../conf/admin.sql /tmp/
|
||||
|
||||
#=================================================
|
||||
# CREATE A MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
# Generate random password
|
||||
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
|
||||
db_pwd=$(ynh_string_random 24)
|
||||
|
||||
# Initialize database and store mysql password for upgrade
|
||||
ynh_app_setting_set $app mysqlpwd $db_pwd
|
||||
|
@ -71,9 +68,9 @@ ynh_mysql_connect_as "$app" "$db_pwd" "$app" < "$final_path/sql/ampache.sql"
|
|||
# Change variables in Ampache configuration
|
||||
ampache_ynh_prepareconfig
|
||||
|
||||
sudo sed -i "s/yunoadmin/$admin_ampache/g" /tmp/admin.sql
|
||||
random_key=db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
|
||||
sudo sed -i "s@RANDOMKEYTOCHANGE@$random_key@g" $final_path/config/ampache.cfg.php
|
||||
ynh_replace_string "yunoadmin" "$admin_ampache" /tmp/admin.sql
|
||||
random_key=db_pwd=$(ynh_string_random 24)
|
||||
ynh_replace_string "RANDOMKEYTOCHANGE" "$random_key" $final_path/config/ampache.cfg.php
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
|
@ -87,8 +84,7 @@ ampache_ynh_preparenginx
|
|||
#=================================================
|
||||
|
||||
# Install dependency
|
||||
sudo apt-get update
|
||||
sudo apt-get install libav-tools -y
|
||||
ynh_install_dependencies libav-tools
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
|
@ -117,5 +113,5 @@ ynh_mysql_connect_as "$app" "$db_pwd" "$app" < /tmp/admin.sql
|
|||
#=================================================
|
||||
|
||||
# Clean install
|
||||
sudo rm -rf ../ampache-$version
|
||||
sudo rm /tmp/admin.sql
|
||||
ynh_secure_remove ../ampache-$version
|
||||
ynh_secure_remove /tmp/admin.sql
|
||||
|
|
|
@ -15,6 +15,8 @@ set -u
|
|||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
|
||||
final_path=/var/www/$app
|
||||
|
||||
#=================================================
|
||||
# REMOVE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
@ -27,17 +29,24 @@ ynh_mysql_drop_user $app
|
|||
#=================================================
|
||||
|
||||
# Remove sources
|
||||
sudo rm -rf /var/www/$app
|
||||
ynh_secure_remove $final_path
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Remove Nginx configuration and reload Nginx conf
|
||||
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
# Remove dependency
|
||||
ynh_remove_dependencies libav-tools
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
sudo service nginx reload
|
||||
systemctl reload nginx
|
||||
|
|
15
scripts/restore
Executable file → Normal file
15
scripts/restore
Executable file → Normal file
|
@ -23,13 +23,15 @@ domain=$(ynh_app_setting_get "$app" domain)
|
|||
path=$(ynh_app_setting_get "$app" path)
|
||||
admin=$(ynh_app_setting_get "$app" admin)
|
||||
|
||||
final_path=/var/www/$app
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
|
||||
# Check domain/path availability
|
||||
test ! -d /var/www/$app \
|
||||
|| ynh_die "There is already a directory: /var/www/$app "
|
||||
test ! -d $final_path \
|
||||
|| ynh_die "There is already a directory: $final_path"
|
||||
|
||||
#=================================================
|
||||
# CHECK THE PATH
|
||||
|
@ -42,20 +44,19 @@ path=$(ynh_normalize_url_path $path)
|
|||
#=================================================
|
||||
|
||||
# Install dependency
|
||||
sudo apt-get update
|
||||
sudo apt-get install libav-tools -y
|
||||
ynh_install_dependencies libav-tools
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
sudo cp -a ./sources "/var/www/$app"
|
||||
ynh_restore_file "$final_path"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
sudo cp -a ./conf/nginx.conf "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
|
@ -69,4 +70,4 @@ ynh_mysql_connect_as $app $db_pwd $app < ./db.sql
|
|||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
sudo service nginx reload
|
||||
systemctl reload nginx
|
||||
|
|
|
@ -7,7 +7,7 @@ set -eu
|
|||
#=================================================
|
||||
|
||||
. /usr/share/yunohost/helpers
|
||||
. _common
|
||||
. _common.sh
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
|
@ -75,4 +75,4 @@ ampache_ynh_doconfig
|
|||
#=================================================
|
||||
|
||||
# Clean install
|
||||
sudo rm -rf ../ampache-$version
|
||||
ynh_secure_remove ../ampache-$version
|
||||
|
|
Loading…
Add table
Reference in a new issue