From b024d9bf69acf38fe0f04f11eebf158940bc38c6 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Tue, 10 Mar 2020 21:27:59 -0600
Subject: [PATCH] WIP: add pkgar support

---
 .gitmodules |  4 ++++
 cook.sh     | 37 +++++++++++++++++++++++++++++++++----
 pkgar       |  1 +
 3 files changed, 38 insertions(+), 4 deletions(-)
 create mode 160000 pkgar

diff --git a/.gitmodules b/.gitmodules
index 868d33227..cc1ec1f57 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -60,3 +60,7 @@
 	path = patches/jobserver-rs
 	url = https://gitlab.redox-os.org/redox-os/jobserver-rs.git
 	branch = redox
+[submodule "pkgar"]
+	path = pkgar
+	url = https://gitlab.redox-os.org/redox-os/pkgar.git
+	branch = master
diff --git a/cook.sh b/cook.sh
index 9ce54ae41..aa19f96d7 100755
--- a/cook.sh
+++ b/cook.sh
@@ -15,15 +15,17 @@ export PREPARE_COPY=1
 
 if [ ! "$(uname -s)" = "Redox" ]
 then
+function docgen {
+    CC=cc cargo run --release --manifest-path "$ROOT/docgen/Cargo.toml" --bin docgen -- "$@"
+}
 
 function pkg {
-    CC=cc cargo run --release --manifest-path "$ROOT/pkgutils/Cargo.toml" --bin pkg -- $@
+    CC=cc cargo run --release --manifest-path "$ROOT/pkgutils/Cargo.toml" --bin pkg -- "$@"
 }
 
-function docgen {
-    CC=cc cargo run --release --manifest-path "$ROOT/docgen/Cargo.toml" --bin docgen -- $@
+function pkgar {
+    CC=cc cargo run --release --manifest-path "$ROOT/pkgar/Cargo.toml" --bin pkgar -- "$@"
 }
-
 fi
 
 function usage {
@@ -423,6 +425,33 @@ function op {
         unstage)
             rm -rfv stage
             ;;
+        pkg)
+            if [ ! -e "${ROOT}/build/secret.key" ]
+            then
+                mkdir -p "${ROOT}/build"
+                pkgar \
+                    keygen \
+                    --secret "${ROOT}/build/secret.key" \
+                    --public "${ROOT}/build/public.key"
+            fi
+
+            pkgar \
+                create \
+                --secret "${ROOT}/build/secret.key" \
+                --file stage.pkg \
+                stage
+
+            if command -v pigz > /dev/null
+            then
+                pigz --force stage.pkg
+            else
+                echo "Install pigz for increased performance"
+                gzip --force recipes/jeremy/stage.pkg
+            fi
+            ;;
+        unpkg)
+            rm -fv stage.pkg stage.pkg.gz
+            ;;
         tar)
             echo "name = \"$1\"" > "stage.toml"
             echo "version = \"$(op $1 version)\"" >> "stage.toml"
diff --git a/pkgar b/pkgar
new file mode 160000
index 000000000..6855ee50a
--- /dev/null
+++ b/pkgar
@@ -0,0 +1 @@
+Subproject commit 6855ee50a3beda271975aebce50196ebdb75d442
-- 
GitLab