diff --git a/script/unzipper b/script/unzipper index a0222ab..9a46be8 100755 --- a/script/unzipper +++ b/script/unzipper @@ -16,12 +16,72 @@ trap cleanup EXIT mkdir -p "$SHARDS_INSTALL_PATH" mkdir -p "$SHARDS_CACHE_PATH/github.com" -# iterate over all the cached shards in the vendor/shards/cache directory -for shard in $(find "$SHARDS_CACHED" -type f -maxdepth 1); do +# check if the .shards.info file exists, if it doesn't this is a fresh bootstrapping +if [ ! -f "$VENDOR_DIR/shards/install/.shards.info" ]; then + # if no .shards.info file found, this must be a fresh bootstrapping + + # iterate over all the cached shards in the vendor/shards/cache directory + for shard in $(find "$SHARDS_CACHED" -type f -maxdepth 1); do + # unzip the file into the TRASHDIR unzip -q -o "$shard" -d "$TRASHDIR" + + # get the only name of the dir in the TRASHDIR + shard_name=$(ls "$TRASHDIR/shard/") + + # clear up the shard in the install dir if it exists + rm -rf "$SHARDS_INSTALL_PATH/$shard_name" + # move the shard and cache directories to the correct location mv -f "$TRASHDIR/shard/"* "$SHARDS_INSTALL_PATH/" 2>/dev/null || true mv -f "$TRASHDIR/cache/"* "$SHARDS_CACHE_PATH/github.com/" 2>/dev/null || true -done + # cleanup the TRASHDIR + rm -rf "$TRASHDIR/shard" + rm -rf "$TRASHDIR/cache" + done + +else + # if found .shards.info file, this must be a bootstrap re-run - we will check if the shards have changed by comparing the sha256 of the cached shard and the sha256 of the current shard + + file="vendor/shards/install/.shards.info" + + # Use yq to parse the file and extract shard names and versions + shards=$(yq eval '.shards | to_entries | .[] | "\(.key)|\(.value.git)|\(.value.version)"' $file) + + # Loop over each shard + echo "$shards" | while IFS= read -r shard; do + # Extract name and version + name=$(echo $shard | cut -d'|' -f1) + version=$(echo $shard | cut -d'|' -f3) + + shard_cache_sha=$(shasum -a 256 "$SHARDS_CACHED/$name-$version.shard" | cut -d' ' -f1) + shard_current_sha="" + if [ -f "$SHARDS_INSTALL_PATH/$name/.shard.vendor.cache.sha256" ]; then + shard_current_sha=$(cat "$SHARDS_INSTALL_PATH/$name/.shard.vendor.cache.sha256") + fi + + if [ "$shard_cache_sha" != "$shard_current_sha" ]; then + echo "shard $name $version has changed, updating" + + # unzip the file into the TRASHDIR + unzip -q -o "$SHARDS_CACHED/$name-$version.shard" -d "$TRASHDIR" + + # clear up the shard in the install dir if it exists + rm -rf "$SHARDS_INSTALL_PATH/$name" + + # move the shard and cache directories to the correct location + mv -f "$TRASHDIR/shard/"* "$SHARDS_INSTALL_PATH/" 2>/dev/null || true + mv -f "$TRASHDIR/cache/"* "$SHARDS_CACHE_PATH/github.com/" 2>/dev/null || true + + # write the new sha to the .shard.vendor.cache.sha256 file + cat > "$SHARDS_INSTALL_PATH/$name/.shard.vendor.cache.sha256" <<< "$shard_cache_sha" + + # cleanup the TRASHDIR + rm -rf "$TRASHDIR/shard" + rm -rf "$TRASHDIR/cache" + else + echo "shard $name $version has not changed, skipping" + fi + done +fi diff --git a/vendor/shards/cache/ameba-1.6.1.shard b/vendor/shards/cache/ameba-1.6.1.shard index f03b676..51e7ad0 100644 Binary files a/vendor/shards/cache/ameba-1.6.1.shard and b/vendor/shards/cache/ameba-1.6.1.shard differ diff --git a/vendor/shards/cache/halite-0.12.0.shard b/vendor/shards/cache/halite-0.12.0.shard index 3a2c319..ae4c0fb 100644 Binary files a/vendor/shards/cache/halite-0.12.0.shard and b/vendor/shards/cache/halite-0.12.0.shard differ diff --git a/vendor/shards/cache/json_mapping-0.1.1.shard b/vendor/shards/cache/json_mapping-0.1.1.shard index 04b5eff..eaa76a8 100644 Binary files a/vendor/shards/cache/json_mapping-0.1.1.shard and b/vendor/shards/cache/json_mapping-0.1.1.shard differ diff --git a/vendor/shards/cache/octokit-0.3.0.shard b/vendor/shards/cache/octokit-0.3.0.shard index 44a6599..5d32cf2 100644 Binary files a/vendor/shards/cache/octokit-0.3.0.shard and b/vendor/shards/cache/octokit-0.3.0.shard differ