I've bash script to load docker images once the application is installed (postinstall script).
Using command manually on the terminal is working, but from postinstall script getting:
docker: command not found
Tried, executing docker with absolute path (which docker) adding the path variable of docker (execute PATH=\usr\bin\docker:$PATH)
Is there something wrong with my macOS or script is wrong.
Original script: I m checking the macOS chip and then using command docker info trying if docker is installed if its installed loading the images from the working directory otherwise installing docker first and then loading images.
#!/bin/bash
#
#
#
CheckVar=`which docker`
echo "$CheckVar"
if [[ `sysctl machdep.cpu.brand_string` == *"Intel"* ]]
then
if [[ `$CheckVar info` == *"Client"* ]];
then
echo "Mac Chip is Intel"
echo "Docker found!"
cd $Home/$DSTROOT/App
echo "Redirected to working dir.."
sudo `$CheckVar load -i app.tar`
echo "Success"
else
echo "Mac Chip is Intel"
echo "Docker not found installing"
cd $Home/$DSTROOT/App
echo "Redirected to working dir.."
sudo hdiutil attach IntelDocker.dmg
sudo /Volumes/Docker/Docker.app/Contents/MacOS/install
sudo hdiutil detach /Volumes/Docker
sudo `$CheckVar load -i app.tar`
echo "Success"
fi
else
if [[ `$CheckVar info` == *"Client"* ]];
then
echo "Mac Chip is AppleSilicon"
echo "Docker found!"
cd $Home/$DSTROOT/App
echo "Redirected to working dir.."
sudo `$CheckVar load -i app.tar`
echo "Success"
else
echo "Mac Chip is AppleSilicon"
echo "Docker not found installing"
cd $Home/$DSTROOT/App
echo "Redirected to working dir.."
sudo hdiutil attach IntelDocker.dmg
sudo /Volumes/Docker/Docker.app/Contents/MacOS/install
sudo hdiutil detach /Volumes/Docker
sudo `$CheckVar load -i app.tar`
echo "Success"
fi
fi
Any solutions? been trying to solve this issue past 3 days.
CodePudding user response:
First make sure your PATH
is valid. It should contain the directory
which the docker
executable is stored in. Not the absolute path to the executable. Also, execute PATH
is not how you set the value. You use export
export PATH=/usr/bin:$PATH
Change your tests from:
[ `$CheckVar info` == *"Client"* ]]
to [ "$CheckVar" ]
from man test
:
-n STRING
the length of STRING is nonzero
STRING equivalent to -n STRING
The CheckVar
variable is empty in the case where docker wasn't found on the system. Reset it in your else
statements after installing docker.
sudo /Volumes/Docker/Docker.app/Contents/MacOS/install
sudo hdiutil detach /Volumes/Docker
CheckVar=`which docker`
sudo $CheckVar load -i app.tar