summaryrefslogtreecommitdiff
path: root/package/adkinstall/src/adkinstall.rb532
blob: 9f1af0bb6dab20655e82f650d1bbc64ce452e741 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
# installs a rootfs tar archive from OpenADK onto 
# a Compact Flash disk or NAND device
# special script for routerboard rb532

nandinstall=0
cfinstall=0

if [ -z $1 ];then
        printf "Please give your target device as first parameter [cf|nand]\n"
        exit 1
fi
if [ -z $2 ];then
        printf "Please give your root tar archive as second parameter\n"
        exit 1
fi
case $1 in
	nand)
		nandinstall=1
		;;
	cf)
		cfinstall=1
		;;
	*)
		printf "Target device not known.\n"
		exit 1
		;;
esac

if [ $cfinstall -eq 1 ];then
	if [ -z $3 ];then
       	 printf "Please give your kernel as third parameter\n"
       	 exit 1
	fi
fi

if [ $cfinstall -eq 1 ];then
	# create empty partition table
	printf "Creating partition scheme\n"
	parted -s /dev/sda mklabel msdos
	sleep 2
	maxsize=$(env LC_ALL=C parted /dev/sda -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//')
	rootsize=$(($maxsize-2))
	parted -s /dev/sda unit cyl mkpart primary ext2 0 1
	parted -s /dev/sda unit cyl mkpart primary ext2 1 $rootsize
	parted -s /dev/sda unit cyl mkpart primary fat32 $rootsize $maxsize
	parted -s /dev/sda set 1 boot on
	sfdisk --change-id /dev/sda 1 27 >/dev/null 2>&1
	sfdisk --change-id /dev/sda 3 88 >/dev/null 2>&1
	sleep 2
	mke2fs /dev/sda2
	sync
	printf "Installing kernel\n"
	dd if=$3 of=/dev/sda1 bs=2048 >/dev/null 2>&1
	sync
	mount -t ext2 /dev/sda2 /mnt
fi

if [ $nandinstall -eq 1 ];then
	printf "Preparing mountpoints\n"
	mount -t yaffs2 /dev/mtdblock1 /mnt
	rm -rf /mnt/* >/dev/null 2>&1
	mkdir /mnt/boot
	mount -t yaffs2 /dev/mtdblock0 /mnt/boot
fi

printf "Extracting install archive\n"
tar -C /mnt -xzpf $2
if [ $? -ne 0 ];then
	printf "Extracting of install archive failed"
	exit 1
fi

chmod 1777 /mnt/tmp
chmod 4755 /mnt/bin/busybox
sync

if [ $nandinstall -eq 1 ];then
	umount /mnt/boot
fi
umount /mnt
if [ $? -ne 0 ];then
	printf "Unmounting filesystem failed"
	exit 1
else
	printf "Successfully installed.\n"
	exit 0
fi