Skip to content

Commit

Permalink
Rewrite 'packages.bash'
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Dye <mrtops03@gmail.com>
  • Loading branch information
ecdye committed Jun 8, 2020
1 parent cee192d commit 2264391
Show file tree
Hide file tree
Showing 23 changed files with 762 additions and 698 deletions.
34 changes: 17 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ jobs:
arch: arm64
script:
- sed -i 's/^java_opt=.*/java_opt=Zulu8-64/' build-image/openhabian.conf
- docker build -t openhabian/dev-openhabian -f Dockerfile.openhabian-aarch64-native .
- docker build -t openhabian/dev-openhabian -f Dockerfile.openhabian-aarch64-32bit .
- docker run -i openhabian/dev-openhabian bash -c '/usr/local/bin/bats -r -f "dev-." .'
- docker run -i openhabian/dev-openhabian bash -c '/usr/local/bin/bats -r -f "unit-." .'
- stage: BATS and shellcheck tests
env: aarch64
arch: arm64
script:
- docker build -t openhabian/bats-openhabian -f Dockerfile.openhabian-aarch64-native .
- docker build -t openhabian/bats-openhabian -f Dockerfile.openhabian-aarch64-32bit .
- docker run --name "bats-inst-tests" -i openhabian/bats-openhabian bash -c '/usr/local/bin/bats -r -f "installation-." .'
- docker run --name "bats-dest-tests" -i openhabian/bats-openhabian bash -c '/usr/local/bin/bats -r -f "destructive-." .'
- shellcheck -x -s bash openhabian-setup.sh functions/*.bash build-image/*.bash build.bash && echo "shellcheck - OK"
Expand All @@ -62,27 +62,27 @@ jobs:
- export HW=x86
- sed -i 's/^java_opt=.*/java_opt=Zulu8-64/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-x86 .
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Enterprise Java on virtual $HW ...\n"
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Enterprise Java on virtual $HW ...\e[0m\n"
- docker run --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- env: arm32hf
arch: arm64
script:
# 32bit Azul Java on 32bit ARMv6hf (RPi0(W) and RPi1) on 32bit OS on Travis Arm64 HW
- export HW=rpi01
- sed -i 's/^java_opt=.*/java_opt=Zulu8-32/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-ARMv6hf-native .
- echo -e "\n\e[36mopenHABian test installation 32bit Azul Embedded Java on virtual $HW ...\n"
- echo -e "\n\e[36mopenHABian test installation 32bit Azul Embedded Java on virtual $HW ...\e[0m\n"
- docker run --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- env: arm32hf
arch: arm64
script:
# 32bit Azul Java on 32bit ARMv7l (RPi2) on 32bit OS on Travis Arm64 HW
- export HW=rpi2
- sed -i 's/^java_opt=.*/java_opt=Zulu8-32/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-arm32hf-native .
- echo -e "\n\e[36mopenHABian test installation 32bit Azul Embedded Java on virtual $HW ...\n"
- echo -e "\n\e[36mopenHABian test installation 32bit Azul Embedded Java on virtual $HW ...\e[0m\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian
- docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- env: arm32hf
Expand All @@ -92,7 +92,7 @@ jobs:
- export HW=cm3
- sed -i 's/^java_opt=.*/java_opt=Zulu8-32/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-arm32hf-CM3 .
- echo -e "\n\e[36mopenHABian test installation 32bit Azul Embedded Java on virtual $HW ...\n"
- echo -e "\n\e[36mopenHABian test installation 32bit Azul Embedded Java on virtual $HW ...\e[0m\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
- docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- env: arm32hf
Expand All @@ -103,8 +103,8 @@ jobs:
- export HW=rpi3
- sed -i 's/^java_opt=.*/java_opt=Zulu8-64/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-arm32hf-native .
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Embedded Java on virtual $HW ..."
- echo -e "\e[31m ** This is known to not work. openHABian is supposed to force install down to 32bit **\n"
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Embedded Java on virtual $HW ...\e[0m"
- echo -e "\e[31m ** This is known to not work. openHABian is supposed to force install down to 32bit **\e[0m\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
- docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- env: aarch64
Expand All @@ -114,28 +114,28 @@ jobs:
# This is known to not work - openHABian is supposed to downgrade to 32bit on install.
- export HW=rpi3
- sed -i 's/^java_opt=.*/java_opt=Zulu8-64/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-aarch64-native .
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Embedded Java on virtual $HW ..."
- echo -e "\e[31m ** This is known to not work. openHABian is supposed to force install down to 32bit **\n"
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-aarch64-32bit .
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Embedded Java on virtual $HW ...\e[0m"
- echo -e "\e[31m ** This is known to not work. openHABian is supposed to force install down to 32bit **\e[0m\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
- docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- env: aarch64
arch: arm64
script:
# 64bit Azul Java on 64bit ARMv8 (RPi3,4) on 64bit OS on Travis Arm64 HW
- export HW=rpi4
- export HW=rpi3
- sed -i 's/^java_opt=.*/java_opt=Zulu8-64/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-aarch64-64bit .
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Embedded Java \e[31m on 64bit OS\e[36m on virtual $HW ...\n"
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Embedded Java\e[31m on 64bit OS\e[36m on virtual $HW ...\e[0m\n"
- docker run --memory="2G" --memory-reservation="2G" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- env: aarch64
arch: arm64
script:
# AdoptOpenJDK Java on 32bit ARMv7 on 32bit OS on Travis Arm64 HW
- export HW=rpi2
- sed -i 's/^java_opt=.*/java_opt=Adopt11/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-arm32hf-native .
- echo -e "\n\e[36mopenHABian test installation 64bit AdoptOpenJDK 11 Java \e[31m on 32bit OS\e[36m on virtual $HW ...\n"
- echo -e "\n\e[36mopenHABian test installation 64bit AdoptOpenJDK 11 Java\e[31m on 32bit OS\e[36m on virtual $HW ...\e[0m\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
- docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
5 changes: 5 additions & 0 deletions Dockerfile.openhabian-ARMv6hf-emulated
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ ENV container docker
ENV INITSYSTEM on
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# bats tests on a minimal install will require additional packages to run properly:
# - lsb-release (influx, homegear)
# - apt-transport-https (homegear)
# - unzip (java)
# those packages would normally be included in our standard install
RUN apt-get update -qq \
&& apt-get install --yes -qq --no-install-recommends systemd systemd-sysv git wget python3 python3-pip apt-utils jq virt-what \
lsb-release unzip apt-transport-https \
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile.openhabian-ARMv6hf-native
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ ENV container docker
ENV INITSYSTEM on
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# bats tests on a minimal install will require additional packages to run properly:
# - lsb-release (influx, homegear)
# - apt-transport-https (homegear)
# - unzip (java)
# those packages would normally be included in our standard install
RUN apt-get update -qq \
&& apt-get install --yes -qq --no-install-recommends systemd systemd-sysv git wget python3 python3-pip apt-utils jq virt-what \
lsb-release unzip apt-transport-https \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Note RPi3 base (first RPi to have aarch64 available)
# ATTENTION: Zulu Java on raspberrypi3 images fails to run
# Note RPi3 base (first RPi to have aarch64 available) WITH 32bit OS
FROM balenalib/raspberrypi3-debian-node:latest-buster-build


ENV container docker
ENV INITSYSTEM on
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# Currently this config is used for BATS tests.
# bats tests on a minimal install will require additional packages to run properly:
# - lsb-release (influx, homegear)
# - psmisc, i.e. killall (homegear)
# - apt-transport-https (homegear)
# - unzip (java)
# those packages would normally be included in our standard install
RUN apt-get update -qq \
Expand Down
9 changes: 6 additions & 3 deletions Dockerfile.openhabian-aarch64-64bit
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Note RPi3 base (first RPi to have aarch64 available) WITH 64bit OS
#FROM balenalib/raspberrypi3-debian-node:latest-buster
#FROM balenalib/generic-aarch64-debian-node
FROM balenalib/raspberrypi4-64-debian-node-build
FROM balenalib/raspberrypi3-64-debian-node:latest-buster-build


ENV container docker
ENV INITSYSTEM on
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# bats tests on a minimal install will require additional packages to run properly:
# - lsb-release (influx, homegear)
# - apt-transport-https (homegear)
# - unzip (java)
# those packages would normally be included in our standard install
RUN apt-get update -qq \
&& apt-get install --yes -qq --no-install-recommends systemd systemd-sysv git wget python3 python3-pip apt-utils jq virt-what \
lsb-release unzip apt-transport-https \
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile.openhabian-arm32hf-CM3
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# CM3 is like RPi3 but without BT,WiFi,Ethernet
# ATTENTION: Zulu Java on raspberrypi3 images fails to run
FROM balenalib/fincm3-debian-node:latest-buster-build


ENV container docker
ENV INITSYSTEM on
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# bats tests on a minimal install will require additional packages to run properly:
# - lsb-release (influx, homegear)
# - apt-transport-https (homegear)
# - unzip (java)
# those packages would normally be included in our standard install
RUN apt-get update -qq \
&& apt-get install --yes -qq --no-install-recommends systemd systemd-sysv git wget python3 python3-pip apt-utils jq virt-what \
lsb-release unzip apt-transport-https \
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile.openhabian-arm32hf-emulated
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ ENV container docker
ENV INITSYSTEM on
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# bats tests on a minimal install will require additional packages to run properly:
# - lsb-release (influx, homegear)
# - apt-transport-https (homegear)
# - unzip (java)
# those packages would normally be included in our standard install
RUN apt-get update -qq \
&& apt-get install --yes -qq --no-install-recommends systemd systemd-sysv git wget python3 python3-pip apt-utils jq virt-what \
lsb-release unzip apt-transport-https \
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile.openhabian-arm32hf-native
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ ENV container docker
ENV INITSYSTEM on
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# bats tests on a minimal install will require additional packages to run properly:
# - lsb-release (influx, homegear)
# - apt-transport-https (homegear)
# - unzip (java)
# those packages would normally be included in our standard install
RUN apt-get update -qq \
&& apt-get install --yes -qq --no-install-recommends systemd systemd-sysv git wget python3 python3-pip apt-utils jq virt-what \
lsb-release unzip apt-transport-https \
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile.openhabian-x86
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ ENV container docker
ENV INITSYSTEM on
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# bats tests on a minimal install will require additional packages to run properly:
# - lsb-release (influx, homegear)
# - apt-transport-https (homegear)
# - unzip (java)
# those packages would normally be included in our standard install
RUN apt-get update -qq \
&& apt-get install --yes -qq --no-install-recommends systemd systemd-sysv git wget python3 python3-pip apt-utils jq virt-what \
lsb-release unzip apt-transport-https \
Expand Down
5 changes: 3 additions & 2 deletions build-image/first-boot.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export DEBIAN_FRONTEND=noninteractive
# Log everything to file
exec &> >(tee -a "/boot/first-boot.log")

# Log with timestamp
timestamp() { date +"%F_%T_%Z"; }

fail_inprogress() {
Expand Down Expand Up @@ -191,8 +192,8 @@ if hash python3 2>/dev/null; then bash /boot/webif.bash cleanup; fi

if [ -z "$SILENT" ]; then
echo -e "\\n${COL_CYAN}Memory usage:"
free -m && ps -auxq "$(cat /var/lib/openhab2/tmp/karaf.pid)" |awk '/openhab/ {print "size/res="$5"/"$6" KB"}'
echo "${COL_DEF}"
free -m && ps -auxq "$(cat /var/lib/openhab2/tmp/karaf.pid)" | awk '/openhab/ {print "size/res="$5"/"$6" KB"}'
echo -e "$COL_DEF"
fi

# vim: filetype=sh
6 changes: 3 additions & 3 deletions build-image/openhabian.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ wifi_country=""
ipv6=enable

# repo and branch to clone from
repositoryurl=https://github.com/openhab/openhabian.git
clonebranch=stable
repositoryurl=https://github.com/ecdye/openhabian.git
clonebranch=fixes-2

# debug verbosity mode
# off, on (verbose output in log) or maximum (show every command)
Expand All @@ -53,6 +53,6 @@ debugmode=on

# Java architecture mode
# Valid arguments: "Adopt11", "Zulu8-32", "Zulu8-64", "Zulu11-32", or "Zulu11-64"
java_opt=Zulu8-32
java_opt=Zulu8-64

# vim: filetype=sh
2 changes: 1 addition & 1 deletion build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ usage() {
# shellcheck disable=SC1090
source "$(dirname "$0")"/functions/helpers.bash

## This format timestamp
# Log with timestamp
timestamp() { date +"%F_%T_%Z"; }

## This function format log messages
Expand Down
9 changes: 4 additions & 5 deletions functions/dev.bats
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/usr/bin/env bats
#!/usr/bin/env bats

load helpers

@test "dev-query-arch" {
if is_arm; then
echo -e "# \e[32mRunning on ARM." >&3
echo -e "# ${COL_GREEN}Running on ARM.${COL_DEF}" >&3
else
echo -ne "# \e[32mRunning on " >&3
/usr/bin/arch >&3
echo -e "# ${COL_GREEN}Running on $(/usr/bin/arch).${COL_DEF}" >&3
fi
}

@test "dev-query-virt" {
VIRT=$(virt-what)
echo -e "# \e[32mRunning on ${VIRT:-native HW}." >&3
echo -e "# ${COL_GREEN}Running on ${VIRT:-native HW}.${COL_DEF}" >&3
}
57 changes: 40 additions & 17 deletions functions/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ COL_LGRAY=$ESC"37;01m"
COL_DGRAY=$ESC"90;01m"
export COL_DEF COL_RED COL_GREEN COL_YELLOW COL_BLUE COL_MAGENTA COL_CYAN COL_LGRAY COL_DGRAY

# Log with timestamp
timestamp() { date +"%F_%T_%Z"; }

cond_redirect() {
if [ -n "$SILENT" ]; then
"$@" &>/dev/null
Expand All @@ -38,10 +41,10 @@ cond_echo() {
## add_keys(String url)
##
add_keys() {
local repoKey
repoKey="$(mktemp /tmp/openhabian.XXXXX)"
local repoKey

repoKey="$(mktemp "${TEMP:-/tmp}"/openhabian.XXXXX)"

echo -n "$(timestamp) [openHABian] Adding required keys to apt... "
cond_redirect wget -qO "$repoKey" "$1"
if cond_redirect apt-key add "$repoKey"; then
Expand Down Expand Up @@ -238,26 +241,46 @@ running_on_github() {
[[ -n "$GITHUB_RUN_ID" ]]
return $?
}

## Attempt a command "$1" for either a default of 10 times or
## for "$2" times unless "$1" evaulates to 0.
## Sleeps for 1 second or for "$3" seconds between each attempt.
## Returns number of command attemps remaining.
##
## tryUntil(String cmd, int attempts, int interval)
##
tryUntil() {
# tryUntil() executes $1 as command
# either $2 times or until cmd evaluates to 0, sleeps $3 seconds inbetween
# returns the number of cmd runs that would have been left
local cmd
local attempts
local interval
local ret

cmd="$1"
count=${2:-10}
local i=$count
attempts=${2:-10}
interval=${3:-1}
until [ "$i" -le 0 ]; do
cond_echo "(executing ${cmd}) ${COL_DEF}\c"

until [ "$attempts" -le 0 ]; do
cond_echo "executing $cmd \c"
eval "${cmd}"
ret=$?
if [ $ret -eq 0 ]; then break; fi
sleep "${interval}"
echo -n ".${i}."
((i-=1))
sleep "$interval"
echo "#${attempts}."
((attempts-=1))
done
return "$i"

return "$attempts"
}


## Returns 0 / true if device has less than 900MB of total memory
## Returns 1 / false if device has more than 900MB of total memory
##
has_lowmem() {
totalmemory=$(grep MemTotal /proc/meminfo |awk '{print $2}')
if [ "${totalmemory:-1000000}" -lt 900000 ]; then return 0; else return 1; fi
local totalMemory

totalMemory="$(grep MemTotal /proc/meminfo | awk '{print $2}')"

if [ -z "$totalMemory" ]; then return 1; fi # assume that device does not have low memory
if [ "$totalMemory" -lt 900000 ]; then return 0; else return 1; fi
}
4 changes: 2 additions & 2 deletions functions/helpers.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ testAppearingHost() {
run testAppearingHost thiswillappear
[ "$status" -eq 7 ]

echo -e "# \n\e[32mPing to host appearing after 3 seconds succeeded." >&3
echo -e "# \n${COL_GREEN}Ping to host appearing after 3 seconds succeeded.${COL_DEF}" >&3
}

@test "unit-tryNonExistingSite" {
run testNonExistingHost nothisdoesnotexit
[ "$status" -eq 0 ]

echo -e "# \n\e[32mPinging to nonexistingsite failed (correctly so)." >&3
echo -e "# \n${COL_GREEN}Pinging to nonexistingsite failed (correctly so).${COL_DEF}" >&3
}

@test "unit-cond_echo" {
Expand Down

0 comments on commit 2264391

Please sign in to comment.