From dae9885b3a6db6adb15afda7fb9eb3bb25e29ef3 Mon Sep 17 00:00:00 2001 From: aymhce Date: Sat, 4 Jun 2016 21:19:05 +0200 Subject: [PATCH] update ampache to 3.8.2 and do yunohost 2.4 compatibility --- manifest.json | 3 +++ scripts/install | 39 ++++++++++++++++++++++++--------------- scripts/remove | 11 ++++++----- scripts/upgrade | 30 +++++++++++++----------------- 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/manifest.json b/manifest.json index 771ff99..c92d242 100644 --- a/manifest.json +++ b/manifest.json @@ -12,6 +12,9 @@ "email": "beudbeud@beudibox.fr" }, "multi_instance": "true", + "requirements": { + "yunohost": ">> 2.3.12.1" + }, "services" : [ "nginx", "php5-fpm", diff --git a/scripts/install b/scripts/install index 264b542..11b6ae7 100644 --- a/scripts/install +++ b/scripts/install @@ -1,14 +1,18 @@ #!/bin/bash # Retrieve arguments +app=$YNH_APP_INSTANCE_NAME domain=$1 path=$2 admin_ampache=$3 -debianversionname=$(lsb_release -a | grep Codename | awk -F' ' '{print $2}') +# Source YunoHost helpers +. /usr/share/yunohost/helpers + +#debianversionname=$(lsb_release -a | grep Codename | awk -F' ' '{print $2}') # Check domain/path availability -sudo yunohost app checkurl $domain$path -a ampache +sudo yunohost app checkurl $domain$path -a $app if [[ ! $? -eq 0 ]]; then exit 1 fi @@ -26,14 +30,16 @@ sudo yunohost app setting ampache admin -v $admin_ampache 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') # Use 'ampache' as database name and user -db_user=ampache +db_user=$app # Initialize database and store mysql password for upgrade -sudo yunohost app initdb $db_user -p $db_pwd -s $(readlink -e ../sources/sql/ampache.sql) -sudo yunohost app setting ampache mysqlpwd -v $db_pwd +#sudo yunohost app initdb $db_user -p $db_pwd -s $(readlink -e ../sources/sql/ampache.sql) +sudo yunohost app setting $app mysqlpwd -v $db_pwd +ynh_mysql_create_db "$app" "$db_user" "$db_pwd" +ynh_mysql_connect_as "$db_user" "$db_pwd" "$app" < "../sources/sql/ampache.sql" # Copy files to the right place -final_path=/var/www/ampache +final_path=/var/www/$app sudo mkdir -p $final_path/log sudo cp -a ../sources/* $final_path sudo cp ../conf/ampache.cfg.php $final_path/config/ampache.cfg.php @@ -55,29 +61,32 @@ sudo chown -R www-data: $final_path # Modify Nginx configuration file and copy it to Nginx conf directory sed -i "s@PATHTOCHANGE@${path%/}@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/ampache.conf +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # Reload Nginx and regenerate SSOwat conf sudo service nginx reload -sudo yunohost app setting ampache skipped_uris -v "/" +sudo yunohost app setting $app skipped_uris -v "/" sudo yunohost app ssowatconf # Install dependency -sudo apt-get install ffmpeg -y +sudo apt-get install libav-tools -y # Ampache installation +cd /var/www/$app +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 + 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 -[ "$debianversionname" == "wheezy" ] && \ -sudo sed -i 's/;transcode_cmd = "ffmpeg"/transcode_cmd = "ffmpeg"/g' /var/www/ampache/config/ampache.cfg.php && \ -sudo sed -i 's/^transcode_cmd = "avconv"/;transcode_cmd = "avconv"/g' /var/www/ampache/config/ampache.cfg.php -sudo yunohost app setting ampache skipped_uris -d -sudo yunohost app setting ampache skipped_uris -v "/rest" + +sudo yunohost app setting $app skipped_uris -d +sudo yunohost app setting $app skipped_uris -v "/rest" sudo yunohost app ssowatconf sudo sed '/yunoampache/d' /etc/hosts > /tmp/hosts.tmp sudo cp /tmp/hosts.tmp /etc/hosts ; sudo rm -f /tmp/hosts.tmp -mysql -u $db_user -p$db_pwd $db_user < /tmp/admin.sql +ynh_mysql_connect_as "$db_user" "$db_pwd" "$app" < /tmp/admin.sql sudo rm /tmp/admin.sql diff --git a/scripts/remove b/scripts/remove index dd02d9b..e763135 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,16 +1,17 @@ #!/bin/bash -db_user=ampache -db_name=ampache +app=$YNH_APP_INSTANCE_NAME +db_user=$app +db_name=$app root_pwd=$(sudo cat /etc/yunohost/mysql) -domain=$(sudo yunohost app setting ampache domain) +domain=$(sudo yunohost app setting $app domain) # Drop MySQL database mysql -u root -p$root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;" # Remove sources -sudo rm -rf /var/www/ampache +sudo rm -rf /var/www/$app # Remove Nginx configuration and reload Nginx conf -sudo rm -f /etc/nginx/conf.d/$domain.d/ampache.conf +sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf sudo service nginx reload diff --git a/scripts/upgrade b/scripts/upgrade index e02caf0..a8f2b3e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,20 +1,18 @@ #!/bin/bash - -debianversionname=$(lsb_release -a | grep Codename | awk -F' ' '{print $2}') - # Retrieve arguments -domain=$(sudo yunohost app setting ampache domain) -path=$(sudo yunohost app setting ampache path) -db_user=ampache -db_pwd=$(sudo yunohost app setting ampache mysqlpwd) -admin_ampache=$(sudo yunohost app setting ampache admin) +app=$YNH_APP_INSTANCE_NAME +domain=$(sudo yunohost app setting $app domain) +path=$(sudo yunohost app setting $app path) +db_user=$app +db_pwd=$(sudo yunohost app setting $app mysqlpwd) +admin_ampache=$(sudo yunohost app setting $app admin) # first make a copy of the db -# mysqldump -u $db_user -p$db_pwd --add-drop-table --allow-keywords ampache > $final_path/ampache-db-backup.sql +# mysqldump -u $db_user -p$db_pwd --add-drop-table --allow-keywords $app > $final_path/ampache-db-backup.sql # Copy files to the right place -final_path=/var/www/ampache +final_path=/var/www/$app sudo cp -a ../sources/* $final_path sudo cp ../conf/ampache.cfg.php $final_path/config/ampache.cfg.php @@ -32,12 +30,12 @@ sudo chown -R www-data: $final_path # Modify Nginx configuration file and copy it to Nginx conf directory sed -i "s@PATHTOCHANGE@${path%/}@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/ampache.conf +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # Reload Nginx and regenerate SSOwat conf sudo service nginx reload -sudo yunohost app setting ampache skipped_uris -v "/" +sudo yunohost app setting $app skipped_uris -v "/" sudo yunohost app ssowatconf # Ampache installation @@ -45,11 +43,9 @@ 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 -[ "$debianversionname" == "wheezy" ] && \ -sudo sed -i 's/;transcode_cmd = "ffmpeg"/transcode_cmd = "ffmpeg"/g' /var/www/ampache/config/ampache.cfg.php && \ -sudo sed -i 's/^transcode_cmd = "avconv"/;transcode_cmd = "avconv"/g' /var/www/ampache/config/ampache.cfg.php -sudo yunohost app setting ampache skipped_uris -d -sudo yunohost app setting ampache skipped_uris -v "/rest" + +sudo yunohost app setting $app skipped_uris -d +sudo yunohost app setting $app skipped_uris -v "/rest" sudo yunohost app ssowatconf sudo sed '/yunoampache/d' /etc/hosts > /tmp/hosts.tmp sudo cp /tmp/hosts.tmp /etc/hosts ; sudo rm -f /tmp/hosts.tmp