forked from gamvrosi/duet-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·165 lines (135 loc) · 3.65 KB
/
setup.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
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
160
161
162
163
164
#!/bin/bash
# Find location of this setup.sh
STARTDIR="$(pwd)"
cd "$(dirname "$0")"
BASEDIR="$(pwd)"
cd "${STARTDIR}"
usage() {
echo "Usage: $0 [OPTION]...
-d Install Ubuntu dependencies
-c Configure Duet kernel
-k Compile Duet kernel
-g Compile Duet kernel with debug symbols
-m Compile Duet module
-t Compile Duet library and tools
-K Install Duet kernel
-M Install Duet module
-T Install Duet tools
-u Uninstall all but latest Duet kernel, and clean up deb packages
"
}
die() {
echo "Aborting..." >&2
exit 1
}
cd "${BASEDIR}/duet-kernel"
KERNEL_VERSION_APPEND="+duet-$(git rev-parse --short HEAD)"
cd "${STARTDIR}"
while getopts ":dckgmtKMTu" opt; do
case $opt in
d)
echo "Installing Ubuntu dependencies..."
# Check that we're running on Ubuntu
if [[ ! `grep "DISTRIB_ID=Ubuntu" /etc/lsb-release` ]]; then
echo "I only know the dependencies for Ubuntu. Sorry." >&2
die
fi
# Install kernel dependencies
sudo apt-get install build-essential kernel-package libssl-dev \
libncurses5-dev libpopt-dev
echo "Done processing Ubuntu dependencies."
exit 0
;;
c)
cd "${BASEDIR}/duet-kernel"
rm .config
touch .scmversion
make localmodconfig || die
cat .config | sed 's/# CONFIG_DUET is not set/CONFIG_DUET=y/g' | \
sed 's/CONFIG_X86_X32=y/CONFIG_X86_X32=n/g' | \
sed 's/CONFIG_CC_STACKPROTECTOR_STRONG=y/CONFIG_CC_STACKPROTECTOR_STRONG=n/g' > .config-new
mv .config-new .config
exit 0
;;
[kg])
cd "${BASEDIR}"
KDBG=`test $opt == 'g' && echo kernel_debug`
# Prep the environment
export CLEAN_SOURCE=no
export CONCURRENCY_LEVEL="$(expr `nproc` + 1)"
echo CLEAN_SOURCE=$CLEAN_SOURCE
echo CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL
# (re)compile the kernel
cd "${BASEDIR}/duet-kernel"
# XXX: Remove when make-kpkg stops expecting REPORTING-BUGS to be there
touch REPORTING-BUGS
time fakeroot make-kpkg --initrd --append-to-version="${KERNEL_VERSION_APPEND}" \
kernel_image kernel_headers $KDBG || die
echo "Done compiling Duet kernel."
exit 0
;;
m)
cd "${BASEDIR}/duet-module"
# (re)compile the duet module
moddir="`ls -l /lib/modules | grep ${KERNEL_VERSION_APPEND} | \
awk '{print $9}' | head -1`"
make -C /lib/modules/${moddir}/build M=$(pwd) modules
echo "Done compiling Duet module."
exit 0
;;
t)
cd "${BASEDIR}"
# (re)compile the duet tools
cd duet-progs
make || die
locate libduet | grep /usr/local/lib > /dev/null
if [[ $? == 1 ]]; then
sudo make install
fi
# (re)compile the dummy task
cd ../dummy_task
make || die
exit 0
;;
K)
# Install the kernel
sudo dpkg -i "${BASEDIR}"/linux-headers-*"${KERNEL_VERSION_APPEND}"*.deb || die
sudo dpkg -i "${BASEDIR}"/linux-image-*"${KERNEL_VERSION_APPEND}"*.deb || die
exit 0
;;
M)
cd "${BASEDIR}/duet-module"
# Install the module
moddir="`ls -l /lib/modules | grep ${KERNEL_VERSION_APPEND} | \
awk '{print $9}' | head -1`"
sudo make -C /lib/modules/${moddir}/build M=$(pwd) modules_install
#sudo depmod
#sudo modprobe duet
echo "Done installing Duet module."
exit 0
;;
T)
cd "${BASEDIR}"
# Install the duet tools (in /usr/local/bin)
cd duet-progs
sudo make install || die
exit 0
;;
u)
# Get installed packages for all but latest Duet kernel
DPKGS="`dpkg --get-selections | grep -E 'linux-.*+duet' | \
cut -f1 | grep -v $KERNEL_VERSION_APPEND | tr '\n' ' '`"
sudo dpkg -P $DPKGS || die
# Get .deb packages in BASEDIR of all but latest Duet kernel
cd "${BASEDIR}"
ls | grep -E 'linux-.*.deb' | grep -v $KERNEL_VERSION_APPEND | \
tr '\n' ' ' | xargs rm -v || die
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage && die
;;
esac
done
usage && die