fabrica/.packer/provisioning/common.sh

51 lines
820 B
Bash

#!/bin/sh
#
# downloadArchive
# ${1} : The download url
# ${2} : the checksum
# ${3} : the filename of download target
# ${4} : the checksum command to use (default sha256sum)
#
downloadArchive(){
url=${1}
sum=${2}
archive=${3}
if [ -n ${4} ]
then
checkCmd=${4}
else
checkCmd="sha256sum"
fi
wget -q ${url}
set +e
echo "${sum} ${archive}" | ${checkCmd} -cs
if [ ${?} ]
then
set -e
return 0
else
set -e
return 2
fi
}
extractArchiveXZ(){
source=${1}
destination=${2}
cmd="tar xzvf"
if [ ! -d ${destination} ]
then
mkdir -p ${destination}
fi
${cmd} ${source} -C ${destination}
return ${?}
}
cleanUpImage(){
rm -rf /var/cache/apk/*
rm -rf /tmp/*
rm -rf /root/.ssh
}