Update build and pack scripts

This commit is contained in:
Daniel 2019-03-13 14:34:32 +01:00
parent 4eed7d8bc0
commit 98d12c9f7b
2 changed files with 55 additions and 27 deletions

View file

@ -5,9 +5,9 @@ cd "$baseDir"
COL_OFF="\033[00m" COL_OFF="\033[00m"
COL_BOLD="\033[01;01m" COL_BOLD="\033[01;01m"
COL_YELLOW="\033[33m" COL_RED="\033[31m"
destDirPart1="./dist" destDirPart1="dist"
destDirPart2="core" destDirPart2="core"
function check { function check {
@ -15,14 +15,16 @@ function check {
version=$(grep "info.Set" main.go | cut -d'"' -f4) version=$(grep "info.Set" main.go | cut -d'"' -f4)
# build versioned file name # build versioned file name
filename="portmaster_v${version//./-}" filename="portmaster_v${version//./-}"
# platform
platform="${GOOS}_${GOARCH}"
# build destination path # build destination path
destPath=${destDirPart1}/linux_amd64/${destDirPart2}/$filename destPath=${destDirPart1}/${platform}/${destDirPart2}/$filename
# check if file exists # check if file exists
if [[ -f $destPath ]]; then if [[ -f $destPath ]]; then
echo "[core] linux_amd64 $version already built" echo "[core] $platform $version already built"
else else
echo -e "${COL_BOLD}[core] linux_amd64 $version${COL_OFF}" echo -e "${COL_BOLD}[core] $platform $version${COL_OFF}"
fi fi
} }
@ -31,40 +33,52 @@ function build {
version=$(grep "info.Set" main.go | cut -d'"' -f4) version=$(grep "info.Set" main.go | cut -d'"' -f4)
# build versioned file name # build versioned file name
filename="portmaster_v${version//./-}" filename="portmaster_v${version//./-}"
# platform
platform="${GOOS}_${GOARCH}"
# build destination path # build destination path
destPath=${destDirPart1}/linux_amd64/${destDirPart2}/$filename destPath=${destDirPart1}/${platform}/${destDirPart2}/$filename
# check if file exists # check if file exists
if [[ -f $destPath ]]; then if [[ -f $destPath ]]; then
echo "core[linux_amd64] already built in version $version, skipping..." echo "[core] $platform already built in version $version, skipping..."
exit 0 exit 0
fi fi
# build # build
GOOS=linux GOARCH=amd64 ./build main.go ./build main.go
cp main $destPath
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo -e "\nlinux_amd64: BUILD FAILED." echo -e "\n${COL_BOLD}[core] $platform: ${COL_RED}BUILD FAILED.${COL_OFF}"
exit 1 exit 1
fi fi
mkdir -p $(dirname $destPath)
cp main $destPath
echo -e "\n${COL_BOLD}[core] $platform: successfully built.${COL_OFF}"
}
function check_all {
GOOS=linux GOARCH=amd64 check
}
function build_all {
GOOS=linux GOARCH=amd64 build
} }
case $1 in case $1 in
"check" ) "check" )
check check_all
;; ;;
"build" ) "build" )
build build_all
;; ;;
* ) * )
echo "" echo ""
echo "build list:" echo "build list:"
echo "" echo ""
check check_all
echo "" echo ""
read -p "press [Enter] to start building" x read -p "press [Enter] to start building" x
echo "" echo ""
build build_all
echo "" echo ""
echo "finished building." echo "finished building."
echo "" echo ""

View file

@ -5,7 +5,7 @@ cd "$baseDir"
COL_OFF="\033[00m" COL_OFF="\033[00m"
COL_BOLD="\033[01;01m" COL_BOLD="\033[01;01m"
COL_YELLOW="\033[33m" COL_RED="\033[31m"
destDirPart1="../dist" destDirPart1="../dist"
destDirPart2="pmctl" destDirPart2="pmctl"
@ -15,14 +15,16 @@ function check {
version=$(grep "info.Set" main.go | cut -d'"' -f4) version=$(grep "info.Set" main.go | cut -d'"' -f4)
# build versioned file name # build versioned file name
filename="pmctl_v${version//./-}" filename="pmctl_v${version//./-}"
# platform
platform="${GOOS}_${GOARCH}"
# build destination path # build destination path
destPath=${destDirPart1}/linux_amd64/${destDirPart2}/$filename destPath=${destDirPart1}/${platform}/${destDirPart2}/$filename
# check if file exists # check if file exists
if [[ -f $destPath ]]; then if [[ -f $destPath ]]; then
echo "[pmctl] linux_amd64 $version already built" echo "[pmctl] $platform $version already built"
else else
echo -e "${COL_BOLD}[pmctl] linux_amd64 $version${COL_OFF}" echo -e "${COL_BOLD}[pmctl] $platform $version${COL_OFF}"
fi fi
} }
@ -31,40 +33,52 @@ function build {
version=$(grep "info.Set" main.go | cut -d'"' -f4) version=$(grep "info.Set" main.go | cut -d'"' -f4)
# build versioned file name # build versioned file name
filename="pmctl_v${version//./-}" filename="pmctl_v${version//./-}"
# platform
platform="${GOOS}_${GOARCH}"
# build destination path # build destination path
destPath=${destDirPart1}/linux_amd64/${destDirPart2}/$filename destPath=${destDirPart1}/${platform}/${destDirPart2}/$filename
# check if file exists # check if file exists
if [[ -f $destPath ]]; then if [[ -f $destPath ]]; then
echo "pmctl[linux_amd64] already built in version $version, skipping..." echo "[pmctl] $platform already built in version $version, skipping..."
exit 0 exit 0
fi fi
# build # build
GOOS=linux GOARCH=amd64 ./build ./build
cp pmctl $destPath
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo -e "\nlinux_amd64: BUILD FAILED." echo -e "\n${COL_BOLD}[pmctl] $platform: ${COL_RED}BUILD FAILED.${COL_OFF}"
exit 1 exit 1
fi fi
mkdir -p $(dirname $destPath)
cp pmctl $destPath
echo -e "\n${COL_BOLD}[pmctl] $platform: successfully built.${COL_OFF}"
}
function check_all {
GOOS=linux GOARCH=amd64 check
}
function build_all {
GOOS=linux GOARCH=amd64 build
} }
case $1 in case $1 in
"check" ) "check" )
check check_all
;; ;;
"build" ) "build" )
build build_all
;; ;;
* ) * )
echo "" echo ""
echo "build list:" echo "build list:"
echo "" echo ""
check check_all
echo "" echo ""
read -p "press [Enter] to start building" x read -p "press [Enter] to start building" x
echo "" echo ""
build build_all
echo "" echo ""
echo "finished building." echo "finished building."
echo "" echo ""