1#!/bin/bash
2# Utility to regenerate and resign repository
3# (haikuporter generally does this, however this tool simplifies doing it manually)
4
5BASE_DIR=/var/packages
6REPO_SIGNING_SECRETS="/run/secrets/repo_signing"
7
8if [ $# -ne 2 ]; then
9	echo ""
10	echo "usage: $0 [branch] [architecture]"
11	exit 1;
12fi
13
14if [[ ! -d $BASE_DIR/repository/$1 ]]; then
15	echo "Invalid branch!"
16	exit 1
17fi
18
19if [[ ! -d $BASE_DIR/repository/$1/$2 ]]; then
20	echo "Invalid architecture!"
21	exit 1
22fi
23
24cd $BASE_DIR/repository/$1/$2/current/
25package_repo create repo.info packages/*
26sha256sum repo | awk '{ print $1 }' > repo.sha256
27
28if [ -f $REPO_SIGNING_SECRETS/privatekey ] && [ -f $REPO_SIGNING_SECRETS/privatekeypass ]
29then
30	touch /tmp/haiku-secret.key && chmod 600 /tmp/haiku-secret.key
31	echo "untrusted comment: minisign encrypted secret key" > /tmp/haiku-secret.key
32	cat $REPO_SIGNING_SECRETS/privatekey >> /tmp/haiku-secret.key
33	SIGFLAGS="$SIGFLAGS $(cat $REPO_SIGNING_SECRETS/privatekeypass)"
34	cat $REPO_SIGNING_SECRETS/privatekeypass | minisign -s /tmp/haiku-secret.key -Sm repo
35	rm /tmp/haiku-secret.key
36fi
37
38echo "$BASE_DIR/repository/$1/$2/current repository regenerated!"
39