From 7b79c9d152652201b34505761b1dc3dc44c16888 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sat, 22 Aug 2020 17:43:59 +0100
Subject: [PATCH] Add Debian packaging metadata

---
 contrib/start-server.sh      | 19 +++++++++++++++++++
 contrib/update.sh            | 15 +++++++++++++++
 debian/accountserver.service | 11 +++++++++++
 debian/changelog             |  5 +++++
 debian/compat                |  1 +
 debian/control               | 13 +++++++++++++
 debian/gitlab-deps.default   |  9 +++++++++
 debian/gitlab-deps.service   | 21 +++++++++++++++++++++
 debian/postinst              | 20 ++++++++++++++++++++
 debian/rules                 | 14 ++++++++++++++
 10 files changed, 128 insertions(+)
 create mode 100755 contrib/start-server.sh
 create mode 100755 contrib/update.sh
 create mode 100644 debian/accountserver.service
 create mode 100644 debian/changelog
 create mode 100644 debian/compat
 create mode 100644 debian/control
 create mode 100644 debian/gitlab-deps.default
 create mode 100644 debian/gitlab-deps.service
 create mode 100755 debian/postinst
 create mode 100755 debian/rules

diff --git a/contrib/start-server.sh b/contrib/start-server.sh
new file mode 100755
index 0000000..c44ce7e
--- /dev/null
+++ b/contrib/start-server.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+if [ -z "$GITLAB_URL" ]; then
+    echo "Gitlab-deps is not configured (GITLAB_URL empty)" >&2
+    exit 0
+fi
+
+if [ ! -e /var/lib/gitlab-deps/deps.json ]; then
+    echo "No deps.json file, executing update..." >&2
+    /usr/sbin/update-gitlab-deps
+    if [ $? -gt 0 ]; then
+        echo "update-gitlab-deps failed" >&2
+        exit 1
+    fi
+fi
+
+exec /usr/bin/gitlab-deps server \
+     --token-file=$GITLAB_TOKEN_FILE --url=$GITLAB_URL \
+     < /var/lib/gitlab-deps/deps.json
diff --git a/contrib/update.sh b/contrib/update.sh
new file mode 100755
index 0000000..a6abffd
--- /dev/null
+++ b/contrib/update.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+[ -e /etc/default/gitlab-deps ] && . /etc/default/gitlab-deps
+
+if [ -z "$GITLAB_URL" -o -z "$GITLAB_TOKEN_FILE" ]; then
+    echo "Gitlab-deps is not configured" >&2
+    exit 2
+fi
+
+opts="--token-file=$GITLAB_TOKEN_FILE --url=$GITLAB_URL"
+
+gitlab-deps list-projects $opts \
+    | egrep "${PROJECT_REGEXP:-.*}" \
+    | gitlab-deps deps $opts \
+    > $deps_file
diff --git a/debian/accountserver.service b/debian/accountserver.service
new file mode 100644
index 0000000..af68e33
--- /dev/null
+++ b/debian/accountserver.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=A/I account server
+After=slapd.service
+
+[Service]
+EnvironmentFile=-/etc/default/accountserver
+ExecStart=/usr/bin/accountserver $DAEMON_OPTS
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..aca065b
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+gitlab-deps (0.1) unstable; urgency=low
+
+  * First packaged release.
+
+ -- Autistici/Inventati <debian@autistici.org>  Sat, 22 Aug 2020 17:21:02 +0100
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..b1bd38b
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+13
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..1a12076
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,13 @@
+Source: gitlab-deps
+Section: net
+Priority: extra
+Maintainer: Autistici/Inventati <debian@autistici.org>
+Build-Depends: debhelper (>= 11), dh-python, python3,
+Standards-Version: 4.1.3
+
+Package: gitlab-deps
+Architecture: all
+Depends: ${python:Depends}, ${misc:Depends}
+Description: Gitlab dependencies tool
+ Build dependency maps between Gitlab projects and
+ automatically trigger rebuilds on pipeline completion.
diff --git a/debian/gitlab-deps.default b/debian/gitlab-deps.default
new file mode 100644
index 0000000..3b34dd1
--- /dev/null
+++ b/debian/gitlab-deps.default
@@ -0,0 +1,9 @@
+# Set to the public URL of your Gitlab repository.
+GITLAB_URL=
+
+# File with the authorization token.
+GITLAB_TOKEN_FILE=/var/lib/gitlab-deps/auth_token
+
+# Set to a regular expression (extended) if you want to filter the
+# project list.
+#PROJECT_REGEXP=
diff --git a/debian/gitlab-deps.service b/debian/gitlab-deps.service
new file mode 100644
index 0000000..24a97c1
--- /dev/null
+++ b/debian/gitlab-deps.service
@@ -0,0 +1,21 @@
+[Unit]
+Description=gitlab-deps server
+After=network.target
+
+[Service]
+Type=simple
+Restart=on-failure
+EnvironmentFile=/etc/default/gitlab-deps
+ExecStart=/usr/sbin/gitlab-deps-server-wrapper
+User=gitlab-deps
+Group=gitlab-deps
+LimitNOFILE=16384
+NoNewPrivileges=yes
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectHome=yes
+ProtectSystem=full
+ReadOnlyDirectories=/
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/postinst b/debian/postinst
new file mode 100755
index 0000000..8d4e30b
--- /dev/null
+++ b/debian/postinst
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+set -e
+
+case "$1" in
+configure)
+    addgroup --system --quiet gitlab-deps
+    adduser --system --no-create-home --home /var/lib/gitlab-deps \
+      --disabled-password --disabled-login \
+      --quiet --ingroup gitlab-deps gitlab-deps
+
+    mkdir /var/lib/gitlab-deps
+    chown gitlab-deps:gitlab-deps /var/lib/gitlab-deps
+    chmod 0700 /var/lib/gitlab-deps
+    ;;
+esac
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..c3f3b53
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,14 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+
+export PYBUILD_NAME=gitlab-deps
+
+%:
+	dh $@ --with=python3 --buildsystem=pybuild
+
+override_dh_auto_install:
+	dh_auto_install
+	install -o root -g root -m 755 $(CURDIR)/contrib/start-server.sh \
+	  $(CURDIR)/debian/gitlab-deps/usr/sbin/gitlab-deps-server-wrapper
+	install -o root -g root -m 755 $(CURDIR)/contrib/update.sh \
+	  $(CURDIR)/debian/gitlab-deps/usr/sbin/update-gitlab-deps
-- 
GitLab