added event input kernel module
[openadk.git] / scripts / create-image.sh
blob4a23b49cf44b146cc92562722cea71f4db431aec
1 #!/usr/bin/env bash
3 filesystem=ext2
5 while getopts "f:i" option
6 do
7 case $option in
8 f)
9 filesystem=$OPTARG
12 initramfs=1
15 printf "Option not recognized\n"
16 exit 1
18 esac
19 done
20 shift $(($OPTIND - 1))
22 if [ $(id -u) -ne 0 ];then
23 printf "Installation is only possible as root\n"
24 exit 1
27 printf "Checking if parted is installed"
28 parted=$(which parted)
30 if [ ! -z $parted -a -x $parted ];then
31 printf "...okay\n"
32 else
33 printf "...failed\n"
34 exit 1
37 printf "Checking if qemu-img is installed"
38 qimg=$(which qemu-img)
40 if [ ! -z $qimg -a -x $qimg ];then
41 printf "...okay\n"
42 else
43 printf "...failed\n"
44 exit 1
47 if [ -z $1 ];then
48 printf "Please give the name of the image file\n"
49 exit 1
50 fi
52 if [ -z $initramfs ];then
53 if [ -z $2 ];then
54 printf "Please give the name of the openadk archive file\n"
55 exit 1
56 fi
57 else
58 if [ -z $2 ];then
59 printf "Please give the full path prefix to kernel/initramfs\n"
60 exit 1
65 printf "Generate qemu image\n"
66 $qimg create -f raw $1 512M >/dev/null
68 printf "Creating filesystem $filesystem\n"
70 printf "Create partition and filesystem\n"
71 $parted -s $1 mklabel msdos
72 $parted -s $1 mkpart primary ext2 0 100%
73 $parted -s $1 set 1 boot on
75 dd if=$1 of=mbr bs=16384 count=1 2>/dev/null
76 dd if=$1 skip=16384 of=$1.new 2>/dev/null
78 if [ "$filesystem" = "ext2" -o "$filesystem" = "ext3" -o "$filesystem" = "ext4" ];then
79 mkfsopts=-F
82 mkfs.$filesystem $mkfsopts ${1}.new >/dev/null
84 if [ $? -eq 0 ];then
85 printf "Successfully created partition\n"
86 #$parted $1 print
87 else
88 printf "Partition creation failed, Exiting.\n"
89 exit 1
92 cat mbr ${1}.new > $1
93 rm ${1}.new
94 rm mbr
96 tmp=$(mktemp -d)
98 mount -o loop,offset=16384 -t $filesystem $1 $tmp
100 if [ -z $initramfs ];then
101 printf "Extracting install archive\n"
102 tar -C $tmp -xzpf $2
103 printf "Fixing permissions\n"
104 chmod 1777 $tmp/tmp
105 chmod 4755 $tmp/bin/busybox
106 else
107 printf "Copying kernel/initramfs\n"
108 mkdir $tmp/boot $tmp/dev
109 cp $2-kernel $tmp/boot/kernel
110 cp $2-initramfs $tmp/boot/initramfs
113 printf "Creating device nodes\n"
114 mknod -m 666 $tmp/dev/zero c 1 5
115 mknod -m 666 $tmp/dev/null c 1 3
116 mknod -m 622 $tmp/dev/console c 5 1
117 mknod -m 666 $tmp/dev/tty c 5 0
118 mknod -m 666 $tmp/dev/tty0 c 4 0
119 #mknod -m 660 $tmp/dev/hda b 3 0
120 #mknod -m 660 $tmp/dev/hda1 b 3 1
121 mknod -m 666 $tmp/dev/ttyS0 c 4 64
123 umount $tmp
125 printf "Successfully installed.\n"
126 printf "Be sure $1 is writable for the user which use qemu\n"
127 exit 0