aboutsummaryrefslogtreecommitdiff
path: root/tools/load_bringelle.sh
blob: ad360ccc2da73d6cf1a4fd8b97dfea949c4989cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash

# Ensure to abort on error
set -e

wai=$(dirname $(readlink -f "$0")) # Current script directory
outdir="${wai}/../"
floppy="${outdir}/floppy.img"
mountp="$(mktemp -d)" # Mount point (where the floppy will be mounted temporally
kernel="${outdir}/src/bringelle"

check_for () {
    command -v "$1" &>/dev/null || { echo "Command $1 not found!"; exit 1; }
}

check_for losetup
[ ! -e "$floppy" ] && { echo "Floppy drive \"$floppy\" not found!"; exit 1; }
[ ! -e "$kernel" ] && { echo "Kernel \"$kernel\" not found!"; exit 1; }

# Initiate loop devices
loop=$(sudo losetup -f)
part="${loop}p1" # Disk partition
sudo losetup -Pf $floppy

# Prepare disk partition
sudo mount $part "$mountp"
cp $kernel $mountp/boot/bringelle.bs

# Umount floppy
sync
sudo umount "$mountp"
rmdir "$mountp"

# Cleanup
sudo losetup -D