summaryrefslogtreecommitdiff
path: root/scripts/install-solidrun.sh
blob: 0a360a3e445f938031848ae080341c098625e42c (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# This file is part of the OpenADK project. OpenADK is copyrighted
# material, please see the LICENCE file in the top-level directory.

if [ $(id -u) -ne 0 ];then
	echo "Installation is only possible as root"
	exit 1
fi

f=0
for tool in parted sfdisk mkfs.ext4;do
	if ! which $tool >/dev/null; then
		echo "Checking if $tool is installed... failed"
		f=1
	fi
done
if [ $f -eq 1 ];then exit 1;fi

datadir=0
keep=0
while getopts "dk" ch; do
	case $ch in
		d)
			datadir=1
			;;
		k)
			keep=1
			;;
	esac
done
shift $((OPTIND - 1))

if [ -z $1 ];then
	echo "Please give your SD card device as first parameter"
	exit 1
else
	if [ -z $2 ];then
		echo "Please give your install tar archive as second parameter"
		exit 1
	fi
	if [ -f $2 ];then
		echo "Installing $2 on $1"
	else
		echo "$2 is not a file, exiting"
		exit 1
	fi
	if [ -z $3 ];then
		echo "Please give your firmware directory as third parameter"
		exit 1
	fi
	if [ ! -d $3 ];then
		echo "$3 is not a directory, exiting"
		exit 1
	fi
	if [ -b $1 ];then
		echo "Using $1 as SD card disk for installation"
		echo "WARNING: This will destroy all data on $1 - type Yes to continue!"
		read y
		if [ "$y" = "Yes" ];then
			env LC_ALL=C sfdisk -l $1 2>&1 |grep 'No medium'
			if [ $? -eq 0 ];then
				echo "No medium found"
				exit 1
			else
				echo "Starting with installation"
			fi
		else
			echo "Exiting."
			exit 1
		fi
	else
		echo "Sorry $1 is not a block device"
		exit 1
	fi
fi

if [ $(mount | grep $1| wc -l) -ne 0 ];then
	echo "Block device $1 is in use, please umount first"
	exit 1
fi

maxsize=$(env LC_ALL=C parted $1 -s unit s print |awk '/^Disk/ { print $3 }'|sed -e 's/s//')
maxsize=$(($maxsize-1))

if [ $datadir -eq 0 ];then
	rootsize=$(($maxsize-32768))
	rootsizeend=$(($rootsize+1))
else
	rootsize=$(($maxsize-32768-131072))
	rootsizeend=$(($rootsize+1))
	datasize=$(($maxsize-32768))
	datasizeend=$(($datasize+1))
fi

echo "Install bootloader for cubox-i/hummingboard"
parted -s $1 mklabel msdos >/dev/null 2>&1
dd if=${3}/SPL of=${1} bs=1K seek=1 >/dev/null 2>&1
dd if=${3}/u-boot.img of=${1} bs=1K seek=42 >/dev/null 2>&1
if [ $datadir -eq 0 ];then
	parted -a optimal -s $1 unit s mkpart primary ext2 -- 2048 $rootsize >/dev/null 2>&1
	parted -a optimal -s $1 unit s mkpart primary fat32 -- $rootsizeend $maxsize
	sfdisk --change-id $1 2 88 >/dev/null 2>&1
else
	parted -a optimal -s $1 unit s mkpart primary ext2 -- 2048 $rootsize
	parted -a optimal -s $1 unit s mkpart primary ext2 -- $rootsizeend $datasize
	parted -a optimal -s $1 unit s mkpart primary fat32 -- $datasizeend $maxsize
	sfdisk --change-id $1 3 88

fi

echo "Creating filesystem"
mkfs.ext4 -F -q -O ^huge_file ${1}1
sync
if [ $datadir -eq 1 ];then
        if [ $keep -eq 0 ];then
                mkfs.ext4 -F -q -O ^huge_file ${1}2
        fi
fi

tmp=$(mktemp -d)
mount -t ext4 ${1}1 $tmp

if [ $datadir -eq 1 ];then
        if [ $keep -eq 0 ];then
                mkdir $tmp/data
                mount -t ext4 ${1}2 $tmp/data
                mkdir $tmp/data/mpd $tmp/data/xbmc
                umount $tmp/data
        fi
fi

echo "Extracting install archive"
tar -C $tmp -xzpf $2 
if [ $datadir -eq 1 ];then
	echo "/dev/mmcblk0p2    /data   ext4    rw      0       0" >>$tmp/etc/fstab
fi
echo "Fixing permissions"
chmod 1777 $tmp/tmp
chmod 4755 $tmp/bin/busybox
cp ${3}/*.dtb $tmp/boot/
umount $tmp
echo "Successfully installed."
exit 0