<commit_before>#!/bin/bash

argv=($@)
argc=$#

case ${argv[0]} in
    64)
        ARCH="amd64"
        FOLDER_INSTALL="install.amd"
    ;;

    32)
        ARCH="i386"
        FOLDER_INSTALL="install.386"
    ;;

    *)
        echo "usage: $0 <32|64>"
        exit
    ;;
esac

VERSION="6.0.5"
BOX="debian-${VERSION}-${ARCH}"

DEBIAN_MIRROR="ftp.acc.umu.se"
DEBIAN_URL="http://${DEBIAN_MIRROR}/debian-cd/${VERSION}/${ARCH}/iso-cd"
DEBIAN_ISO_NAME="debian-${VERSION}-${ARCH}-netinst.iso"
DEBIAN_ISO_URL="${DEBIAN_URL}/${DEBIAN_ISO_NAME}"

FOLDER_BASE=`pwd`
FOLDER_BUILD="${FOLDER_BASE}/build"
FOLDER_VBOX="${FOLDER_BUILD}/vbox"
FOLDER_ISO="${FOLDER_BUILD}/iso"
FOLDER_ISO_CUSTOM="${FOLDER_ISO}/custom"
FOLDER_ISO_INITRD="${FOLDER_ISO}/initrd"
FOLDER_ISO_CUSTOM_INSTALL="${FOLDER_ISO_CUSTOM}/${FOLDER_INSTALL}"

ISO_FILEPATH="${FOLDER_ISO}/${DEBIAN_ISO_NAME}"

function abort {
	echo >&2 "ERROR: $1"
	exit 1
}

function info {
	echo "INFO: $1"
}

# Check if VM name is occupied
if VBoxManage showvminfo "${BOX}" >/dev/null 2>/dev/null; then
	abort "VM ${BOX} already exist. Aborting."
fi

info "Cleaning build directories..."
mkdir -p "${FOLDER_BUILD}"
chmod -R u+w "${FOLDER_BUILD}"
rm -rf "${FOLDER_ISO_CUSTOM}"
rm -rf "${FOLDER_ISO_INITRD}"

mkdir -p "${FOLDER_VBOX}"
mkdir -p "${FOLDER_ISO}"
mkdir -p "${FOLDER_ISO_CUSTOM}"
mkdir -p "${FOLDER_ISO_INITRD}"

# Download ISO if needed
info "Downloading ${DEBIAN_ISO_NAME}..."
if [ ! -f "${ISO_FILEPATH}" ]; then
	curl --progress-bar -o "${ISO_FILEPATH}" -L "${DEBIAN_ISO_URL}"
fi

# Command to get MD5 hash from server
ISO_MD5=$(curl -s "${DEBIAN_URL}/MD5SUMS" | grep "${DEBIAN_ISO_NAME}" | awk '{ print $1 }')

# Check if hash is correct
if [ ! "${ISO_MD5}" ]; then
	info "Faild to download MD5 hash for ${DEBIAN_ISO_NAME}. Skipping."
else
	ISO_HASH=`md5 -q "${ISO_FILEPATH}"`
	if [ "${ISO_MD5}" != "${ISO_HASH}" ]; then
		abort "MD5 does not match - expected ${ISO_MD5}. Aborting."
	fi
fi

info "Unpacking ${DEBIAN_ISO_NAME}..."
bsdtar -xf "${ISO_FILEPATH}" -C "${FOLDER_ISO_CUSTOM}"

info "Customizing ISO files..."
chmod -R u+w "${FOLDER_ISO_CUSTOM}"

cd "${FOLDER_ISO_INITRD}"
	gunzip -c "${FOLDER_ISO_CUSTOM_INSTALL}/initrd.gz" | cpio -id
	cp "${FOLDER_BASE}/conf/preseed.cfg" "${FOLDER_ISO_INITRD}/preseed.cfg"
	find . | cpio --create --format='newc' | gzip  > "${FOLDER_ISO_CUSTOM_INSTALL}/initrd.gz"
cd "${FOLDER_BASE}"

cp "${FOLDER_BASE}/conf/late_command.sh" "${FOLDER_ISO_CUSTOM}/late_command.sh"
cp "${FOLDER_BASE}/conf/isolinux.${ARCH}.cfg" "${FOLDER_ISO_CUSTOM}/isolinux/isolinux.cfg"

info "Packing ISO files..."
mkisofs -r -V "Custom Debian Install CD" -cache-inodes -quiet -J -l \<commit_msg>Replace cd with pushd/popd<commit_after>#!/bin/bash

argv=($@)
argc=$#

case ${argv[0]} in
    64)
        ARCH="amd64"
        FOLDER_INSTALL="install.amd"
    ;;

    32)
        ARCH="i386"
        FOLDER_INSTALL="install.386"
    ;;

    *)
        echo "usage: $0 <32|64>"
        exit
    ;;
esac

VERSION="6.0.5"
BOX="debian-${VERSION}-${ARCH}"

DEBIAN_MIRROR="ftp.acc.umu.se"
DEBIAN_URL="http://${DEBIAN_MIRROR}/debian-cd/${VERSION}/${ARCH}/iso-cd"
DEBIAN_ISO_NAME="debian-${VERSION}-${ARCH}-netinst.iso"
DEBIAN_ISO_URL="${DEBIAN_URL}/${DEBIAN_ISO_NAME}"

FOLDER_BASE=`pwd`
FOLDER_BUILD="${FOLDER_BASE}/build"
FOLDER_VBOX="${FOLDER_BUILD}/vbox"
FOLDER_ISO="${FOLDER_BUILD}/iso"
FOLDER_ISO_CUSTOM="${FOLDER_ISO}/custom"
FOLDER_ISO_INITRD="${FOLDER_ISO}/initrd"
FOLDER_ISO_CUSTOM_INSTALL="${FOLDER_ISO_CUSTOM}/${FOLDER_INSTALL}"

ISO_FILEPATH="${FOLDER_ISO}/${DEBIAN_ISO_NAME}"

function abort {
	echo >&2 "ERROR: $1"
	exit 1
}

function info {
	echo "INFO: $1"
}

# Check if VM name is occupied
if VBoxManage showvminfo "${BOX}" >/dev/null 2>/dev/null; then
	abort "VM ${BOX} already exist. Aborting."
fi

info "Cleaning build directories..."
mkdir -p "${FOLDER_BUILD}"
chmod -R u+w "${FOLDER_BUILD}"
rm -rf "${FOLDER_ISO_CUSTOM}"
rm -rf "${FOLDER_ISO_INITRD}"

mkdir -p "${FOLDER_VBOX}"
mkdir -p "${FOLDER_ISO}"
mkdir -p "${FOLDER_ISO_CUSTOM}"
mkdir -p "${FOLDER_ISO_INITRD}"

# Download ISO if needed
info "Downloading ${DEBIAN_ISO_NAME}..."
if [ ! -f "${ISO_FILEPATH}" ]; then
	curl --progress-bar -o "${ISO_FILEPATH}" -L "${DEBIAN_ISO_URL}"
fi

# Command to get MD5 hash from server
ISO_MD5=$(curl -s "${DEBIAN_URL}/MD5SUMS" | grep "${DEBIAN_ISO_NAME}" | awk '{ print $1 }')

# Check if hash is correct
if [ ! "${ISO_MD5}" ]; then
	info "Faild to download MD5 hash for ${DEBIAN_ISO_NAME}. Skipping."
else
	ISO_HASH=`md5 -q "${ISO_FILEPATH}"`
	if [ "${ISO_MD5}" != "${ISO_HASH}" ]; then
		abort "MD5 does not match - expected ${ISO_MD5}. Aborting."
	fi
fi

info "Unpacking ${DEBIAN_ISO_NAME}..."
bsdtar -xf "${ISO_FILEPATH}" -C "${FOLDER_ISO_CUSTOM}"

info "Customizing ISO files..."
chmod -R u+w "${FOLDER_ISO_CUSTOM}"

pushd "${FOLDER_ISO_INITRD}"
	gunzip -c "${FOLDER_ISO_CUSTOM_INSTALL}/initrd.gz" | cpio -id
	cp "${FOLDER_BASE}/conf/preseed.cfg" "${FOLDER_ISO_INITRD}/preseed.cfg"
	find . | cpio --create --format='newc' | gzip  > "${FOLDER_ISO_CUSTOM_INSTALL}/initrd.gz"
popd

cp "${FOLDER_BASE}/conf/late_command.sh" "${FOLDER_ISO_CUSTOM}/late_command.sh"
cp "${FOLDER_BASE}/conf/isolinux.${ARCH}.cfg" "${FOLDER_ISO_CUSTOM}/isolinux/isolinux.cfg"

info "Packing ISO files..."
mkisofs -r -V "Custom Debian Install CD" -cache-inodes -quiet -J -l \
{'fraction_non_alphanumeric': 0.18899117039263574, 'fraction_numerical': 0.013526207026113094, 'mean_word_length': 4.651804670912951, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4052777', 'n_tokens_mistral': 2311, 'n_tokens_neox': 2217, 'n_words': 436}