add update function

This commit is contained in:
Jonathan Baecker 2020-08-27 13:10:19 +02:00
parent 67c9510a8d
commit a3debb2196
2 changed files with 478 additions and 332 deletions

View File

@ -6,6 +6,8 @@ For a better understanding about the functionality, take a look to the screensho
You can install it on a fresh debian/centos minimal like system with running `./install.sh` as root. You can install it on a fresh debian/centos minimal like system with running `./install.sh` as root.
Updating is also possible with: `./install.sh update`
Or read the instruction [install.md](docs/install.md) for manual installation. Or read the instruction [install.md](docs/install.md) for manual installation.
After installations you have to setup ssl for your **https** connections. After installations you have to setup ssl for your **https** connections.

View File

@ -5,18 +5,21 @@ if [[ $(whoami) != 'root' ]]; then
exit 1 exit 1
fi fi
echo "" if [[ "$(grep -Ei 'centos|fedora' /etc/*release)" ]]; then
echo "-----------------------------------------------------------------------------------------------------" serviceUser="nginx"
echo "ffplayout gui domain name (like: example.org)" else
echo "-----------------------------------------------------------------------------------------------------" serviceUser="www-data"
echo "" fi
read -p "domain name :$ " domain # get sure that we have our correct PATH
export PATH=$PATH:/usr/local/bin
runInstall() {
if [[ ! -f "/etc/ffplayout/ffplayout.yml" ]]; then
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "path to media storage, default: /opt/ffplayout/media" echo "path to media storage, default: /opt/ffplayout/media"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "" echo ""
read -p "media path :$ " mediaPath read -p "media path :$ " mediaPath
@ -26,9 +29,9 @@ if [[ -z "$mediaPath" ]]; then
fi fi
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "playlist path, default: /opt/ffplayout/playlists" echo "playlist path, default: /opt/ffplayout/playlists"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "" echo ""
read -p "playlist path :$ " playlistPath read -p "playlist path :$ " playlistPath
@ -36,11 +39,13 @@ read -p "playlist path :$ " playlistPath
if [[ -z "$playlistPath" ]]; then if [[ -z "$playlistPath" ]]; then
playlistPath="/opt/ffplayout/playlists" playlistPath="/opt/ffplayout/playlists"
fi fi
fi
if [[ "$(which ffmpeg)" == *"/usr/bin/which"* ]]; then
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "compile and install (nonfree) ffmpeg:" echo "compile and install (nonfree) ffmpeg:"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "" echo ""
while true; do while true; do
read -p "Do you wish to compile ffmpeg? (Y/n) :$ " yn read -p "Do you wish to compile ffmpeg? (Y/n) :$ " yn
@ -54,11 +59,13 @@ while true; do
);; );;
esac esac
done done
fi
if [[ "$(which nginx)" == *"/usr/bin/which"* ]]; then
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "install and setup nginx:" echo "install and setup nginx:"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "" echo ""
while true; do while true; do
read -p "Do you wish to install nginx? (Y/n) :$ " yn read -p "Do you wish to install nginx? (Y/n) :$ " yn
@ -74,9 +81,19 @@ while true; do
done done
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "ffplayout gui domain name (like: example.org)"
echo "------------------------------------------------------------------------------"
echo ""
read -p "domain name :$ " domain
fi
if [[ ! -d /usr/local/srs ]]; then
echo ""
echo "------------------------------------------------------------------------------"
echo "install and srs rtmp/hls server:" echo "install and srs rtmp/hls server:"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "" echo ""
while true; do while true; do
read -p "Do you wish to install srs? (Y/n) :$ " yn read -p "Do you wish to install srs? (Y/n) :$ " yn
@ -90,11 +107,13 @@ while true; do
);; );;
esac esac
done done
fi
if [[ ! -d "/opt/ffplayout-engine" ]]; then
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "install ffplayout-engine:" echo "install ffplayout-engine:"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "" echo ""
while true; do while true; do
read -p "Do you wish to install ffplayout-engine? (Y/n) :$ " yn read -p "Do you wish to install ffplayout-engine? (Y/n) :$ " yn
@ -108,42 +127,72 @@ while true; do
);; );;
esac esac
done done
fi
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "install main packages" echo "install main packages"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
if [[ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]]; then if [[ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]]; then
packages=(sudo curl wget net-tools git python3-dev build-essential virtualenv
python3-virtualenv mediainfo autoconf automake libtool pkg-config
yasm cmake mercurial gperf)
installedPackages=$(dpkg --get-selections | awk '{print $1}' | tr '\n' ' ')
apt update apt update
apt install -y sudo curl wget net-tools git python3-dev build-essential virtualenv python3-virtualenv mediainfo autoconf automake libtool pkg-config yasm cmake mercurial gperf if [[ "$installedPackages" != *"curl"* ]]; then
apt install -y curl
fi
if [[ "$installedPackages" != *"nodejs"* ]]; then
curl -sL https://deb.nodesource.com/setup_12.x | bash - curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt install -y nodejs apt install -y nodejs
fi
if [[ $installNginx == 'y' ]]; then for pkg in ${packages[@]}; do
if [[ "$installedPackages" != *"$pkg"* ]]; then
apt install -y $pkg
fi
done
if [[ $installNginx == 'y' ]] && [[ "$installedPackages" != *"nginx"* ]]; then
apt install -y nginx apt install -y nginx
rm /etc/nginx/sites-enabled/default rm /etc/nginx/sites-enabled/default
fi fi
serviceUser="www-data"
nginxConfig="/etc/nginx/sites-available" nginxConfig="/etc/nginx/sites-available"
elif [[ "$(grep -Ei 'centos|fedora' /etc/*release)" ]]; then elif [[ "$(grep -Ei 'centos|fedora' /etc/*release)" ]]; then
packages=(libstdc++-static yasm mercurial libtool libmediainfo mediainfo
cmake net-tools git python3 python36-devel wget python3-virtualenv
gperf nano nodejs python3-policycoreutils policycoreutils-devel)
installedPackages=$(dnf list --installed | awk '{print $1}' | tr '\n' ' ')
activeRepos=$(dnf repolist enabled | awk '{print $1}' | tr '\n' ' ')
if [[ "$activeRepos" != *"epel"* ]]; then
dnf -y install epel-release dnf -y install epel-release
dnf repolist epel -v fi
if [[ "$activeRepos" != *"PowerTools"* ]]; then
dnf -y config-manager --enable PowerTools dnf -y config-manager --enable PowerTools
dnf -y group install "Development Tools" fi
dnf -y --enablerepo=PowerTools install libmediainfo mediainfo
dnf -y install libstdc++-static yasm mercurial libtool cmake net-tools git python3 python36-devel wget python3-virtualenv gperf nano
dnf -y install policycoreutils-{python3,devel}
if [[ "$activeRepos" != *"nodesource"* ]]; then
curl -sL https://rpm.nodesource.com/setup_12.x | sudo -E bash - curl -sL https://rpm.nodesource.com/setup_12.x | sudo -E bash -
fi
dnf -y install nodejs for pkg in ${packages[@]}; do
if [[ "$installedPackages" != *"$pkg"* ]]; then
dnf -y install $pkg
fi
done
if [[ $installNginx == 'y' ]]; then if [[ ! $(dnf group list "Development Tools" | grep -i "install") ]]; then
dnf -y group install "Development Tools"
fi
if [[ $installNginx == 'y' ]] && [[ "$installedPackages" != *"nginx"* ]]; then
dnf -y install nginx dnf -y install nginx
systemctl enable nginx systemctl enable nginx
systemctl start nginx systemctl start nginx
@ -154,17 +203,18 @@ elif [[ "$(grep -Ei 'centos|fedora' /etc/*release)" ]]; then
chcon -vR system_u:object_r:httpd_sys_content_t:s0 /var/www chcon -vR system_u:object_r:httpd_sys_content_t:s0 /var/www
fi fi
if [[ $(alternatives --list | grep "no-python") ]]; then
alternatives --set python /usr/bin/python3 alternatives --set python /usr/bin/python3
fi
serviceUser="nginx"
nginxConfig="/etc/nginx/conf.d" nginxConfig="/etc/nginx/conf.d"
fi fi
if [[ $compileFFmpeg == 'y' ]]; then if [[ $compileFFmpeg == 'y' ]]; then
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "compile and install ffmpeg" echo "compile and install ffmpeg"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
cd /opt/ cd /opt/
if [[ ! -d "ffmpeg-build" ]]; then if [[ ! -d "ffmpeg-build" ]]; then
@ -212,9 +262,9 @@ fi
if [[ $installSRS == 'y' ]] && [[ ! -d "/usr/local/srs" ]]; then if [[ $installSRS == 'y' ]] && [[ ! -d "/usr/local/srs" ]]; then
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "compile and install srs" echo "compile and install srs"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
cd /opt/ cd /opt/
git clone https://github.com/ossrs/srs.git git clone https://github.com/ossrs/srs.git
@ -295,16 +345,21 @@ EOF
systemctl start srs.service systemctl start srs.service
fi fi
if [[ "$(grep -Ei 'centos|fedora' /etc/*release)" ]]; then if [[ "$(grep -Ei 'centos|fedora' /etc/*release)" ]]; then
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "creating selinux rules" echo "creating selinux rules"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
if [[ $(getsebool httpd_can_network_connect | awk '{print $NF}') == "off" ]]; then
setsebool httpd_can_network_connect on -P setsebool httpd_can_network_connect on -P
semanage port -a -t http_port_t -p tcp 8001 fi
if [[ ! $(semanage port -l | grep http_port_t | grep "8001") ]]; then
semanage port -a -t http_port_t -p tcp 8001
fi
if [[ ! $(semodule -l | grep gunicorn) ]]; then
cat <<EOF > gunicorn.te cat <<EOF > gunicorn.te
module gunicorn 1.0; module gunicorn 1.0;
@ -337,8 +392,12 @@ EOF
semodule_package -o gunicorn.pp -m gunicorn.mod semodule_package -o gunicorn.pp -m gunicorn.mod
semodule -i gunicorn.pp semodule -i gunicorn.pp
cat <<EOF > conf.te rm -f gunicorn.*
module conf 1.0; fi
if [[ ! $(semodule -l | grep "custom-http") ]]; then
cat <<EOF > custom-http.te
module custom-http 1.0;
require { require {
type init_t; type init_t;
@ -353,12 +412,16 @@ allow init_t httpd_sys_content_t:file unlink;
allow init_t httpd_sys_content_t:file { create lock write }; allow init_t httpd_sys_content_t:file { create lock write };
EOF EOF
checkmodule -M -m -o conf.mod conf.te checkmodule -M -m -o custom-http.mod custom-http.te
semodule_package -o conf.pp -m conf.mod semodule_package -o custom-http.pp -m custom-http.mod
semodule -i conf.pp semodule -i custom-http.pp
cat <<EOF > create.te rm -f custom-http.*
module create 1.0; fi
if [[ ! $(semodule -l | grep "custom-fileop") ]]; then
cat <<EOF > custom-fileop.te
module custom-fileop 1.0;
require { require {
type init_t; type init_t;
@ -381,9 +444,12 @@ allow init_t usr_t:file { rename unlink write };
EOF EOF
checkmodule -M -m -o create.mod create.te checkmodule -M -m -o custom-fileop.mod custom-fileop.te
semodule_package -o create.pp -m create.mod semodule_package -o custom-fileop.pp -m custom-fileop.mod
semodule -i create.pp semodule -i custom-fileop.pp
rm -f custom-fileop.*
fi
fi fi
if ! grep -q "ffplayout-engine.service" "/etc/sudoers"; then if ! grep -q "ffplayout-engine.service" "/etc/sudoers"; then
@ -392,9 +458,9 @@ fi
if [[ "$installEngine" == "y" ]] && [[ ! -d "/opt/ffplayout-engine" ]]; then if [[ "$installEngine" == "y" ]] && [[ ! -d "/opt/ffplayout-engine" ]]; then
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "install ffplayout engine" echo "install ffplayout engine"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
cd /opt cd /opt
git clone https://github.com/ffplayout/ffplayout-engine.git git clone https://github.com/ffplayout/ffplayout-engine.git
@ -430,9 +496,9 @@ fi
if [[ ! -d "/var/www/ffplayout" ]]; then if [[ ! -d "/var/www/ffplayout" ]]; then
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "install ffplayout gui" echo "install ffplayout gui"
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
cd /var/www cd /var/www
git clone https://github.com/ffplayout/ffplayout-gui.git ffplayout git clone https://github.com/ffplayout/ffplayout-gui.git ffplayout
@ -502,10 +568,88 @@ if [[ $installNginx == 'y' ]]; then
fi fi
echo "" echo ""
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "installation done..." echo "installation done..."
echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
echo "" echo ""
echo "add your ssl config to $nginxConfig/ffplayout.conf" echo "add your ssl config to $nginxConfig/ffplayout.conf"
echo "" echo ""
}
runUpdate() {
if [[ -d "/opt/ffmpeg-build" ]]; then
cd "/opt/ffmpeg-build"
git pull
./compile-ffmpeg.sh
echo ""
echo "------------------------------------------------------------------------------"
echo "updating ffmpeg-build done..."
echo "------------------------------------------------------------------------------"
fi
if [[ -d "/opt/ffplayout-engine" ]]; then
cd "/opt/ffplayout-engine"
git pull
source ./venv/bin/activate
pip install --upgrade -r requirements-base.txt
deactivate
echo ""
echo "------------------------------------------------------------------------------"
echo "updating ffplayout-engine done..."
echo "------------------------------------------------------------------------------"
else
echo ""
echo "------------------------------------------------------------------------------"
echo "WARNING: no ffplayout-engine found..."
echo "------------------------------------------------------------------------------"
fi
if [[ -d "/var/www/ffplayout" ]]; then
cd "/var/www/ffplayout"
git pull
source ./venv/bin/activate
pip install --upgrade -r requirements-base.txt
deactivate
cd "ffplayout/frontend"
rm -rf node_modules
sudo -H -u $serviceUser bash -c 'npm install'
sudo -H -u $serviceUser bash -c 'npm run build'
echo ""
echo "------------------------------------------------------------------------------"
echo "updating ffplayout-gui done..."
echo "------------------------------------------------------------------------------"
else
echo ""
echo "------------------------------------------------------------------------------"
echo "WARNING: no ffplayout-gui found..."
echo "------------------------------------------------------------------------------"
fi
echo ""
echo "------------------------------------------------------------------------------"
echo "updating done..."
echo "if there is a new ffmpeg version, run:"
echo " systemctl stop ffplayout-engine"
echo " cp /opt/ffmpeg-build/local/bin/ff* /usrlocal/bin"
echo " systemctl start ffplayout-engine"
echo ""
echo "to apply update restart services:"
echo " systemctl restart ffplayout-engine"
echo " systemctl restart ffplayout-api"
}
if [[ "$1" == "update" ]]; then
runUpdate
else
runInstall
fi