target/linux/config: allow for selecting xtables support as module
[openadk.git] / scripts / install-rpi.sh
blobae4deff94193091d6491223c4c38920377142dee
1 #!/usr/bin/env bash
2 # This file is part of the OpenADK project. OpenADK is copyrighted
3 # material, please see the LICENCE file in the top-level directory.
5 if [ $(id -u) -ne 0 ];then
6 echo "Installation is only possible as root"
7 exit 1
8 fi
10 f=0
11 for tool in parted sfdisk mkfs.vfat mkfs.ext4;do
12 if ! which $tool >/dev/null; then
13 echo "Checking if $tool is installed... failed"
14 f=1
16 done
17 if [ $f -eq 1 ];then exit 1;fi
19 datadir=0
20 keep=0
21 while getopts "dk" ch; do
22 case $ch in
24 datadir=1
27 keep=1
29 esac
30 done
31 shift $((OPTIND - 1))
33 if [ -z $1 ];then
34 echo "Please give your SD card device as first parameter"
35 exit 1
36 else
37 if [ -z $2 ];then
38 echo "Please give your install tar archive as second parameter"
39 exit 1
41 if [ -f $2 ];then
42 echo "Installing $2 on $1"
43 else
44 echo "$2 is not a file, exiting"
45 exit 1
47 if [ -b $1 ];then
48 echo "Using $1 as SD card disk for installation"
49 echo "WARNING: This will destroy all data on $1 - type Yes to continue!"
50 read y
51 if [ "$y" = "Yes" ];then
52 env LC_ALL=C sfdisk -l $1 2>&1 |grep 'No medium'
53 if [ $? -eq 0 ];then
54 echo "No medium found"
55 exit 1
56 else
57 echo "Starting with installation"
59 else
60 echo "Exiting."
61 exit 1
63 else
64 echo "Sorry $1 is not a block device"
65 exit 1
70 if [ $(mount | grep $1| wc -l) -ne 0 ];then
71 echo "Block device $1 is in use, please umount first"
72 exit 1
75 echo "Wiping existing partitions"
76 dd if=/dev/zero of=$1 bs=512 count=1 >/dev/null 2>&1
77 sync
79 echo "Create partition and filesystem for raspberry pi"
80 rootpart=${1}2
81 parted -s $1 mklabel msdos
82 sleep 2
83 maxsize=$(env LC_ALL=C parted $1 -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//')
85 if [ $datadir -eq 0 ];then
86 rootsize=$(($maxsize-2))
87 else
88 rootsize=$(($maxsize-34))
89 datasize=$(($maxsize-2))
92 parted -s $1 unit cyl mkpart primary fat32 -- 0 16
93 if [ $datadir -eq 0 ];then
94 parted -s $1 unit cyl mkpart primary ext2 -- 16 $rootsize
95 parted -s $1 unit cyl mkpart primary fat32 $rootsize $maxsize
96 sfdisk --change-id $1 3 88 >/dev/null 2>&1
97 else
98 parted -s $1 unit cyl mkpart primary ext2 -- 16 $rootsize
99 parted -s $1 unit cyl mkpart primary ext2 $rootsize $datasize
100 parted -s $1 unit cyl mkpart primary fat32 $datasize $maxsize
101 parted -s $1 set 1 boot on
102 sfdisk --change-id $1 4 88 >/dev/null 2>&1
104 sleep 2
105 mkfs.vfat ${1}1 >/dev/null
106 mkfs.ext4 -F -q -O ^huge_file ${1}2
107 if [ $datadir -eq 1 ];then
108 if [ $keep -eq 0 ];then
109 mkfs.ext4 -F -q -O ^huge_file ${1}3
112 sync
113 sleep 2
115 tmp=$(mktemp -d)
116 mount -t ext4 ${rootpart} $tmp
117 mkdir $tmp/boot
118 if [ $datadir -eq 1 ];then
119 if [ $keep -eq 0 ];then
120 mkdir $tmp/data
121 mount -t ext4 ${1}3 $tmp/data
122 mkdir $tmp/data/mpd $tmp/data/xbmc
123 umount $tmp/data
126 mount -t vfat ${1}1 $tmp/boot
127 sleep 1
128 echo "Extracting install archive"
129 tar -C $tmp -xzpf $2
130 echo "Fixing permissions"
131 chmod 1777 $tmp/tmp
132 chmod 4755 $tmp/bin/busybox
133 if [ $datadir -eq 1 ];then
134 echo "/dev/mmcblk0p3 /data ext4 rw 0 0" >>$tmp/etc/fstab
136 umount $tmp/boot
137 umount $tmp
138 echo "Successfully installed."
139 exit 0