[gnome-build-meta/valentindavid/gnome-os-ostree: 15/17] Add development scripts



commit a0284b06046ab81127a24ec58fc48b9c746ac537
Author: Valentin David <valentin david codethink co uk>
Date:   Mon Jan 13 10:29:14 2020 +0100

    Add development scripts
    
    On host side to update local repository:
    
    ```
    ./utils/update-local-repo.sh
    ```
    
    To run the local repository:
    
    ```
    ./utils/update-local-repo.sh
    ```
    
    On the GNOME OS side, to switch and upgrade to the local development
    repository:
    
    ```
    sudo enable-developer-repository
    ```

 elements/vm/deps.bst                 |   1 +
 elements/vm/dev-repo-script.bst      |  19 ++++++
 files/vm/enable-developer-repository |  70 +++++++++++++++++++++
 utils/run-local-repo.sh              |   3 +
 utils/update-local-repo.sh           |  38 ++++++++++++
 utils/update-repo.sh                 | 116 +++++++++++++++++++++++++++++++++++
 6 files changed, 247 insertions(+)
---
diff --git a/elements/vm/deps.bst b/elements/vm/deps.bst
index 3b722c5b..375bb4a0 100644
--- a/elements/vm/deps.bst
+++ b/elements/vm/deps.bst
@@ -16,6 +16,7 @@ runtime-depends:
 
 - vm/plymouth-gnome-theme.bst
 - vm/kbd.bst
+- vm/dev-repo-script.bst
 
 - freedesktop-sdk.bst:vm/config/pulseaudio.bst
 - freedesktop-sdk.bst:vm/config/sudo.bst
diff --git a/elements/vm/dev-repo-script.bst b/elements/vm/dev-repo-script.bst
new file mode 100644
index 00000000..9728f0bc
--- /dev/null
+++ b/elements/vm/dev-repo-script.bst
@@ -0,0 +1,19 @@
+kind: manual
+
+depends:
+- freedesktop-sdk.bst:bootstrap-import.bst
+
+runtime-depends:
+- core-deps/ostree.bst
+- freedesktop-sdk.bst:components/curl.bst
+
+config:
+  build-commands:
+    - sed -i "s/@@ARCH@@/%{arch}/g" enable-developer-repository
+
+  install-commands:
+  - install -Dm755 -t "%{install-root}%{bindir}" enable-developer-repository
+
+sources:
+- kind: local
+  path: files/vm/enable-developer-repository
diff --git a/files/vm/enable-developer-repository b/files/vm/enable-developer-repository
new file mode 100644
index 00000000..4980d428
--- /dev/null
+++ b/files/vm/enable-developer-repository
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+set -eu
+
+DEFAULT_REF="gnome-os/@@ARCH@@/devel"
+DEFAULT_NAME="local"
+DEFAULT_URL="http://10.0.2.2:8000/";
+DEFAULT_GPG="http://10.0.2.2:8000/key.gpg";
+
+while [ $# -gt 0 ]; do
+    case "$1" in
+        --name=*)
+            NAME="${1#--name=}"
+            ;;
+        --name)
+            shift
+            NAME="$1"
+            ;;
+        --ref=*)
+            REF="${1#--ref=}"
+            ;;
+        --ref)
+            shift
+            REF="${1}"
+            ;;
+        --url=*)
+            URL="${1#--url=}"
+            ;;
+        --url)
+            shift
+            URL="${1}"
+            ;;
+        --gpg=*)
+            GPG="${1#--gpg=}"
+            ;;
+        --gpg)
+            shift
+            GPG="${1}"
+            ;;
+        --help) ;&
+        -h)
+            cat <<EOF
+$0 [OPTIONS]
+
+Options:
+  --name NAME  OSTree remote name to add (default: ${DEFAULT_NAME})
+  --ref REF    OSTree ref to use (default: ${DEFAULT_REF})
+  --url URL    URL for remote OSTree repository (default: ${DEFAULT_URL})
+  --gpg URL    URL to the public key (default: ${DEFAULT_GPG}))
+  --help       Display this help message and exit
+EOF
+            exit 0
+            ;;
+    esac
+done
+
+: ${REF:="${DEFAULT_REF}"}
+: ${NAME:="${DEFAULT_NAME}"}
+: ${URL:="${DEFAULT_URL}"}
+: ${GPG:="${DEFAULT_GPG}"}
+
+ostree remote add --gpg-import=<(curl "${GPG}") "${NAME}" "${URL}"
+
+ostree pull "${NAME}" "${REF}"
+
+ostree admin deploy "${NAME}:${REF}"
+
+cat <<EOF
+You can now reboot.
+EOF
diff --git a/utils/run-local-repo.sh b/utils/run-local-repo.sh
new file mode 100755
index 00000000..7ac3bf85
--- /dev/null
+++ b/utils/run-local-repo.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+exec python3 -m http.server 8000 --directory ostree-repo
diff --git a/utils/update-local-repo.sh b/utils/update-local-repo.sh
new file mode 100755
index 00000000..64bc24cd
--- /dev/null
+++ b/utils/update-local-repo.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+set -eu
+
+: ${BST:=bst}
+export BST
+
+ref="$(${BST} show --format "%{vars}" --deps none vm/repo.bst | sed '/ostree-branch: /{;s///;q;};d')"
+
+if ! [ -d ostree-gpg ]; then
+    rm -rf ostree-gpg.tmp
+    mkdir ostree-gpg.tmp
+    chmod 0700 ostree-gpg.tmp
+    cat >ostree-gpg.tmp/key-config <<EOF
+Key-Type: DSA
+Key-Length: 1024
+Subkey-Type: ELG-E
+Subkey-Length: 1024
+Name-Real: Gnome OS
+Expire-Date: 0
+%no-protection
+%commit
+%echo finished
+EOF
+    gpg --batch --homedir=ostree-gpg.tmp --generate-key ostree-gpg.tmp/key-config
+    gpg --homedir=ostree-gpg.tmp -k --with-colons | sed '/^fpr:/q;d' | cut -d: -f10 
ostree-gpg.tmp/default-id
+    mv ostree-gpg.tmp ostree-gpg
+fi
+
+utils/update-repo.sh \
+    --gpg-homedir=ostree-gpg \
+    --gpg-sign="$(cat ostree-gpg/default-id)" \
+    --collection-id=org.gnome.GnomeOS \
+    --target-ref="${ref%/*}/devel" \
+    ostree-repo vm/repo.bst \
+    "${ref}"
+
+gpg --homedir=ostree-gpg --export --armor >ostree-repo/key.gpg
diff --git a/utils/update-repo.sh b/utils/update-repo.sh
new file mode 100755
index 00000000..c2e8f0d1
--- /dev/null
+++ b/utils/update-repo.sh
@@ -0,0 +1,116 @@
+#!/bin/bash
+
+set -eu
+
+gpg_opts=()
+main_opts=()
+
+help() {
+    cat <<EOF
+$0 [OPTIONS] REPO ELEMENT REF
+EOF
+}
+
+while [ $# -gt 0 ]; do
+    case "$1" in
+       --target-ref=*)
+           target_ref="${1#--target-ref=}"
+           ;;
+       --target-ref)
+           target_ref="$2"
+           shift
+           ;;
+       --gpg-*=*)
+           gpg_opts+=("$1")
+           ;;
+       --gpg-*)
+           gpg_opts+=("$1", "$2")
+           shift
+           ;;
+       --collection-id=*)
+           collection_id="${1#--collection-id=}"
+           ;;
+       --collection-id)
+           collection_id="${2}"
+           shift
+           ;;
+       --help)
+           help
+           exit 0
+           ;;
+       --)
+           main_opts+=("$@")
+           shift $(($#-1))
+           ;;
+       --*)
+           echo "Unknown option '$1'" 1>&2
+           exit 1
+           ;;
+       -*)
+           for ((i=1;$i < ${#1};++i)); do
+               case "${1:i}" in
+                   h)
+                       help
+                       exit 0
+                       ;;
+                   *)
+                       echo "Unknown option '${1:i}'" 1>&2
+                       exit 1
+                       ;;
+               esac
+           done
+           ;;
+       *)
+           main_opts+=("$1")
+           ;;
+    esac
+    shift
+done
+
+if [ ${#main_opts[*]} -ne 3 ]; then
+    echo "Wrong number of parameters" 1>&2
+    exit 1
+fi
+
+OSTREE_REPO="${main_opts[0]}"
+export OSTREE_REPO
+element="${main_opts[1]}"
+ref="${main_opts[2]}"
+: ${target_ref:="${ref}"}
+
+checkout="$(mktemp --suffix="-update-repo" -d -p "$(dirname ${OSTREE_REPO})")"
+
+on_exit() {
+    rm -rf "${checkout}"
+}
+trap on_exit EXIT
+
+${BST:-bst} build "${element}"
+${BST:-bst} checkout --hardlinks "${element}" "${checkout}"
+
+if ! [ -d ${OSTREE_REPO} ]; then
+    ostree init --repo=${OSTREE_REPO} --mode=archive
+fi
+
+commit="$(ostree --repo="${checkout}" rev-parse "${ref}")"
+ostree pull-local "${checkout}" "${commit}"
+
+prev_commit="$(ostree rev-parse "${target_ref}" 2>/dev/null || true)"
+
+ostree commit ${gpg_opts[*]} \
+       --branch="${target_ref}" --tree=ref="${commit}" --skip-if-unchanged
+
+new_commit="$(ostree rev-parse "${target_ref}")"
+
+if [ "${new_commit}" != "${prev_commit}" ]; then
+    ostree prune --refs-only --keep-younger-than="6 months ago"
+
+    if [ -n "${prev_commit}" ]; then
+        ostree static-delta generate "${target_ref}"
+    fi
+
+    ostree summary \
+           ${collection_id:+--add-metadata=ostree.deploy-collection-id='"'"${collection_id}"'"'} \
+           ${gpg_opts[*]} \
+           --update
+fi


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]