Skip to content

Commit

Permalink
Add mariadb tar environ
Browse files Browse the repository at this point in the history
Also some rework on defaults
  • Loading branch information
andrii-suse committed Jan 30, 2023
1 parent 40dc470 commit 281a68e
Show file tree
Hide file tree
Showing 85 changed files with 156 additions and 36 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
strategy:
matrix:
product:
- product/ap
- product/fk
- product/ma
- product/md
- product/ng
- product/pg
- product/rs
- environ.d/ap
- environ.d/fk
- environ.d/ma
- environ.d/md
- environ.d/ng
- environ.d/pg
- envrion.d/rs
- '.'
steps:
- uses: actions/checkout@v2
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

install:
mkdir -p "${DESTDIR}"/usr/bin/
mkdir -p "${DESTDIR}"/var/opt/environ
chmod 777 "${DESTDIR}"/var/opt/environ
install bin/environ "${DESTDIR}"/usr/bin/
install -d -m 0755 "${DESTDIR}"/etc/environ.d/
cd product && for d in * ; do \
cd environ.d && for d in * ; do \
mkdir -p "${DESTDIR}"/etc/environ.d/$$d ;\
for f in $$d/*.{m4,cnf} ; do \
test -f $$f && install -m 0644 $$f "${DESTDIR}"/etc/environ.d/$$f ;\
Expand All @@ -19,10 +21,10 @@ install:
done

test:
for f in product/*/t/*.sh ; do bash -x $f && continue; echo FAIL: $f; break; done
for f in environ.d/*/t/*.sh ; do bash -x $f && continue; echo FAIL: $f; break; done

test_leap:
for f in product/ap/*/*.sh; do echo starting $f; ENVIRON_TEST_IMAGE=registry.opensuse.org/opensuse/leap $f && continue; echo FAIL $f; break; done
for f in environ.d/ap/*/*.sh; do echo starting $f; ENVIRON_TEST_IMAGE=registry.opensuse.org/opensuse/leap $f && continue; echo FAIL $f; break; done

test_tw:
for f in product/ap/*/*.sh; do echo starting $f; ENVIRON_TEST_IMAGE=registry.opensuse.org/opensuse/tumbleweed $f && continue; echo FAIL $f; break; done
for f in environ.d/ap/*/*.sh; do echo starting $f; ENVIRON_TEST_IMAGE=registry.opensuse.org/opensuse/tumbleweed $f && continue; echo FAIL $f; break; done
12 changes: 4 additions & 8 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#!/bin/bash
[ ! -e environ_env ] || source environ_env

usage () {
cat <<'HELP_USAGE'
Usage: environ [--rebuild 0] [--build 0] [--local 0] [--cachedir <0|path>] \
[--dir <path>] [-l|--localdir <path>] <product> [<path>]

Expand All @@ -24,11 +19,12 @@ environ - generate a folder with helper scripts to manage and automate services
--cachedir <path> - use <path> for cache directory location (default is
/temp/environ/)
--dir <path> - path to templates (default /etc/environ.d/).
-l <path>,
--localdir <path> - additional path to templates (default t/lib/environ/).
<product> - a service for which scripts will be generated. Currently
supported values are names of folders in --tempatedir parameter (default
/etc/environ/product). <product> may be also followed by a digit if more
than one service is needed.
supported values are names of folders in --tempatedir parameter (default
/etc/environ.d/product). <product> may be also followed by a digit if more
than one service is needed.
<path> - if specified, must point to a folder with source codes of the
desired product. In this case templates (when available) will actually
build the product from source, (unless --build option is set to 0).
Expand Down
31 changes: 23 additions & 8 deletions bin/environ
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ environ - generate a folder with helper scripts to manage and automate services
--localdir <path> - additional path to templates (default t/lib/environ/).
<product> - a service for which scripts will be generated. Currently
supported values are names of folders in --tempatedir parameter (default
/etc/environ/product). <product> may be also followed by a digit if more
/etc/environ.d/product). <product> may be also followed by a digit if more
than one service is needed.
<path> - if specified, must point to a folder with source codes of the
desired product. In this case templates (when available) will actually
Expand Down Expand Up @@ -112,8 +112,8 @@ HELP_USAGE

set -euo pipefail
: "${ENVIRON_DIR:=/etc/environ.d}"
: "${ENVIRON_LOCAL_DIR:=t/lib/environ}"
: "${ENVIRON_CACHE:=/tmp/environ}"
: "${ENVIRON_LOCAL_DIR:=./environ.d}"
: "${ENVIRON_CACHE:=/var/opt/environ}"
: "${ENVIRON_REBUILD:=1}"
: "${ENVIRON_BUILD:=1}"
: "${ENVIRON_LOCAL:=1}"
Expand Down Expand Up @@ -212,7 +212,8 @@ rebuild=${ENVIRON_REBUILD}
local=${ENVIRON_LOCAL}
template=${ENVIRON_DIR}
template_local=${ENVIRON_LOCAL_DIR}
type=local
type=''

[ $# -le 1 ] || {
type=source
srcdir=$2
Expand All @@ -221,6 +222,17 @@ type=local
[ ! -d "$srcdir"/t/lib/environ ] || [ -d t/lib/environ ] || template_local="$srcdir"/t/lib/environ
}

[ -z ${env:4} ] || {
[ ! -e $template_local/$product/detect_type.sh ] || \
type=$($template_local/$product/detect_type.sh ${1})

[ ! -z "$type" ] || [ ! -e $template/$product/detect_type.sh ] || \
type=$($template/$product/detect_type.sh ${1})
}

[ -n "$type" ] || \
type=local

cleanup_message=0
# try to stop existing environ, if possible
if [ -x "$cache/$env/stop" ]; then
Expand Down Expand Up @@ -294,7 +306,7 @@ else
[ ! -f $filename ] || _exec_present=1
done

for filename in {$template,$template_local}/{common,$product/$type}/* ; do
for filename in {$template,$template_local}/{common,$product/common,$product/$type}/* ; do
if [ -d $filename ] ; then
folder=$filename
mkdir -p $workdir/$(basename $folder)
Expand All @@ -303,21 +315,23 @@ else
dst=$workdir/$(basename $folder)/$(basename $src)
dst=${dst%.m4}
dst=${dst%.sh}
opts="-D__wid=$wid -D__workdir=$workdir/$(basename $folder) -D__datadir=$workdir/$(basename $folder)/dt -D__port=$port -D__user=$USER -D__lockdir=$cache -D__environ=$env -D__libdir=$folder"
opts="-D__wid=$wid -D__workdir=$workdir/$(basename $folder) -D__datadir=$workdir/$(basename $folder)/dt -D__port=$port -D__user=$USER -D__lockdir=$cache -D__cachedir=$cache -D__environ=$env -D__libdir=$folder"
if [ $type == source ]; then
opts="$opts -D__srcdir=$workdir/src -D__blddir=$workdir/bld -D__installdir=$workdir/install"
fi
[ $type != version ] || opts="$opts -D__version=${1:4} -D__bindir=$cache/$product-version/${1:4}/bin"
m4 $opts $src > $dst
[[ $src != *.sh.m4 ]] || chmod +x "$dst"
done
else
# we skip generating start/stop/status/_lock from common, unless _exec preset
[[ ! $filename =~ .*/common/(((start|stop|status).sh)|_lock).m4 ]] || [ "${_exec_present}" == 1 ] || continue
opts="-D__wid=$wid -D__workdir=$workdir -D__datadir=$workdir/dt -D__port=$port -D__user=$USER -D__lockdir=$cache -D__environ=$env -D__libdir=$(dirname $filename)"
opts="-D__wid=$wid -D__workdir=$workdir -D__datadir=$workdir/dt -D__port=$port -D__user=$USER -D__lockdir=$cache -D__cachedir=$cache -D__environ=$env -D__libdir=$(dirname $filename)"
if [ $type == source ]; then
ln -sfn $srcdir $workdir/src
opts="$opts -D__srcdir=$workdir/src -D__blddir=$workdir/bld -D__installdir=$workdir/install"
fi
[ $type != version ] || opts="$opts -D__version=${1:4} -D__bindir=$cache/$product-version/${1:4}/bin"
[ -f "$filename" ] || continue
[ m4 == ${filename//*.} ] || [ "$filename" == .service.lst ] || continue
dest=$workdir/$(basename $filename)
Expand Down Expand Up @@ -345,10 +359,11 @@ else
dst=$workdir/${service}/$(basename $src)
dst=${dst%.m4}
dst=${dst%.sh}
opts="-D__wid=$wid -D__workdir=$workdir -D__datadir=$workdir/dt -D__port=$port -D__user=$USER -D__lockdir=$cache -D__environ=$env"
opts="-D__wid=$wid -D__workdir=$workdir -D__datadir=$workdir/dt -D__port=$port -D__user=$USER -D__lockdir=$cache -D__cachedir=$cache -D__environ=$env"
if [ $type == source ]; then
opts="$opts -D__srcdir=$workdir/src -D__blddir=$workdir/bld -D__installdir=$workdir/install"
fi
[ $type != version ] || opts="$opts -D__version=${1:4} -D__bindir=$cache/$product-version/${1:4}/bin"
m4 $opts -D__service=$service $src > $dst
[[ $src != *.sh.m4 ]] || chmod +x "$dst"
done
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions environ.d/ma/common/build.sh.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ -d __datadir ] || mkdir __datadir
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions environ.d/ma/detect_type.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo version
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions environ.d/ma/t/01-smoke-00-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!t/lib/test-in-image.sh mariadb-server
set -euo pipefail
ma=$(environ ma9-10.10.2)

$ma/download

$ma/start
$ma/status

$ma/create_db tst
$ma/sql_tst "create table t1 as select 'x1'"

test x1 == $($ma/sql --batch -Ne "select * from t1" tst)
test x1 == $($ma/sql_tst "select * from t1")

$ma/sql_test x1 == "select * from t1"
$ma/sql_test x2 != "select * from t1"

rc=0
$ma/sql_test x2 == "select * from t1" || rc=$?
test $rc -gt 0

$ma/stop

rc=0
$ma/status || rc=$?

test $rc -gt 0
echo PASS $0
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 46 additions & 0 deletions environ.d/ma/version/download.sh.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
set -e

# $eatmydata mysql_install_db --no-defaults --data=__datadir --log-error=__workdir/.install | head -n 3

# example url ftp://ftp.hosteurope.de/mirror/archive.mariadb.org/mariadb-__version/bintar-linux-x86_64/mariadb-__version-linux-x86_64.tar.gz
#

file=ftp://ftp.hosteurope.de/mirror/archive.mariadb.org/mariadb-__version/bintar-linux-systemd-x86_64/mariadb-__version-linux-systemd-x86_64.tar.gz

file1=http://mirrors.dotsrc.org/mariadb/mariadb-__version/bintar-linux-systemd-x86_64/mariadb-__version-linux-systemd-x86_64.tar.gz

mkdir -p __cachedir/ma-version/__version

(
cd __cachedir/ma-version/__version

function cleanup {
[ -z "$wgetpid" ] || kill "$wgetpid" 2>/dev/null
}

trap cleanup INT TERM

if [ ! -f "$(basename $file)" ] ; then
echo downloading "$file"
( wget -q -np -nc "$file" || wget -q -np -nc "$file1" )&
wgetpid=$!
while kill -0 $wgetpid 2>/dev/null ; do
sleep 10
echo -n .
done
res=0
wait $wgetpid || res=$?
wgetpid=""
if [ "$res" -ne 0 ] ; then
>&2 echo "failed to download '$file1' ($res)"
exit $res
fi
fi

if [ -f "$(basename $file)" ] ; then
if [ ! -x bin/mysqld ] ; then
tar -zxf "$(basename $file)" ${ERN_M_TAR_EXTRA_FLAGS} --strip 1
fi
fi
)
:
6 changes: 6 additions & 0 deletions environ.d/ma/version/init_datadir.sh.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set -e
[ -d __datadir ] || mkdir __datadir

eatmydata=$(which eatmydata 2>/dev/null) || :

$eatmydata __bindir/../scripts/mysql_install_db --no-defaults --data=__datadir --log-error=__workdir/.install | head -n 3
22 changes: 22 additions & 0 deletions environ.d/ma/version/sql.sh.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if [[ $1 == -* ]] ; then
__bindir/mysql --batch --socket=__workdir/.sock "$@"
elif [ -z "$2" ]; then
if [ "$(basename $0)" == sql ]; then
if [ -f __workdir/default_db.cnf ] && [ "$#" == 1 ]; then
__bindir/mysql "$(cat __workdir/default_db.cnf)" --batch --socket=__workdir/.sock -Ne "$*"
else
__bindir/mysql --batch --socket=__workdir/.sock -Ne "$*"
fi
else
db=${0#*_}
if [ "$#" == 0 ]; then
__bindir/mysql "$db" --socket=__workdir/.sock
else
__bindir/mysql $db --socket=__workdir/.sock --batch -Ne "$@"
fi
fi
else
db=$1
shift
__bindir/mysql "$db" --batch --socket=__workdir/.sock -Ne "$@"
fi
9 changes: 9 additions & 0 deletions environ.d/ma/version/start.sh.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -e
[ -d __workdir/dt ] || mkdir __workdir/dt
[ -f __datadir/ibdata1 ] || __workdir/init_datadir

__bindir/mariadbd --datadir=__datadir --user=$USER --socket=__workdir/.sock --skip-networking --log-error=__workdir/.cerr --pid-file=__workdir/.pid "$@" &

sleep 1
__workdir/status >& /dev/null || sleep 1
__workdir/status >& /dev/null || sleep 1
1 change: 1 addition & 0 deletions environ.d/ma/version/status.sh.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__bindir/mysqladmin --socket=__workdir/.sock status
1 change: 1 addition & 0 deletions environ.d/ma/version/stop.sh.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__bindir/mysqladmin --socket=__workdir/.sock shutdown
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions product/ma/local/build.sh.m4

This file was deleted.

0 comments on commit 281a68e

Please sign in to comment.