Rewrite code & up to version 2.0

This commit is contained in:
q3aql 2021-03-12 17:47:33 +01:00
parent c6034c7394
commit 03a69bcbae

View File

@ -1,170 +1,208 @@
#!/bin/bash #!/bin/bash
# Script to install FFmpeg on GNU/Linux ########################################################
# Website: https://www.johnvansickle.com/ffmpeg/ # Script to install FFmpeg on GNU/Linux #
# Created by q3aql (q3aql@protonmail.ch) # Website: https://www.johnvansickle.com/ffmpeg/ #
# Builds by John Van Sickle (john.vansickle@gmail.com) # Created by q3aql (q3aql@protonmail.ch) #
# Licensed by GPL v.2 # Builds by John Van Sickle (john.vansickle@gmail.com) #
# Date: 22-03-2019 # Licensed by GPL v2.0 #
# -------------------------------------- # Date: 12-03-2021 #
VERSION=1.2.1 ########################################################
VERSION="v2.0"
M_DATE="100321"
# Variables
URL=https://www.johnvansickle.com/ffmpeg/ URL=https://www.johnvansickle.com/ffmpeg/
URL_RELEASES=https://johnvansickle.com/ffmpeg/releases/ URL_RELEASES=https://johnvansickle.com/ffmpeg/releases/
URL_BUILDS=https://johnvansickle.com/ffmpeg/builds/ URL_BUILDS=https://johnvansickle.com/ffmpeg/builds/
TMP_DIR=/tmp TMP_DIR=/tmp
PATH_INSTALL=/usr/bin/ PATH_INSTALL=/usr/bin/
# Downloader
APP_DOWNLOAD="x"
NAME_APP_DOWNLOAD="x"
# Check if 'user' is 'root'
user=$(whoami)
if [ "$user" == "root" ] ; then
echo "OK" > /dev/null
else
echo "You must be root!"
exit 0
fi
# Detect "kernel" name # Function to check root permission
KERNEL=$(uname -s) function rootMessage() {
mkdir -p /etc/root &> /dev/null
if [ $KERNEL == "Linux" ]; then administrator=$?
KERNEL=linux if [ ${administrator} -eq 0 ] ; then
else rm -rf /etc/root
echo "Unsupported OS ($KERNEL)"
exit 0
fi
# Detect "arch" system
archs=`uname -m`
case "$archs" in
i?86)
ARCH=i686
;;
x86_64)
ARCH=amd64
;;
*)
echo "Unsupported Arquitecture ($archs)"
exit 0
esac
#Check if 'curl' is installed.
curl --help > /dev/null
if [ "$?" -eq 0 ] ; then
echo "OK" > /dev/null
else else
echo "You must install 'curl'." echo ""
echo "* ffmpeg-install ${VERSION} (${M_DATE}) (GPL v2.0)"
echo ""
echo "+ Root permissions are required!"
echo ""
exit
fi fi
}
# Function to detect "kernel" name
function kernelCheck() {
KERNEL=$(uname -s)
if [ $KERNEL == "Linux" ]; then
KERNEL=linux
else
echo ""
echo "* ffmpeg-install ${VERSION} (${M_DATE}) (GPL v2.0)"
echo ""
echo "+ Unsupported OS ($KERNEL)"
echo ""
exit
fi
}
# Function to detect "arch" system.
function archCheck() {
archs=`uname -m`
case "$archs" in
i?86)
ARCH=i686
;;
x86_64)
ARCH=amd64
;;
*)
echo ""
echo "* ffmpeg-install ${VERSION} (${M_DATE}) (GPL v2.0)"
echo ""
echo "+ Unsupported Arquitecture ($archs)"
echo ""
exit
esac
}
# Function to check if 'curl' is installed.
function curlCheck () {
curl --help &> /dev/null
if [ "$?" -eq 0 ] ; then
echo "OK" > /dev/null
else
echo ""
echo "* ffmpeg-install ${VERSION} (${M_DATE}) (GPL v2.0)"
echo ""
echo "+ Error: You must install 'curl'."
echo ""
exit
fi
}
# Check available downloaders (wget, axel or aria2c). # Function to check available downloaders (wget, axel or aria2c).
wget --help > /dev/null function checkDownloader() {
if [ "$?" -eq 0 ] ; then # Check wget installed
APP_DOWNLOAD='wget -c' wget --help &> /dev/null
NAME_APP_DOWNLOAD="wget" checkWget="$?"
else # Check axel installed
echo "wget disabled" axel --help &> /dev/null
fi checkAxel="$?"
# Check aria2c installed
axel --help > /dev/null aria2c --help &> /dev/null
if [ "$?" -eq 0 ] ; then checkAria2="$?"
APP_DOWNLOAD='axel' # Check variables
NAME_APP_DOWNLOAD="axel" if [ ${checkAria2} -eq 0 ] ; then
else APP_DOWNLOAD='aria2c --check-certificate=false'
echo "axel disabled" NAME_APP_DOWNLOAD="aria2c"
fi elif [ ${checkAxel} -eq 0 ] ; then
APP_DOWNLOAD='axel'
NAME_APP_DOWNLOAD="axel"
elif [ ${checkWget} -eq 0 ] ; then
APP_DOWNLOAD='wget -c'
NAME_APP_DOWNLOAD="wget"
elif [ "x${APP_DOWNLOAD}" = "x" ] ; then
echo ""
echo "* ffmpeg-install ${VERSION} (${M_DATE}) (GPL v2.0)"
echo ""
echo "+ Error: You must install 'wget' or 'axel' or 'aria2'."
echo ""
exit
fi
}
aria2c --help > /dev/null # Check all configs
if [ "$?" -eq 0 ] ; then rootMessage
APP_DOWNLOAD='aria2c --check-certificate=false' kernelCheck
NAME_APP_DOWNLOAD="aria2c" archCheck
else curlCheck
echo "aria2c disabled" checkDownloader
fi
if [ "x$APP_DOWNLOAD" = "x" ] ; then # Sintax to install, update and uninstall FFmpeg.
echo "Error: You must install 'wget' or 'axel' or 'aria2'." case ${1} in
fi --install|-install|--update|-update)
cd ${TMP_DIR}
#Install, update & uninstall FFmpeg rm -rf ffmpeg-*
case $1 in echo ""
echo "* ffmpeg-install ${VERSION} (${M_DATE}) (GPL v2.0)"
--install|-install|--update|-update) echo ""
cd $TMP_DIR if [ "${2}" == "release" ] ; then
rm -rf ffmpeg-* curl ${URL} | grep "${URL_RELEASES}" | cut -d '"' -f 2 | grep "${ARCH}" | head -1 > $TMP_DIR/ffmpeg-url
if [ "$2" == "release" ] ; then if [ "$?" -eq 0 ] ; then
curl $URL | grep "$URL_RELEASES" | cut -d '"' -f 2 | grep "$ARCH" | head -1 > $TMP_DIR/ffmpeg-url echo "OK" > /dev/null
if [ "$?" -eq 0 ] ; then else
echo "OK" > /dev/null echo "+ Connection problem!"
else echo "* Exiting..."
echo "Connection problem!" exit
echo "Exiting..." fi
exit else
fi curl ${URL} | grep "${URL_BUILDS}" | cut -d '"' -f 2 | grep "${ARCH}" | head -1 > $TMP_DIR/ffmpeg-url
else if [ "$?" -eq 0 ] ; then
curl $URL | grep "$URL_BUILDS" | cut -d '"' -f 2 | grep "$ARCH" | head -1 > $TMP_DIR/ffmpeg-url echo "OK" > /dev/null
if [ "$?" -eq 0 ] ; then else
echo "OK" > /dev/null echo "+ Connection problem!"
else echo "* Exiting..."
echo "Connection problem!" exit
echo "Exiting..." fi
exit fi
fi URL_PACKAGE=`cat $TMP_DIR/ffmpeg-url`
fi NAME_PACKAGE=`cat /tmp/ffmpeg-url | cut -d "/" -f 6`
URL_PACKAGE=`cat $TMP_DIR/ffmpeg-url` #clear
NAME_PACKAGE=`cat /tmp/ffmpeg-url | cut -d "/" -f 6` echo "* Downloading ${NAME_PACKAGE} (${NAME_APP_DOWNLOAD})"
clear ${APP_DOWNLOAD} ${URL_PACKAGE}
echo "Downloading $NAME_PACKAGE ($NAME_APP_DOWNLOAD)" if [ "$?" -eq 0 ] ; then
$APP_DOWNLOAD $URL_PACKAGE echo "OK" > /dev/null
if [ "$?" -eq 0 ] ; then else
echo "OK" > /dev/null echo ""
else echo "+ Connection problem!"
echo "Connection problem!" echo "* Exiting..."
echo "Exiting..." exit
exit
fi fi
tar Jxvf $NAME_PACKAGE tar Jxvf ${NAME_PACKAGE}
rm -f ffmpeg-url ffmpeg*xz rm -f ffmpeg-url ffmpeg*xz
cd ffmpeg-* cd ffmpeg-*
cp -rf ffmpeg $PATH_INSTALL cp -rfv ffmpeg ${PATH_INSTALL}
cp -rf ffprobe $PATH_INSTALL cp -rfv ffprobe ${PATH_INSTALL}
cd .. cd ..
rm -rf ffmpeg-* rm -rf ffmpeg-*
echo "Done!" echo "* Finished!"
exit 0 exit
;; ;;
--uninstall|-uninstall) --uninstall|-uninstall)
echo "Uninstalling..." echo ""
sleep 3 echo "* ffmpeg-install ${VERSION} (${M_DATE}) (GPL v2.0)"
rm -rf /usr/bin/ffmpeg echo ""
rm -rf /usr/bin/ffprobe echo "* Uninstalling FFmpeg..."
rm -rf /usr/bin/ffserver sleep 3
rm -rf /usr/bin/ffmpeg-10bit rm -rfv /usr/bin/ffmpeg
echo "Done!" rm -rfv /usr/bin/ffprobe
;; echo "* Finished!"
--help|-help|-h|*) ;;
clear --help|-help|-h|*)
echo "" echo ""
echo "** ffmpeg-install v.$VERSION **" echo "* ffmpeg-install ${VERSION} (${M_DATE}) (GPL v2.0)"
echo "" echo ""
echo "* How to install:" echo "* Script: q3aql (q3aql@protonmail.ch)"
echo "" echo "* Builds: John Van Sickle (john.vansickle@gmail.com)"
echo " ffmpeg-install --install (Latest git version)" echo ""
echo " ffmpeg-install --install release (Latest stable version)" echo "+ Sintax:"
echo "" echo ""
echo "* How to update:" echo " $ ffmpeg-install --install --> Install FFmpeg (Git version)"
echo "" echo " $ ffmpeg-install --install release --> Install FFmpeg (Stable version)"
echo " ffmpeg-install --update (Latest git version)" echo " $ ffmpeg-install --update --> Update FFmpeg (Git version)"
echo " ffmpeg-install --update release (Latest stable version)" echo " $ ffmpeg-install --update release --> Update FFmpeg (Stable version)"
echo "" echo " $ ffmpeg-install --uninstall --> Uninstall FFmpeg previously installed"
echo "* How to uninstall:" echo " $ ffmpeg-install --help --> Show help"
echo "" echo ""
echo " ffmpeg-install --uninstall" exit
echo ""
echo "* Show help:"
echo ""
echo " ffmpeg --help"
echo ""
exit 0
esac esac