<commit_before>#!/bin/bash

if [ $EUID != 0 ]; then
    echo "This script requires sudo, so it might not work."
fi

set -e

if [ -z "$PI_IMAGE" ]; then
    echo "Please set PI_IMAGE and try agian."
    exit 1
fi

if [[ "$PI_IMAGE" != /* ]]; then
    PI_IMAGE=$WORKSPACE_DIR/$PI_IMAGE
fi

echo "Allocating image..."
dd if=/dev/zero of=$PI_IMAGE bs=1GB count=1

echo "Setting up loopback device..."
PI_SD=$(sudo losetup --show -fP $PI_IMAGE)

# Setup no interactive since we know its a brand new file.
export SKIFF_NO_INTERACTIVE=1

$SKIFF_CURRENT_CONF_DIR/scripts/format_sd.sh
$SKIFF_CURRENT_CONF_DIR/scripts/install_sd.sh

echo "Removing loopback device..."
sudo losetup -d $PI_SD<commit_msg>pi/common: build_image: cleanup script, use skiff root as base dir<commit_after>#!/bin/bash

if [ $EUID != 0 ]; then
    echo "This script requires sudo, so it might not work."
fi

set -e

if [ -z "$PI_IMAGE" ]; then
    echo "Please set PI_IMAGE to the path to the output image."
    exit 1
fi

if [[ "$PI_IMAGE" != /* ]]; then
    # the "make" command is run from the skiff root,
    # it's most intuitive to take that as the base path
    PI_IMAGE=$SKIFF_ROOT_DIR/$PI_IMAGE
fi

echo "Allocating image..."
dd if=/dev/zero of=$PI_IMAGE bs=1GB count=1

echo "Setting up loopback device..."
export PI_SD=$(losetup --show -fP $PI_IMAGE)
function cleanup {
  echo "Removing loopback device..." || true
  sync || true
  losetup -d $PI_SD || true
}
trap cleanup EXIT

# Setup no interactive since we know its a brand new file.
export SKIFF_NO_INTERACTIVE=1

echo "Using loopback device at ${PI_SD}"
$SKIFF_CURRENT_CONF_DIR/scripts/format_sd.sh
$SKIFF_CURRENT_CONF_DIR/scripts/install_sd.sh

{'fraction_non_alphanumeric': 0.1174716756112105, 'fraction_numerical': 0.005963029218843173, 'mean_word_length': 3.7535410764872523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3003318', 'n_tokens_mistral': 611, 'n_tokens_neox': 588, 'n_words': 201}