2 # Shell script to install Nameless to a disk.
4 BINARIES
=( boot
/x86
/mbr boot
/x86
/vbr-fat32 boot
/x86
/stage
3/LOADER.BIN kernel
/kernel.elf
)
7 for i
in "${BINARIES[@]}"; do
9 echo $i does not exist
, have you compiled Nameless?
16 # Ask the user are they sure they want to install.
18 echo About to
install Nameless to real disk
$target.
19 echo This will WIPE ALL DATA on
$target, type YES
if you want to
continue.
21 if [ $prompt != "YES" ]; then
26 echo OK
, installing Nameless to
$target.
27 echo Creating partition table on
$target...
29 # Create a partition table on the disk.
30 fdisk
$target <<- END > /dev/null
42 if ! [ $?
-eq 0 ]; then
43 echo An error occurred
!
46 # Create a FAT32 filesystem on the disk.
47 echo Formatting
$target...
48 mkfs.fat
-F 32 "$target"1
49 if ! [ $?
-eq 0 ]; then
50 echo An error occurred
!
53 # Write MBR and VBR to the disk.
54 # TODO: write VBR to the backup BPB as well?
55 echo Writing bootsectors to
$target...
56 dd 'if=boot/x86/mbr' "of=$target" 'bs=440' 'count=1'
57 if ! [ $?
-eq 0 ]; then
58 echo An error occurred
!
61 dd 'if=boot/x86/vbr-fat32' 'of='"$target"1 'bs=1' 'skip=90' 'seek=90'
62 if ! [ $?
-eq 0 ]; then
63 echo An error occurred
!
66 # Mount the partition and copy stage3 and kernel to it.
67 echo Copying files to
$target...
68 local mountpoint
=$
(mktemp
-d)
69 mount
"$target"1 $mountpoint
70 if ! [ $?
-eq 0 ]; then
71 echo An error occurred
!
74 cp boot
/x86
/stage
3/LOADER.BIN
$mountpoint/LOADER.BIN
75 cp kernel
/kernel.elf
$mountpoint/KERNEL.ELF
76 if ! [ $?
-eq 0 ]; then
77 echo An error occurred
!
80 # Unmount the partition and flush write cache to make sure the OS
81 # binaries have actually been written to the disk.
82 echo Unmounting
$target...
85 echo Flushing cache...
87 echo Nameless has been successfully installed to
$target!
91 # Check if all the required tools are installed.
92 [ -z $
(command -v fdisk
) ] && echo fdisk not found
, is util-linux installed?
&& exit 127
93 [ -z $
(command -v mkfs.fat
) ] && echo mkfs.fat not found
, is dosfstools installed?
&& exit 127
95 # Make sure that Nameless has been compiled.
98 # cd to the directory we're in.
99 cd $
(dirname $
(realpath
$0))
101 # For convenience, list all connected disks.
104 # Ask the user where to install.
105 echo -n "Choose the disk you want to install to: "
108 # If the target does not exist or is not a blkdev, exit.
109 [ -b $target ] ||
echo $target does not exist or is not a block device
! ||
exit 1