-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuniso.sh
112 lines (94 loc) · 3.36 KB
/
uniso.sh
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
#!/bin/sh
set -e
if [ "$USER" != "root" ] ; then
echo "error: you are not run as root user, you should excute sudo."
exit -1
fi
if [ $# -lt 2 ] ; then
echo You should execute this script with two param at least as follow:
echo sh $0 ISOPATH OUTPATH
exit -1
fi
if [ ! -f $1 ] ; then
echo You should make sure the iso $1 is a file that exists
exit -1
fi
if [ -e $2 ] ; then
if [ ! -d $2 ] ; then
echo You should make sure the outpath $2 is a dir
exit -1
fi
else
mkdir $2
fi
SQUASHFS=$1
OUTPATH=$(cd $2; pwd)
SCRIPTPATH=$(cd "$(dirname $0)"; pwd)
. $SCRIPTPATH/set_version.sh
echo $SQUASHFS | grep -E "\.iso$" >/dev/null && ISISO=1 || ISISO=0
echo $SQUASHFS | grep -E "\.squashfs$" >/dev/null && ISSQUASHFS=1 || ISSQUASHFS=0
if [ $ISISO -eq 1 ] ; then
#=========================
#uniso begin
echo uniso.sh will export iso $ISOPATH file to $OUTPATH, the dir tree like this:
echo +out
echo \|---$OSNAME--------------- The files contained in iso.
echo \\---squashfs-root-------- The files contained in iso/casper/filesystem.squashfs
if [ ! -d $OUTPATH/$OSNAME ] ; then
mkdir $OUTPATH/$OSNAME
if [ ! -e mintiso ] ; then
echo mount iso to $OUTPATH/mintiso
mkdir $OUTPATH/mintiso
mount -o loop $SQUASHFS $OUTPATH/mintiso
else
echo warning:mintiso has exist, it is expected iso has been mounted normally.
fi
echo copy iso/casper to $OSNAME, just wait for some minutes.
mkdir $OUTPATH/$OSNAME/casper
cp $OUTPATH/mintiso/casper/initrd.lz $OUTPATH/$OSNAME/casper/
cp $OUTPATH/mintiso/casper/vmlinuz $OUTPATH/$OSNAME/casper/
cd $OUTPATH
if [ ! -e squashfs-root ] ; then
echo unsquashfs $OSNAME/casper/filesystem.squashfs
echo just wait for some minutes.
unsquashfs $OUTPATH/mintiso/casper/filesystem.squashfs
else
echo warning:squashfs-root has exist, it is expected filesystem.squashfs has been executed unsquashfs normally.
fi
umount $OUTPATH/mintiso
rmdir $OUTPATH/mintiso
else
echo warning:$OSNAME has exist, it is expected iso/* has been copied to $OSNAME dir.
fi
#uniso end
#=========================
elif [ $ISSQUASHFS -eq 1 ] ; then
#=========================
#unsquashfs begin
echo uniso.sh will export iso $SQUASHFS file to $OUTPATH, the dir tree like this:
echo +out
echo \\---squashfs-root-------- The files contained in filesystem.squashfs
if [ ! -d $OUTPATH/$OSNAME ] ; then
mkdir $OUTPATH/$OSNAME
mkdir $OUTPATH/$OSNAME/casper
cd $OUTPATH
if [ ! -e squashfs-root ] ; then
echo unsquashfs $OSNAME/casper/filesystem.squashfs
echo just wait for some minutes.
unsquashfs $SQUASHFS
else
echo warning:squashfs-root has exist, it is expected filesystem.squashfs has been executed unsquashfs normally.
fi
else
echo warning:$OSNAME has exist, it is expected squashfs file has been unsquashfsed to $OSNAME dir.
fi
#wangyu:Copy vmlinuz and initrd.lz to casper, to make sure user can excute mkiso without customization.
sudo cp $OUTPATH/squashfs-root/boot/vmlinuz-3.8.0-19-generic $OUTPATH/$OSNAME/casper/vmlinuz
sudo cp $OUTPATH/squashfs-root/boot/initrd.img-3.8.0-19-generic $OUTPATH/$OSNAME/casper/initrd.lz
#unsquashfs end
#=========================
else
echo ERROR: this file $ISOPATH can not be supported for not iso or squashfs file.
exit -1
fi
echo uniso has finished.