Skip to content

Commit

Permalink
new build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hernandev committed Dec 28, 2020
1 parent 1add3f8 commit 0eaf6bf
Show file tree
Hide file tree
Showing 20 changed files with 436 additions and 417 deletions.
66 changes: 66 additions & 0 deletions bin/builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

# stop on errors.
set -e

# define starting directory.
PA_SOURCES_PATH=$(pwd)

# load variables from scripts config.
# shellcheck disable=SC1090
source "${PA_SOURCES_PATH}/config.sh"

# source helpers.
# shellcheck disable=SC1090
source "${BASH_SOURCE%/*}/helpers/colors.sh"
# shellcheck disable=SC1090
source "${BASH_SOURCE%/*}/helpers/prepare.sh"
# shellcheck disable=SC1090
source "${BASH_SOURCE%/*}/helpers/flags.sh"
# shellcheck disable=SC1090
source "${BASH_SOURCE%/*}/helpers/build.sh"

# ensure starts on sources path.
# shellcheck disable=SC2164
cd "${PA_SOURCES_PATH}"

# update repositories first.
sudo apk update

# run for extra packages.
if [ "$PA_BUILD_EXTRA" = true ]; then
# verbose.
information "running tasks for:" "extra packages."
# loop and build packages.
build_list "${PA_PHP_EXTRA}";
else
warning "skipping:" "extra packages."
fi

# # run for main php package.
if [ "$PA_BUILD_MAIN" = true ]; then
# verbose.
information "running tasks for:" "main (php)."
# update apk so extra packages are available.
sudo apk update
# build package.
build_package "${PA_PHP_MAIN}"
else
warning "skipping:" "main (php)."
fi

# run for extensions.
if [ "$PA_BUILD_EXTENSIONS" = true ]; then
# verbose.
information "running tasks for:" "extensions."
# update apk so main & extra packages are available.
sudo apk update
# loop and build packages.
build_list "${PA_PHP_EXTENSIONS_PREFIXED}";
else
warning "skipping:" "extensions."
fi

# ensure the final destination is the sources path.
# shellcheck disable=SC2164
cd "$PA_SOURCES_PATH"
44 changes: 44 additions & 0 deletions bin/helpers/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# function for building packages.
function build_package()
{
# alias package name from function input.
PACKAGE_NAME=${1}

# enter package source directory.
# shellcheck disable=SC2164
cd "$PA_SOURCES_PATH/$PACKAGE_NAME"

# give a little feedback about the current package being built.
success "building:" "$PACKAGE_NAME"

# build the package from source.
if [ "$PA_BUILD_CHECKSUM" = true ]; then
abuild checksum
fi

# build the package from source.
if [ "$PA_BUILD_BUILD" = true ]; then
abuild -r
fi

# return shell to previous location for safe scripting!
# shellcheck disable=SC2164
cd "${PA_SOURCES_PATH}"
}

# build all packages in a given list.
function build_list()
{
# define build list variable.
BUILD_PACKAGE_LIST=$*

# verbose.
success "building list:" "$BUILD_PACKAGE_LIST"

# loop packages and build each one.
for PACKAGE in $BUILD_PACKAGE_LIST; do
build_package "$PACKAGE"
done
}
82 changes: 82 additions & 0 deletions bin/helpers/colors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

# Source: https://bytefreaks.net/gnulinux/bash/cecho-a-function-to-print-using-different-colors-in-bash

# The following function prints a text using custom color
# -c or --color define the color for the print. See the array colors for the available options.
# -n or --noline directs the system not to print a new line after the content.
# Last argument is the message to be printed.
cecho () {

declare -A colors;
colors=(\
['black']='\E[0;47m'\
['red']='\E[0;31m'\
['green']='\E[0;92m'\
['yellow']='\E[0;33m'\
['blue']='\E[0;34m'\
['magenta']='\E[0;35m'\
['cyan']='\E[0;36m'\
['white']='\E[0;37m'\
);

local defaultMSG="No message passed.";
local defaultColor="black";
local defaultNewLine=true;

while [[ $# -gt 1 ]];
do
key="$1";

case $key in
-c|--color)
color="$2";
shift;
;;
-n|--noline)
newLine=false;
;;
*)
# unknown option
;;
esac
shift;
done

message=${1:-$defaultMSG}; # Defaults to default message.
color=${color:-$defaultColor}; # Defaults to default color, if not specified.
newLine=${newLine:-$defaultNewLine};

echo -en "${colors[$color]}";
echo -en "$message";
if [ "$newLine" = true ] ; then
echo;
fi
tput sgr0; # Reset text attributes to normal without clearing screen.

return;
}

warning () {
cecho -n -c 'yellow' "\n=== ";
cecho -n -c 'white' "$1 ";
cecho -c 'yellow' "$2\n";
}

error () {
cecho -n -c 'red' "\n=== ";
cecho -n -c 'white' "$1 ";
cecho -c 'red' "$2\n";
}

information () {
cecho -n -c 'cyan' "\n=== ";
cecho -n -c 'white' "$1 ";
cecho -c 'cyan' "$2\n";
}

success () {
cecho -n -c 'green' "\n=== ";
cecho -n -c 'white' "$1 ";
cecho -c 'green' "$2\n";
}
54 changes: 54 additions & 0 deletions bin/helpers/flags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

# alias build options.
PA_BUILD_OPTIONS=$*

# flags for package groups to build.
PA_BUILD_EXTRA=false
PA_BUILD_MAIN=false
PA_BUILD_EXTENSIONS=false
# actually build packages.
PA_BUILD_BUILD=false
# run checksum first.
PA_BUILD_CHECKSUM=false

# check for --full flag.
if [[ "$PA_BUILD_OPTIONS" == *"--full"* ]]; then
PA_BUILD_EXTRA=true
PA_BUILD_MAIN=true
PA_BUILD_EXTENSIONS=true
fi

# check for --no-update flag.
if [[ "$PA_BUILD_OPTIONS" == *"--no-update"* ]]; then
# shellcheck disable=SC2034
PA_BUILD_UPDATE=false
fi

# check for --build flag.
if [[ "$PA_BUILD_OPTIONS" == *"--build"* ]]; then
# shellcheck disable=SC2034
PA_BUILD_BUILD=true
fi

# check for --checksum flag.
if [[ "$PA_BUILD_OPTIONS" == *"--checksum"* ]]; then
# shellcheck disable=SC2034
PA_BUILD_CHECKSUM=true
fi

# check for --dep
if [[ "$PA_BUILD_OPTIONS" == *"--extra"* ]]; then
# shellcheck disable=SC2034
PA_BUILD_EXTRA=true
fi
# check for --php flag.
if [[ "$PA_BUILD_OPTIONS" == *"--main"* ]]; then
# shellcheck disable=SC2034
PA_BUILD_MAIN=true
fi
# check for --ext flag.
if [[ "$PA_BUILD_OPTIONS" == *"--extensions"* ]]; then
# shellcheck disable=SC2034
PA_BUILD_EXTENSIONS=true
fi
14 changes: 14 additions & 0 deletions bin/helpers/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# failsafe $PACKAGES and $EXTENSIONS variables.
PA_PHP_EXTRA=${PA_PHP_EXTRA:-""}
PA_PHP_MAIN=${PA_PHP_MAIN:-""}
PA_PHP_EXTENSIONS=${PA_PHP_EXTENSIONS:-""}

# define prefixed version of extensions list, start empty.
PA_PHP_EXTENSIONS_PREFIXED=""

# loop extensions.
for PA_EXT_NAME in $PA_PHP_EXTENSIONS; do
PA_PHP_EXTENSIONS_PREFIXED="$PA_PHP_EXTENSIONS_PREFIXED ${PA_PHP_MAIN}-${PA_EXT_NAME}"
done
2 changes: 2 additions & 0 deletions sandbox/start.sh → sandbox/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

export PATH=/opt/php-alpine/bin:$PATH

# trust the locally mounted public key.
sudo cp /home/sandbox/.abuild/php-alpine.rsa.pub /etc/apk/keys/php-alpine.rsa.pub

Expand Down
60 changes: 0 additions & 60 deletions scripts/v3.10/php-7.3/build.sh

This file was deleted.

27 changes: 27 additions & 0 deletions scripts/v3.10/php-7.3/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# export php package name.
export PA_PHP_MAIN="php7"

# dependencies to build.
export PA_PHP_EXTRA="argon2 secp256k1"

# extensions to build.
export PA_PHP_EXTENSIONS="
amqp
apcu
ast
ds
hashids
imagick
libsodium
memcached
mongodb
msgpack
phalcon
psr
redis
scalar_objects
secp256k1
swoole
timecop
xdebug
"
Loading

0 comments on commit 0eaf6bf

Please sign in to comment.