kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

dist-kitchen.sh (2876B)


      1 #!/bin/sh
      2 # Coarse Tier 1 kitchen-sink smoke for CAS and package distribution.
      3 
      4 set -u
      5 
      6 script_dir=$(cd "$(dirname "$0")" && pwd)
      7 repo_root=$(cd "$script_dir/../../.." && pwd)
      8 KIT="${KIT:-$repo_root/build/kit}"
      9 
     10 if [ ! -x "$KIT" ]; then
     11     echo "dist-kitchen: kit binary not found at $KIT" >&2
     12     exit 2
     13 fi
     14 
     15 work=$(mktemp -d "${TMPDIR:-/tmp}/kit-t1-dist.XXXXXX")
     16 trap 'rm -rf "$work"' EXIT
     17 
     18 HOME="$work/home"
     19 KIT_TRUSTED_KEYS="$work/trusted_keys"
     20 SOURCE_DATE_EPOCH=1
     21 export HOME KIT_TRUSTED_KEYS SOURCE_DATE_EPOCH
     22 
     23 KIT_KIT_DIR="$repo_root/test/lib"
     24 . "$repo_root/test/lib/kit_sh_kit.sh"
     25 kit_report_init
     26 
     27 mkdir -p "$work/src/bin" "$work/cas" "$work/out" "$work/pkg" "$work/unpack"
     28 printf 'tier1 package payload\n' > "$work/src/payload.txt"
     29 {
     30     printf '#!/bin/sh\n'
     31     printf 'printf "tier1 tool\\n"\n'
     32 } > "$work/src/bin/tool.sh"
     33 chmod +x "$work/src/bin/tool.sh"
     34 
     35 run_ok cas-add-tree "$KIT" cas add-tree --cas "$work/cas" --root "$work/src"
     36 tree_id=$(first_hex_id "$work/cas-add-tree.out")
     37 if [ -n "$tree_id" ]; then
     38     ok cas-tree-id
     39 else
     40     echo "could not parse tree id" > "$work/cas-tree-id.diag"
     41     not_ok cas-tree-id "$work/cas-tree-id.diag"
     42 fi
     43 tree_file=$(cas_object_path "$work/cas" tree "$tree_id")
     44 assert_file_exists cas-tree-object "$tree_file"
     45 run_ok cas-verify "$KIT" cas verify-tree --cas "$work/cas" "$tree_id"
     46 run_ok cas-materialize "$KIT" cas materialize --cas "$work/cas" "$tree_id" -C "$work/out/root"
     47 same_file cas-materialize-payload "$work/src/payload.txt" "$work/out/root/payload.txt"
     48 is_executable cas-materialize-exec "$work/out/root/bin/tool.sh"
     49 
     50 run_ok pkg-keygen "$KIT" pkg keygen -o "$work/key"
     51 run_ok pkg-create-targz "$KIT" pkg create --name tier1 --version 1.0.0 \
     52     --format tar.gz --cas "$work/cas" --tree "$tree_id" \
     53     -s "$work/key.key" -o "$work/pkg/tier1.tar.gz"
     54 run_ok pkg-verify-targz "$KIT" pkg verify -p "$work/key.pub" "$work/pkg/tier1.tar.gz"
     55 
     56 run_ok pkg-create-kpkg "$KIT" pkg create --name tier1 --version 1.0.0 \
     57     --format kpkg --compression lz4-block-v1 --cas "$work/cas" --tree "$tree_id" \
     58     -s "$work/key.key" -o "$work/pkg/tier1.kpkg"
     59 run_ok pkg-inspect-kpkg "$KIT" pkg inspect "$work/pkg/tier1.kpkg"
     60 contains pkg-inspect-name "$work/pkg-inspect-kpkg.out" "name = tier1"
     61 run_ok pkg-verify-kpkg "$KIT" pkg verify -p "$work/key.pub" "$work/pkg/tier1.kpkg"
     62 run_ok pkg-unpack-kpkg "$KIT" pkg unpack --verify -p "$work/key.pub" \
     63     "$work/pkg/tier1.kpkg" -C "$work/unpack/kpkg"
     64 same_file pkg-unpack-payload "$work/src/payload.txt" "$work/unpack/kpkg/payload.txt"
     65 is_executable pkg-unpack-exec "$work/unpack/kpkg/bin/tool.sh"
     66 
     67 cp "$work/pkg/tier1.kpkg" "$work/pkg/tier1.bad.kpkg"
     68 printf '\377' | dd of="$work/pkg/tier1.bad.kpkg" bs=1 seek=0 count=1 conv=notrunc \
     69     >/dev/null 2>&1
     70 run_fail pkg-rejects-tamper "$KIT" pkg verify -p "$work/key.pub" "$work/pkg/tier1.bad.kpkg"
     71 
     72 kit_summary dist-kitchen
     73 kit_exit