-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.sh
More file actions
160 lines (140 loc) · 2.86 KB
/
utils.sh
File metadata and controls
160 lines (140 loc) · 2.86 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
mount_partition()
{
SIZE=$(echo $(/sbin/sfdisk -l -u S $1 | grep $2) | cut -d ' ' -f 4)
START=$(echo $(/sbin/sfdisk -l -u S $1 | grep $2) | cut -d ' ' -f 2)
echo Size: $SIZE
echo Start: $START
START=$((START*512))
SIZE=$((SIZE*512))
sudo /sbin/losetup -o $START /dev/loop0 $1
sudo mount /dev/loop0 $3
}
umount_partition() {
set +e # umount can fail due to some daemons doing stupid things with loopback devices
until sudo umount $1
do
echo UMount returned $?
sleep 1
done
set -e
sleep 1
sudo /sbin/losetup -d /dev/loop0
}
format_partition() {
echo Formatting partition $2 on $1
echo Getting partition information...
SIZE=$(echo $(/sbin/sfdisk -l -u S $1 | grep img$2) | cut -d ' ' -f 4)
START=$(echo $(/sbin/sfdisk -l -u S $1 | grep img$2) | cut -d ' ' -f 2)
echo Size: $SIZE
echo Start: $START
START=$((START*512))
SIZE=$((SIZE*512))
echo Creating a FS on the partition...
sudo /sbin/losetup --offset $START --sizelimit $SIZE /dev/loop0 $1
sudo /sbin/mkfs.ext3 /dev/loop0
sudo /sbin/losetup -d /dev/loop0
}
get_cpus() {
echo $(grep processor /proc/cpuinfo | wc -l)
}
get_j() {
C=$(get_cpus)
if [ $C -ne 1 ]
then
C=$((C-1))
fi
echo $C
}
get_exec_libs() {
LIBS=$(ldd $1 | cut -f 2 | cut -d ' ' -f 3)
for L in $LIBS
do
cp $L $2
done
}
extract_initramfs() {
echo Extract $1 $2
HERE=$PWD
sudo rm -rf $2
mkdir $2
cd $2
zcat $1 | sudo cpio -i
cd $HERE
}
mk_initramfs() {
echo MkInitRAMFs $1 $2
HERE=$PWD
cd $1
sudo find . | sudo cpio -o -H newc | gzip > $2
cd $HERE
}
update_initramfs()
{
extract_initramfs $1 $2/tmproot
sudo rm -rf $2/tmproot/lib/modules/*
sudo mkdir -p $2/tmproot/lib/modules
sudo cp -r $2/lib/modules/* $2/tmproot/lib/modules
mk_initramfs $2/tmproot $3/core.gz
}
get_kernel() {
if test -e $1;
then
echo $1 already exists
else
if test -e $1.tar.bz2;
then
echo $1.tar.bz2 already exists
else
wget http://www.kernel.org/pub/linux/kernel/v3.0/$1.tar.bz2
fi
tar xvjf $1.tar.bz2
fi
}
build_kernel() {
BUILDDIR=$4
mkdir -p $BUILDDIR
cd $BUILDDIR
cp $2 .config
make -C $(pwd)/../$1 O=$(pwd) oldconfig
make -j $3
cd ..
}
install_kernel() {
BUILDDIR=$2
cd $BUILDDIR
make INSTALL_MOD_PATH=$1 modules_install
cp arch/x86/boot/bzImage $1
cd ..
}
patch_source()
{
PATCHES=$(ls $1)
TMP=$(pwd)
if test -e $2/.patched;
then
echo $2 is already patched
else
cd $2
touch .patched
for p in $PATCHES
do
ls $1/$p
patch -p1 < $1/$p
done
cd $TMP
fi
}
make_kernel() {
DIR=linux-$KVER
INSTALL_DIR=$1
CONFIG_FILE=$2
BUILDDIR=$3
PATCH_DIR=$4
get_kernel $DIR
if [ x$PATCH_DIR != x ];
then
patch_source $PATCH_DIR linux-$KVER
fi
build_kernel $DIR $CONFIG_FILE $CPUS $BUILDDIR
install_kernel $INSTALL_DIR $BUILDDIR
}