<commit_before>#!/bin/bash
[[ "$#" == "2" ]] || {
	echo "Usage: $0 <rootfs> <initramfs_dir>"
	exit 1
}

[[ $EUID == 0 ]] || {
	exec sudo -E "$0" "$@"
}

ROOTFS="$(readlink -f "$1")"
INITRAMFS="$(readlink -f "$2")"

SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
TOP_DIR="$(readlink -f "$SCRIPT_DIR/..")"
FILES_DIR="$SCRIPT_DIR/files"

install_file() {
	local src="$1"
	local dst="$2"
	shift 2
	
	echo "$dst <- $src"
	install -D -T "$@" "$src" "$INITRAMFS/$dst"
}

install_from_rootfs() {
	local src="$1"
	local dst="$2"
	shift

	[[ -z "$dst" ]] && {
		dst="$src"
		shift
	}
	install_file "$ROOTFS/$src" "$dst" "$@"
}

rm -rf "$INITRAMFS"

mkdir -p "$INITRAMFS/dev"
mkdir -p "$INITRAMFS/proc"
mkdir -p "$INITRAMFS/sys"

mkdir -p "$INITRAMFS/sbin"
mkdir -p "$INITRAMFS/usr/bin"
mkdir -p "$INITRAMFS/usr/sbin"

mknod "$INITRAMFS/dev/console" c 5 1

install_from_rootfs /bin/busybox
install_file "$FILES_DIR/init" "/init"
install_file "$FILES_DIR/fstab" "/etc/fstab"<commit_msg>initramfs: some cleanups of create_initramfs.sh<commit_after>#!/bin/bash
set -e
#set -x

[[ "$#" == "2" ]] || {
	echo "Usage: $0 <rootfs> <initramfs_dir>"
	exit 1
}

[[ $EUID == 0 ]] || {
	exec sudo -E "$0" "$@"
}

ROOTFS="$(readlink -f "$1")"
INITRAMFS="$(readlink -f "$2")"

SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
TOP_DIR="$(readlink -f "$SCRIPT_DIR/..")"
FILES_DIR="$SCRIPT_DIR/files"

install_dir() {
	echo "dir $1"
	mkdir -p "$INITRAMFS/$1"
}

install_file() {
	local src="$1"
	local dst="$2"
	
	local dstdir=$(dirname "$dst")
	[[ -d "$INITRAMFS/$dstdir" ]] || install_dir "$dstdir"
	
	echo "file $dst <- $src"
	cp "$src" "$INITRAMFS/$dst"
}

install_from_rootfs() {
	local src="$1"
	local dst="$2"

	[[ -z "$dst" ]] && {
		dst="$src"
		shift
	}
	install_file "$ROOTFS/$src" "$dst"
}

rm -rf "$INITRAMFS"

install_dir "/dev"
install_dir "/proc"
install_dir "/sys"

install_dir "/sbin"
install_dir "/usr/bin"
install_dir "/usr/sbin"

mknod "$INITRAMFS/dev/console" c 5 1

install_from_rootfs /bin/busybox
install_file "$FILES_DIR/init" "/init"
install_file "$FILES_DIR/fstab" "/etc/fstab"
{'fraction_non_alphanumeric': 0.2340627973358706, 'fraction_numerical': 0.014747859181731684, 'mean_word_length': 4.297229219143577, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '3803403', 'n_tokens_mistral': 986, 'n_tokens_neox': 901, 'n_words': 193}