export PATH inside a bash script - bash

I am install ffmpeg from source in my bash script.However although i have source /etc/environment after i install ffmpeg dependancies, ffmpeg compilation isn't able to see the dependencies yasm/nasm.After the script is fully run i need to manually run source /etc/environment and then rerun compile ffmpeg again.
Full script is shown below
#!/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

Instead of:
echo "export PATH=$PATH:/usr/local/bin" >> /etc/environment
source /etc/environment
try this:
echo "export PATH=/usr/local/bin:$PATH" >> /etc/environment
source /etc/environment

Related

chmod +x cant find build.sh file

I have been trying to make a VCS in C++ but the build file is not running in my LINUX(Ubuntu).
It is prompting the above message.
my build file is as follows:
#!/bin/bash
sudo apt-get update
udo apt-get install openssl -y
sudo apt-get install libssl-dev -y
mkdir -p ~/imperium/bin
cp imperium.sh ~/imperium
cd ..
make
cd ~/imperium/bin || echo "error"
chmod +x main
cd ..
if grep -q "source $PWD/imperium.sh" "$PWD/../.bashrc" ; then
echo 'already installed bash source';
else
echo "source $PWD/imperium.sh" >> ~/.bashrc;
fi
my imperium.sh file is also as follows:
function imperium(){
DIR=$PWD
export dir=$DIR
cd ~/imperium/bin || echo "Error"
./main "$#"
cd "$DIR" || echo "Error"
}
I will be heavily obliged if any one can solve this problem of mine. After chmod I have been doing:
./build.sh but its prompting that build.sh file does not exists.
For me it seems you have a typo right in the 3rd row "udo" ->
"sudo".
Also, You should avoid using cd .. and use relative paths for
the commands.

Singularity 3.6.2 Installation

I have problems with installation of singularity 3.6.2 in linux mint, I followed the instructions of https://sylabs.io/guides/3.0/user-guide/installation.html.
I installed the dependencies and Go.
Then I run the command for install the latest version:
export VERSION=3.6.2 && # adjust this as necessary \
mkdir -p $GOPATH/src/github.com/sylabs && \
cd $GOPATH/src/github.com/sylabs && \
wget https://github.com/sylabs/singularity/releases/download/v${VERSION}/singularity-${VERSION}.tar.gz && \
tar -xzf singularity-${VERSION}.tar.gz && \
cd ./singularity && \
./mconfig
The error is:
Configuring for project `singularity' with languages: C, Golang
=> running pre-basechecks project specific checks ...
=> running base system checks ...
checking: host C compiler... cc
checking: host C++ compiler... c++
checking: host Go compiler (at least version 1.13)... not found!
mconfig: could not complete configuration
I have go (go version)
go version go1.15.2 linux/amd64
I don't know what happend!
Thanks so much!
I was struggling with the same error. All the suggestions say that probably you have an older version of Go and that's why. But turned out it's even more important to place Go and Singularity in the right locations.
I found these docs https://github.com/hpcng/singularity/blob/release-3.5/INSTALL.md are the most useful and correct about where to put what in terms of directories.
The key is to clone Singularity in a directory which is GOPATH:
You won't have this directory by default so create it first
$ mkdir -p ${GOPATH}/src/github.com/sylabs && \
cd ${GOPATH}/src/github.com/sylabs && \
git clone https://github.com/sylabs/singularity.git && \
cd singularity
Make sure your singularity is here: {GOPATH}/src/github.com/sylabs/singularity
To summarize:
The Go itself is located here /usr/local/go
GOPATH would be something like home/your_username/go and the singularity will be located inside in e.g. home/your_username/go/src/github.com/sylabs/singularity
The issue was reported in 5099.
# 5320 also mentions:
I deleted the PPO python 3.6 and this worked fine!
Make sure nothing is executed as root, which would have a $PATH different from your current user.
If someone faces this issue, follow this installation guide.
sudo apt-get update && \
sudo apt-get install -y build-essential \
libseccomp-dev pkg-config squashfs-tools cryptsetup
sudo rm -r /usr/local/go
export VERSION=1.13.15 OS=linux ARCH=amd64 # change this as you need
wget -O /tmp/go${VERSION}.${OS}-${ARCH}.tar.gz https://dl.google.com/go/go${VERSION}.${OS}-${ARCH}.tar.gz && \
sudo tar -C /usr/local -xzf /tmp/go${VERSION}.${OS}-${ARCH}.tar.gz
echo 'export GOPATH=${HOME}/go' >> ~/.bashrc && \
echo 'export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin' >> ~/.bashrc && \
source ~/.bashrc
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh |
sh -s -- -b $(go env GOPATH)/bin v1.21.0
mkdir -p ${GOPATH}/src/github.com/sylabs && \
cd ${GOPATH}/src/github.com/sylabs && \
git clone https://github.com/sylabs/singularity.git && \
cd singularity
git checkout v3.6.3
cd ${GOPATH}/src/github.com/sylabs/singularity && \
./mconfig && \
cd ./builddir && \
make && \
sudo make install
singularity version

Need assistance in converting Makefile to Shell script

Need your help to convert code in Makefile to Shell script? Please help as I am new to both MakeFile and Shell Scripting.Thanks.
Sample Code:
include Configfile
.PHONY: config-arch asoc-tool clone-repo generate-irx api-login \
upload-file get-app run-scan show-scan-id get-asset-group create-app
config-arch:
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
asoc-tool: config-arch
$(eval DIR := $(shell pwd))
curl -o client.zip $(APPSCAN_TOOL)
mkdir client ; mkdir tool
unzip -qq client.zip -d client
cd client ; ls | xargs -I {} sh -c "cp -r {}/* $(DIR)/tool"
rm -rf client
clone-repo:
git clone $(GIT_REPO)
# Generates the irx file for icp-cert-manager.
generate-irx:
$(eval DIR := $(shell pwd))
cd $(PROJECT_NAME); $(DIR)/tool/bin/appscan.sh prepare $(flag)
#!/bin/sh
# config-arch
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
# asoc-tool
curl -o client.zip $(APPSCAN_TOOL)
mkdir client ; mkdir tool
unzip -qq client.zip -d client
cd client ; ls | xargs -I {} sh -c "cp -r {}/* ./tool"
rm -rf client
# clone repo
git clone ${GIT_REPO} # you should overwrite ${GIT_REPO} to your git repo, maybe from Configfile
# generate-irx
cd $(PROJECT_NAME)
./tool/bin/appscan.sh prepare ${flag} # you should check your ${flag}, maybe from Configfile

Command `source` doesn't work in Dockerfile

I want build my images, here is my Dockerfile:
FROM ubuntu:16.04
MAINTAINER 'hulei886#aliyun.com'
ENV PHANTOMJS_VERSION 2.1.1
ENV PYTHON_VERSION 3.6.3
# install python3.6.3
RUN apt-get update \
&& apt-get install -y build-essential \
git \
curl \
libssl-dev \
zlib1g-dev \
libncurses5-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
&& apt-get install -y libgdbm-dev \
libdb5.3-dev \
libbz2-dev \
libexpat1-dev \
liblzma-dev \
tk-dev \
&& cd ~ \
&& git clone https://github.com/pyenv/pyenv.git .pyenv \
&& echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc \
&& echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc \
&& echo 'eval "$(pyenv init -)"' >> ~/.bashrc \
&& source ~/.bashrc \
&& curl -L https://raw.githubusercontent.com/yyuu/pyenv- installer/master/bin/pyenv-installer | bash \
&& pyenv install PYTHON_VERSION \
&& pyenv global PYTHON_VERSION \
&& cd .. \
CMD [python]
but when i run "docker build . -t [mytag]",
git clone command didn't clone anything,here is screenshot:
I need help to fix this problem,thanks!
The error message is pretty clear:
/bin/sh: 1: source: not found
No problem with git clone but with source in a /bin/sh shell. You need to use the . (dot) command instead.
When writing a Dockerfile, it's better to test the commands in a container with /bin/sh shell.
In your case, after the source error, there are other errors:
space in the curl URL
env variable wrongly used: missing $ prefix
useless cd ~: only WORKDIR instruction will change the current directory when running containers from the resulting image
CMD instruction wrongly inserted in the RUN instruction
A fixed version would be:
[...]
&& git clone https://github.com/pyenv/pyenv.git .pyenv \
&& echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc \
&& echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc \
&& echo 'eval "$(pyenv init -)"' >> ~/.bashrc \
&& . ~/.bashrc \
&& curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash \
&& pyenv install $PYTHON_VERSION \
&& pyenv global $PYTHON_VERSION
WORKDIR /root
CMD [python]
You have to use source alternative in bash. You can do something like
. somefile
instead of
source somefile

How do I add an updated ghostscript to AWS EC2 Instance with Amazon Linux AMI

How can I get 9.20 - the current version?
(I'm doing the research and will answer as I finish.)
This answer is an update to the now stale answer here, with a few extra details and a reference to the current repo location.
This may be obvious to the more experienced, but this is intended to help those less experienced with CLI/make/gcc who just need gs.
First set up gcc-c++ if you haven't already [Are all packages necessary? Last two seem to be not needed.]:
sudo yum install -y gcc gcc-c++ compat-gcc-32 compat-gcc-32-c++
Then download, make and install ghostscript:
wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs920/ghostscript-9.20.tar.gz
tar -zxvf ghostscript-9.20.tar.gz
cd ghostscript-9.20
./configure --prefix=/usr --enable-dynamic --disable-compile-inits --with-system-libtiff
make
make so
sudo make install
sudo chmod go+w /usr/include/ghostscript/
sudo make soinstall && install -v -m644 base/*.h /usr/include/ghostscript && sudo ln -v -s ghostscript /usr/include/ps
sudo ln -sfv ../ghostscript/9.20/doc /usr/share/doc/ghostscript-9.20
cd ..
wget http://sourceforge.net/projects/gs-fonts/files/latest/download?source=files --output-document=ghostscript-fonts-std-8.11.tar.gz
sudo tar -xvf ghostscript-fonts-std-8.11.tar.gz -C /usr/share/ghostscript
fc-cache -v /usr/share/ghostscript/fonts/
sudo mkdir /usr/include/ghostscript/
sudo chmod go-w /usr/include/ghostscript/
ghostscript -v
gs -v
You could put the source code on the instance and compile it.....
Met an error when ran
sudo chmod go+w /usr/include/ghostscript/
because the folder didn't exist yet.
So I did minor adjustment to the command order:
wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs920/ghostscript-9.20.tar.gz
tar -zxvf ghostscript-9.20.tar.gz
cd ghostscript-9.20
./configure --prefix=/usr --enable-dynamic --disable-compile-inits --with-system-libtiff
make
make so
sudo make install
sudo mkdir /usr/include/ghostscript/
sudo chmod go+w /usr/include/ghostscript/
sudo make soinstall && install -v -m644 base/*.h /usr/include/ghostscript && sudo ln -v -s ghostscript /usr/include/ps
sudo ln -sfv ../ghostscript/9.20/doc /usr/share/doc/ghostscript-9.20
cd ..
wget http://sourceforge.net/projects/gs-fonts/files/latest/download?source=files --output-document=ghostscript-fonts-std-8.11.tar.gz
sudo tar -xvf ghostscript-fonts-std-8.11.tar.gz -C /usr/share/ghostscript
fc-cache -v /usr/share/ghostscript/fonts/
sudo chmod go-w /usr/include/ghostscript/
ghostscript -v
gs -v

Resources