diff options
author | Erich Eckner <git@eckner.net> | 2017-12-01 12:23:30 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2017-12-01 12:23:30 +0100 |
commit | 6a3fd4ca52b6e799bd2dc250b28d994e1ac8cb65 (patch) | |
tree | c8522a43f909a4781b0ef46062328c74c3458513 /bin | |
parent | ead5de6e01b799ef9b1e39ccbd72fb4bcdbfb524 (diff) | |
download | builder-6a3fd4ca52b6e799bd2dc250b28d994e1ac8cb65.tar.xz |
bin/mysql-functions: a start
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/mysql-functions | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/bin/mysql-functions b/bin/mysql-functions new file mode 100755 index 0000000..33f5d6d --- /dev/null +++ b/bin/mysql-functions @@ -0,0 +1,44 @@ +#!/bin/sh + +# contains functions used to access mysql db + +# shellcheck disable=SC2039 + +mysql_command='mysql buildmaster -e' + +# add_package_source $pkgbase $pkgver $pkgrel $git_revision $mod_git_revision $upstream_package_repository + +# shellcheck disable=SC2016,SC2086 +add_package_source() { + local names='pkgbase pkgver pkgrel git_revision mod_git_revision upstream_package_repository' + local values; + for _ in ${names}; do + values="${values}$( + printf '%s' "$1" | \ + base64 -w0 + ) " + shift + done + values="${values% }" + + ${mysql_command} "$( + printf 'INSERT IGNORE INTO package_sources' + { + printf ' (' + printf '`%s`, ' ${names} + printf ') SELECT' + printf ' from_base64("%s"), ' ${values% *} + printf ' `upstream_repositories`.`id`' + printf ' FROM `upstream_repositories`' + printf ' WHERE `upstream_repositories`.`name` = from_base64("%s");' \ + "${values##* }" + } | \ + sed 's|, )|)|g' + )" + + ${mysql_command} "$( + printf 'SELECT * FROM package_sources' + printf ' LEFT JOIN upstream_repositories' + printf ' ON package_sources.upstream_package_repository = upstream_repositories.id;' + )" +} |