File get-source.sh of Package ampache

#!/bin/bash
#

function usage (){
    echo
    echo "Usage: $0 [options]"
    echo "       -f : force update"
    echo "       -m : try to update the ampache package"
    echo "       -i : install needed composer"
    echo
    exit 0
}

while getopts 'himf'  OPTION ; do
    case $OPTION in
	f) FORCE="yes"
	;;
	h) usage
	;;
	i) COMPOSER="yes"
	;;
	m) AMPACHE="yes"
	;;
    esac
done
shift $(( OPTIND - 1 ))


if [ -f ampache.spec ]; then
	AMPACHEVERSION=`grep ^Version: ampache.spec  | awk '" " { print $2 }'`
	AMPACHESOURCE=`grep ^Source: ampache.spec  | awk '" " { print $2 }' | sed 's|%{version}|'$AMPACHEVERSION'|g' | sed 's|%{name}|ampache|g'`
	echo "Ampache Version: $AMPACHEVERSION"
	echo "Ampache Source:  $AMPACHESOURCE"
	echo ""
else 
	echo "Couldn't find ampache.spec"
	echo ""
	exit 1
fi

if [ "$COMPOSER" == "yes" ]; then
    echo "First we need to install composer and php7-intl. php7 because we build under Leap..."
    sudo zypper in php-composer2
    sudo zypper in php7-intl
    exit 1
fi

if [ "$FORCE" = yes ]; then
    rm ampache-$AMPACHEVERSION.tar.gz
    rm ampache-$AMPACHEVERSION-vendor.tar.gz
    wget -4 --no-clobber --continue ${AMPACHESOURCE}
    tar -xvzf ampache-$AMPACHEVERSION.tar.gz
fi


if [ "$AMPACHE" == "yes" ]; then
    if [ -f ampache-$AMPACHEVERSION.tar.gz ] ; then
        echo "Warning: file ampache exists - exiting"
        exit 1
    else
        wget -4 --no-clobber --continue ${AMPACHESOURCE}
        tar -xvzf ampache-$AMPACHEVERSION.tar.gz
    fi
fi

echo "Download components and vendor..."
    cd ampache-$AMPACHEVERSION

    echo "First we need copy composer_old.json to composer.json because composer.json supports only php 8.2..."
    cp -f ./composer_old.json ./composer.json
    echo "Now download/install..."
    composer install --prefer-source --no-interaction
    for f in `find . -type d | grep "/.git"`; do
       rm -rf $f
    done
    for f in `find . -type d | grep "/.gitignore"`; do
       rm -rf $f
    done
    for f in `find . -type f | grep "/.gitignore"`; do
       rm -rf $f
    done
    for f in `find . -type f | grep "/.gitattributes"`; do
       rm -rf $f
    done
    cd ..

echo "Packaging..."
    tar -czf ampache-$AMPACHEVERSION-vendor.tar.gz  ampache-$AMPACHEVERSION/public/lib/components ampache-$AMPACHEVERSION/vendor
rm -rf ampache-$AMPACHEVERSION
echo "Done..."

exit
openSUSE Build Service is sponsored by