Skip to content
This repository
tree: 2694a3604c
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 134 lines (97 sloc) 2.635 kb
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
#!/bin/sh -x

# Répertoire de travail
SH_BASE="${SH_BASE:-`pwd`}"

#Scripts de live-helper
. "${LH_BASE:-/usr/share/live-helper}"/functions.sh

# $LS_BINARY: Image iso
# (Default: binary.iso)
LS_BINARY="${LS_BINARY:-binary.iso}"

if [ -z $1 ]
then
Echo "Usage : ./install.sh /dev/sdX"
exit 0
fi

# $LS_DEVICE: clé usb
# (Default: empty)
LS_DEVICE=$1
FS="true"

Echo "Device : ${LS_DEVICE}"

SIZEISOB=`stat -c %s ${LS_BINARY}`
Echo "Size of iso : ${SIZEISOB} bytes"

CYLINDERSBY=`sfdisk -l ${LS_DEVICE}|grep "Units = "|awk {'print $5'}` 2>&1
Echo "Number of Bytes/cylinders : ${CYLINDERSBY}"


SIZEISOC=$((($SIZEISOB/$CYLINDERSBY)+1))
Echo "Size of ISO : ${SIZEISOC} cylinders"

SIZEDEVC=`sfdisk -l -uS ${LS_DEVICE}|grep "Disk /"|awk {'print $3'}` 2>&1
Echo "Size of dev : ${SIZEDEVC} cylinders"

SIZE1=$(($SIZEDEVC-$SIZEISOC-30))
Echo "Size partition 1 : ${SIZE1} cylinders"

SIZE2=$(($SIZE1+1))
#while true
#do
# if [ $((${SIZE1}%4)) != "0" ]
# then
# SIZE1=$((${SIZE1}-1))
# else
# break
# fi
#done
#Echo "Size partition 1 adjust modulo 4 : ${SIZE1} cylinders"

umount ${LS_DEVICE}"1" | exit 0
umount ${LS_DEVICE}"2" | exit 0


Echo "Write partition table"

sfdisk ${LS_DEVICE} << EOF
0,${SIZE1},b
${SIZE2},,83,*
EOF

Echo "Re-read partition table"
partprobe -s

if [[ $FS == true ]]
then
Echo "Making filesystem"

        umount ${LS_DEVICE}1 | exit 0
        umount ${LS_DEVICE}2 | exit 0
        mkfs.vfat -F 32 ${LS_DEVICE}"1"
mkfs.ext2 ${LS_DEVICE}"2" -L "satan"
fi

partprobe -s

echo "############################"
Echo "Start copy of iso"
echo "############################"

TEMPMOUNT="$(mktemp -d -t live-mount.XXXXXXXX)"
TEMPISO="$(mktemp -d -t live-iso.XXXXXXXX)"

if [ -z ${TEMPMOUNT} ]
then
Echo "Error TEMPMOUNT"
exit 0
fi
if [ -z ${TEMPISO} ]
then
Echo "Error TEMPISO"
exit 0
fi

Echo "Making tempdir"

mkdir -p "${TEMPMOUNT}"
mkdir -p "${TEMPISO}"

Echo "Mounting device and binary"
mount -t ext2 ${LS_DEVICE}"2" "${TEMPMOUNT}"
mount -o loop ${LS_BINARY} "${TEMPISO}"

Echo "Copying binary"
cp -a "${TEMPISO}"/* "${TEMPMOUNT}"/

Echo "Installing Grub"
echo "(hd1) ${LS_DEVICE}" > ${TEMPMOUNT}/boot/grub/device.map

Echo "Device map"
cat ${TEMPMOUNT}/boot/grub/device.map

grub-install --root-directory=${TEMPMOUNT} --no-floppy '(hd1)'


Echo "Unmounting device"
umount ${LS_DEVICE}2 | exit 0
umount ${LS_DEVICE}1 | exit 0
umount ${LS_BINARY} |exit 0

Echo "Removing build directory"
rm -rf ${TEMPMOUNT}

if [[ $FS == true ]]
then
Echo "Making filesystem"
        mkfs.vfat -F 32 ${LS_DEVICE}"1"
fi

Echo "Installation terminé"
Something went wrong with that request. Please try again.