在bash脚本中导出PATH

时间:2018-03-04 08:08:17

标签: bash unix

我是在我的bash脚本中从源安装ffmpeg。但是在我安装ffmpeg dependancies之后我有source /etc/environment,ffmpeg编译是不能看到依赖yasm/nasm。脚本之后完全运行我需要手动运行source /etc/environment然后重新运行编译ffmpeg。

完整脚本如下所示

#!/bin/bash
#####################################################
#                                                   #
# Author : Khavish Anshudass Bhundoo                #
# License : MIT                                     #
# Install dependencies needed for compression test  #
#####################################################
echo "This script will install softwares needed to run compression_test.sh"
if [ "$EUID" -ne 0 ]
  then echo "This script must be run as root user....exiting"
  exit
fi

rm -f /var/cache/yum/timedhosts.txt
yum -y -q install redhat-lsb-core deltarpm
version=$(lsb_release -sr | sed 's/\.[^ ]*/ /g') #Version = 7
echo "Setting Up EPEL and remi Repositories" 
{
yum install -y -q epel-release
rpm --quiet --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
rpm --quiet --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm --quiet -ivh http://rpms.famillecollet.com/enterprise/remi-release-${version:0:1}.rpm
} &> /dev/null

echo "Updating System...This may take a while"
{ 
yum clean all &> /dev/null
package-cleanup --cleandupes > /dev/null
yum -y -q update 
systemctl daemon-reload
} &> /dev/null

#Installing some commonly used tools
echo "Installing tools needed by script or compilation"
{
yum -y -q install deltarpm
yum clean all &> /dev/null
yum -y groupinstall "Development Tools" &> /dev/null
rpm --quiet -ivh https://download-mirror.savannah.gnu.org/releases/datamash/datamash-1.2-1agn.el6.x86_64.rpm
yum -y -q install nano wget make htop mlocate unzip git bc parallel gnuplot libpng-devel ninja-build 
updatedb
} 2>&1 | grep -v "already installed and latest version"

echo "Install bazel"
{
wget -q https://copr.fedorainfracloud.org/coprs/vbatts/bazel/repo/epel-7/vbatts-bazel-epel-7.repo -P /etc/yum.repos.d/
yum -y -q install bazel
} &> /dev/null

#Update path for all users
#echo "export PATH=\$PATH:/usr/local/bin" >> /etc/profile
echo "export PATH=$PATH:/usr/local/bin" >> /etc/environment
source /etc/environment

#Optimize OpenCV install by not relying on third party script to make full use of Ninja and make -j

echo "Installing OpenCV(This might take a while)"
{
cd "$HOME"
git clone https://github.com/jayrambhia/Install-OpenCV
cd Install-OpenCV
cd RedHat
chmod +x * 
sed -i '1s/^/version="2.4.13"\n/' opencv_install.sh
sed -i '1s/^/downloadfile="opencv-2.4.13.zip"\n/' opencv_install.sh
sed -i '1s/^/downloadfile="opencv-2.4.13.zip"\n/' opencv_install.sh
sed -i '/cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ../c\cmake -G Ninja -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..' opencv_install.sh
./opencv_install.sh
} &> /dev/null

number_of_cores=$(nproc)
shopt -s expand_aliases
alias make="/usr/bin/make -j$number_of_cores"

echo "Installing libjpeg"
{
cd "$HOME"
git clone https://github.com/thorfdbg/libjpeg
cd libjpeg
make 
cp jpeg /usr/local/bin
} &> /dev/null

echo "Installing butteraugli"
{
cd "$HOME"
git clone https://github.com/google/butteraugli
cd butteraugli
bazel build -c opt //:butteraugli
cd bazel-bin
chmod +x butteraugli
cp butteraugli /usr/local/bin
} &> /dev/null

echo "Installing guetzli"
{
cd "$HOME"
git clone https://github.com/google/guetzli
cd guetzli
bazel build -c opt //:guetzli
chmod +x bazel-bin/guetzli
cp bazel-bin/guetzli /usr/local/bin
} &> /dev/null



echo "Installing Ssimulacra"
{
cd "$HOME"
git clone https://github.com/cloudinary/ssimulacra
cd ssimulacra 
make
chmod +x ssimulacra
cp ssimulacra /usr/local/bin
} &> /dev/null

echo "Installing Imagemagick7"
{
yum --enablerepo=remi -y -q install ImageMagick7*
} &> /dev/null

echo "Installing Pik"
{
cd "$HOME"
git clone https://github.com/google/pik
cd pik
git submodule init && git submodule update
make 
cd bin
chmod +x *
cp * /usr/local/bin
} &> /dev/null

echo "Installing Webp"
{
cd "$HOME"
wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.6.1-linux-x86-64.tar.gz 
tar -xzf libwebp-0.6.1-linux-x86-64.tar.gz 
cd libwebp-0.6.1-linux-x86-64/bin
cp * /usr/local/bin
} &> /dev/null


echo "Installing ffmpeg(This might take some time)"
{
cd "$HOME"
yum  -y -q install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel
mkdir ~/ffmpeg_sources

#NASM
yum remove -y nasm && hash -r
cd ~/ffmpeg_sources
curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2
tar xjvf nasm-2.13.02.tar.bz2
cd nasm-2.13.02
./autogen.sh
./configure --prefix="$HOME/ffmpeg_build" --bindir="/usr/local/bin"
make
make install

source /etc/environment

#Yasm
cd ~/ffmpeg_sources
curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xzvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure --prefix="$HOME/ffmpeg_build" --bindir="/usr/local/bin"
make
make install

source /etc/environment

#x264
cd ~/ffmpeg_sources
git clone --depth 1 http://git.videolan.org/git/x264
cd x264
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="/usr/local/bin" --enable-static
make
make install

source /etc/environment

#x265
cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
cmake -G "Unix Makefiles" -DBIN_INSTALL_DIR="/usr/local/bin" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source 
make
make install
cp x265 /usr/local/bin

source /etc/environment

#libfdk_aac
cd ~/ffmpeg_sources
git clone --depth 1 https://github.com/mstorsjo/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install

source /etc/environment

#libmp3lame
cd ~/ffmpeg_sources
curl -O -L https://phoenixnap.dl.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
tar xzvf lame-3.100.tar.gz
cd lame-3.100
./configure --prefix="$HOME/ffmpeg_build" --bindir="/usr/local/bin" --disable-shared --enable-nasm
make
make install

source /etc/environment

#libopus
cd ~/ffmpeg_sources
curl -O -L https://archive.mozilla.org/pub/opus/opus-1.2.1.tar.gz
tar xzvf opus-1.2.1.tar.gz
cd opus-1.2.1
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install

source /etc/environment

#libogg
cd ~/ffmpeg_sources
curl -O -L http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.gz
tar xzvf libogg-1.3.3.tar.gz
cd libogg-1.3.3
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install

source /etc/environment

#libvorbis-1.3.5
cd ~/ffmpeg_sources
curl -O -L http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz
tar xzvf libvorbis-1.3.5.tar.gz
cd libvorbis-1.3.5
./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared
make
make install

source /etc/environment

#libvpx
cd ~/ffmpeg_sources
git clone --depth 1 -b v1.6.1 https://chromium.googlesource.com/webm/libvpx.git
cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
make
make install

source /etc/environment

#ffmpeg
cd ~/ffmpeg_sources
curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
    PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --extra-libs=-lpthread \
  --extra-libs=-lm \
  --bindir="/usr/local/bin" \
  --enable-gpl \
  --enable-libfdk_aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree
make
make install
make distclean
hash -r
source /etc/environment
} &> /dev/null

echo "Installing AV1"
{
yum -y -q install cmake3
cd "$HOME"
git clone https://aomedia.googlesource.com/aom
cd aom
aom_directory=$(pwd)
mkdir -p ../aom_build && cd ../aom_build
cmake3 "$aom_directory"
make
cp aomdec aomenc /usr/local/bin                      
} &> /dev/null


echo "Installing OpenJPEG"
{
cd "$HOME"
wget https://github.com/uclouvain/openjpeg/releases/download/v2.3.0/openjpeg-v2.3.0-linux-x86_64.tar.gz
tar -xzf openjpeg-v2.3.0-linux-x86_64.tar.gz
cd openjpeg-v2.3.0-linux-x86_64/bin
cp * /usr/local/bin
} &> /dev/null

echo "Installing FLIF"
{
cd "$HOME"
wget https://github.com/FLIF-hub/FLIF/archive/v0.3.tar.gz -O flif_v0.3.tar.gz
tar -xzf flif_v0.3.tar.gz
cd FLIF-0.3
make && make install
} &> /dev/null

echo "Installing BPG"
{
yum install -y -q SDL*
cd "$HOME"
wget -q https://bellard.org/bpg/libbpg-0.9.7.tar.gz
tar -xzf libbpg-0.9.7.tar.gz
cd libbpg-0.9.7
sed -i '/#USE_JCTVC=y/c\USE_JCTVC=y' Makefile
make && make install
} &> /dev/null


echo "Installing MozJPEG"
{
cd "$HOME"
wget -q https://github.com/mozilla/mozjpeg/releases/download/v3.2/mozjpeg-3.2-release-source.tar.gz
tar -xzf mozjpeg-3.2-release-source.tar.gz
cd mozjpeg
autoreconf -fiv
./configure
make && make install
cd /opt/mozjpeg/bin/
cp * /usr/local/bin
} &> /dev/null

source /etc/environment

1 个答案:

答案 0 :(得分:0)

而不是:

echo "export PATH=$PATH:/usr/local/bin" >> /etc/environment
source /etc/environment

试试这个:

echo "export PATH=/usr/local/bin:$PATH" >> /etc/environment
source /etc/environment