Skip to content

Commit

Permalink
global upgrade for yunohost package_linter and ampache 3.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
aymhce committed Sep 3, 2017
1 parent febcf9d commit 54ba788
Show file tree
Hide file tree
Showing 13 changed files with 3,227 additions and 306 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

510 changes: 310 additions & 200 deletions conf/ampache.cfg.php

Large diffs are not rendered by default.

1,081 changes: 1,081 additions & 0 deletions conf/ampache.cfg.php.dist

Large diffs are not rendered by default.

File renamed without changes.
986 changes: 986 additions & 0 deletions conf/ampache.cfg.php.old2

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"fr": "Une application de streaming audio et vidéo"
},
"url": "http://ampache.org",
"packaging_format": 1,
"license": "free",
"maintainer": {
"name": "beudbeud",
"email": "beudbeud@beudibox.fr"
"name": "aymhce",
"email": "aymhce@gmail.com"
},
"multi_instance": "true",
"multi_instance": true,
"requirements": {
"yunohost": ">> 2.3.12.1"
},
Expand Down
60 changes: 60 additions & 0 deletions scripts/_common
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/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 () {
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/$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
}
18 changes: 18 additions & 0 deletions scripts/backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -eu

. /usr/share/yunohost/helpers

app=$YNH_APP_INSTANCE_NAME

domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
admin=$(ynh_app_setting_get "$app" admin)

ynh_backup "/var/www/$app" "sources" 1

ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"

ynh_mysql_dump_db "$app" > db.sql
#ynh_backup "db.sql" "db.sql"
87 changes: 30 additions & 57 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -1,92 +1,65 @@
#!/bin/bash

set -eu

# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$1
path=$2
admin_ampache=$3
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
admin_ampache=$YNH_APP_ARG_ADMIN

# Source YunoHost helpers
# Source helpers
. /usr/share/yunohost/helpers
. _common

# Check if admin exists
sudo yunohost user list --json | grep -qi "\"username\": \"$admin_ampache\"" || ynh_die "wrong admin username"

#debianversionname=$(lsb_release -a | grep Codename | awk -F' ' '{print $2}')
ynh_app_setting_set $app admin $admin_ampache

# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app
if [[ ! $? -eq 0 ]]; then
exit 1
fi
path=$(ynh_normalize_url_path $path)
ynh_webpath_available $domain $path
ynh_webpath_register $app $domain $path

# Check if admin exists
sudo yunohost user list --json | grep -qi "\"username\": \"$admin_ampache\""
if [[ ! $? -eq 0 ]]; then
echo "Wrong admin"
exit 1
fi
# get sources and copy files to the right place
ampache_ynh_getsources

sudo yunohost app setting ampache admin -v $admin_ampache
sudo cp ../conf/admin.sql /tmp/

# 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')

# Use 'ampache' as database name and user
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 $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/$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
sudo cp ../conf/admin.sql /tmp/
ynh_app_setting_set $app mysqlpwd $db_pwd
ynh_mysql_setup_db "$app" "$app" "$db_pwd"
ynh_mysql_connect_as "$app" "$db_pwd" "$app" < "$final_path/sql/ampache.sql"

# Change variables in Ampache configuration
sudo sed -i "s/yunouser/$db_user/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/$db_user/g" $final_path/config/ampache.cfg.php
ampache_ynh_prepareconfig

sudo sed -i "s/yunoadmin/$admin_ampache/g" /tmp/admin.sql
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
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

# 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/$app.conf
ampache_ynh_preparenginx

# Install dependency
sudo apt-get update
sudo apt-get install libav-tools -y

# Ampache installation
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
ampache_ynh_install

# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app setting $app skipped_uris -v "/"
sudo yunohost app ssowatconf
ampache_ynh_reloadservices

# Pre config ampache
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
ampache_ynh_doconfig

ynh_mysql_connect_as "$app" "$db_pwd" "$app" < /tmp/admin.sql

# Clean install
sudo sed '/yunoampache/d' /etc/hosts > /tmp/hosts.tmp
sudo cp /tmp/hosts.tmp /etc/hosts ; sudo rm -f /tmp/hosts.tmp
ynh_mysql_connect_as "$db_user" "$db_pwd" "$app" < /tmp/admin.sql
sudo rm -rf ../ampache-$version
sudo rm /tmp/admin.sql


13 changes: 7 additions & 6 deletions scripts/remove
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash

set -u

. /usr/share/yunohost/helpers

app=$YNH_APP_INSTANCE_NAME
db_user=$app
db_name=$app
root_pwd=$(sudo cat /etc/yunohost/mysql)
domain=$(sudo yunohost app setting $app domain)
domain=$(ynh_app_setting_get $app domain)

# Drop MySQL database
mysql -u root -p$root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;"
ynh_mysql_drop_db $app
ynh_mysql_drop_user $app

# Remove sources
sudo rm -rf /var/www/$app
Expand Down
33 changes: 33 additions & 0 deletions scripts/restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -eu

. /usr/share/yunohost/helpers

app=$YNH_APP_INSTANCE_NAME

domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
admin=$(ynh_app_setting_get "$app" admin)

# Check domain/path availability
test ! -d /var/www/$app \
|| ynh_die "There is already a directory: /var/www/$app "

path=$(ynh_normalize_url_path $path)
ynh_webpath_available $domain $path
ynh_webpath_register $app $domain $path

# Install dependency
sudo apt-get update
sudo apt-get install libav-tools -y

sudo cp -a ./sources "/var/www/$app"

sudo cp -a ./conf/nginx.conf "/etc/nginx/conf.d/$domain.d/$app.conf"

db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $app $app $db_pwd
ynh_mysql_connect_as $app $db_pwd $app < ./db.sql

sudo service nginx reload
63 changes: 23 additions & 40 deletions scripts/upgrade
Original file line number Diff line number Diff line change
@@ -1,54 +1,37 @@
#!/bin/bash

set -eu

. /usr/share/yunohost/helpers
. _common

# Retrieve arguments
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)
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
admin_ampache=$(ynh_app_setting_get $app admin)

# first make a copy of the db
# mysqldump -u $db_user -p$db_pwd --add-drop-table --allow-keywords $app > $final_path/ampache-db-backup.sql
path=$(ynh_normalize_url_path $path)

# Copy files to the right place
final_path=/var/www/$app
sudo cp -a ../sources/* $final_path
sudo cp ../conf/ampache.cfg.php $final_path/config/ampache.cfg.php
# Get sources and copy files to the right place
ampache_ynh_getsources

# Change variables in Ampache configuration
sudo sed -i "s/yunouser/$db_user/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/$db_user/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


# Set permissions to roundcube directory
sudo chown -R www-data: $final_path
ampache_ynh_prepareconfig

# 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/$app.conf
ampache_ynh_preparenginx

# Ampache installation
ampache_ynh_install

# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app setting $app skipped_uris -v "/"
sudo yunohost app ssowatconf
ampache_ynh_reloadservices

# Ampache installation
cd $final_path
sudo -u www-data 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

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
# Pre config ampache
ampache_ynh_doconfig

# Clean install
sudo rm -rf ../ampache-$version
sudo rm /tmp/admin.sql
1 change: 1 addition & 0 deletions scripts/upstream_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8.3

0 comments on commit 54ba788

Please sign in to comment.