asu: add attended sysupgrade server package
authorDaniel Golle <daniel@makrotopia.org>
Thu, 7 Mar 2019 19:40:45 +0000 (20:40 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Fri, 8 Mar 2019 02:36:25 +0000 (03:36 +0100)
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
devel/asu/Makefile [new file with mode: 0644]
devel/asu/files/asu.defaults [new file with mode: 0644]
devel/asu/files/asu.init [new file with mode: 0644]

diff --git a/devel/asu/Makefile b/devel/asu/Makefile
new file mode 100644 (file)
index 0000000..b7da2dc
--- /dev/null
@@ -0,0 +1,60 @@
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=asu
+PKG_VERSION:=0.2.3
+PKG_RELEASE=1
+
+PKG_LICENSE:=GPL-3.0
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://files.pythonhosted.org/packages/source/a/asu/
+PKG_HASH:=e60027cd531cc5b9b20d3321acc06fdf0cdd894004919800575b8235343ba8ef
+
+PKG_BUILD_DEPENDS:=python3
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
+PKG_UNPACK=$(HOST_TAR) -C $(PKG_BUILD_DIR) --strip-components=1 -xzf $(DL_DIR)/$(PKG_SOURCE)
+
+include $(INCLUDE_DIR)/package.mk
+include ../../lang/python/python3-package.mk
+
+IMAGEBUILDER_DEPENDS:= \
+    @x86_64 +bash +bzip2 +coreutils +coreutils-stat +diffutils +file \
+    +gawk +gcc +getopt +git +git-http +libncurses +make +patch +perl \
+    +perlbase-attributes +perlbase-findbin +perlbase-getopt \
+    +perlbase-thread +python-light +tar +unzip +wget +xz +xzdiff \
+    +xzgrep +xzless +xz-utils +zlib-dev
+
+define Package/asu
+    SECTION:=devel
+    CATEGORY:=Development
+    TITLE:=attended sysupgrade image server
+    MAINTAINER:=Paul Spooren <paul@spooren.de>
+    URL:=http://github.com/aparcar/gsoc17-attended-sysupgrade/
+    DEPENDS:=$(IMAGEBUILDER_DEPENDS) +pgsql-server +psqlodbcw \
+             +python3-ctypes +python3-distutils +python3-flask \
+             +python3-openssl +python3-pyodbc +python3-yaml \
+             +libustream-mbedtls +ca-certificates +gnupg
+    USERID:=asu:asu
+    VARIANT:=python3
+endef
+
+define Package/asu/description
+   Build server to deliver OpenWrt/LEDE sysupgrade images
+endef
+
+define Py3Package/asu/install
+       $(INSTALL_DIR) $(1)/etc/uci-defaults
+       $(INSTALL_BIN) ./files/asu.defaults $(1)/etc/uci-defaults/99-asu
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/asu.init $(1)/etc/init.d/asu
+       $(INSTALL_DIR) $(1)/etc/asu
+       $(INSTALL_CONF) $(PKG_BUILD_DIR)/asu/utils/config.yml.default $(1)/etc/asu/config.yml
+endef
+
+$(eval $(call Py3Package,asu))
+$(eval $(call BuildPackage,asu))
diff --git a/devel/asu/files/asu.defaults b/devel/asu/files/asu.defaults
new file mode 100644 (file)
index 0000000..8fb2d7e
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+asu_tables="$(ls -1 /usr/lib/*/site-packages/asu/utils/tables.sql | head -n 1)"
+uci -q batch <<EOF
+       del postgresql.asu
+       set postgresql.asu=postgres-db
+       set postgresql.asu.name=asu
+       set postgresql.asu.user=asu
+       set postgresql.asu.pass=password
+       set postgresql.asu.script='$asu_tables'
+       commit postgresql
+EOF
+
+sed -i 's/database_user:.*/database_user: asu/' /etc/asu/config.yml
+sed -i 's/database_pass:.*/database_pass: asu/' /etc/asu/config.yml
diff --git a/devel/asu/files/asu.init b/devel/asu/files/asu.init
new file mode 100644 (file)
index 0000000..f022e7f
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh /etc/rc.common
+
+START=99
+STOP=01
+
+USE_PROCD=1
+PROG=/usr/bin/flask
+
+start_service() {
+    . /lib/functions/postgresql.sh
+
+    local pgdata=$(uci get postgresql.config.PGDATA)
+    local i=0
+
+    while ! pg_server_ready "$pgdata"; do
+      sleep 1
+      [ $((i++)) -gt 30 ] && return 1
+    done
+
+    i=0
+    while ! pg_test_db asu asu; do
+      sleep 1
+      [ $((i++)) -gt 30 ] && return 1
+    done
+
+    FLASK_APP=asu $PROG loaddb
+
+    procd_open_instance asu_main
+#    procd_set_param user asu
+#    procd_set_param group asu
+    procd_set_param env FLASK_APP=asu
+    procd_set_param command $PROG run
+    procd_close_instance
+
+    procd_open_instance main_worker
+#    procd_set_param user asu
+#    procd_set_param group asu
+    procd_set_param env FLASK_APP=asu
+    procd_set_param command $PROG run_worker
+    procd_close_instance
+}