forked from cifsd-team/ksmbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_ksmbd.sh
executable file
·177 lines (149 loc) · 3.18 KB
/
build_ksmbd.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
165
166
167
168
169
170
171
172
173
174
175
176
177
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright (C) 2019 Samsung Electronics Co., Ltd.
#
#!/bin/sh
KERNEL_SRC=''
COMP_FLAGS=''
function is_module
{
local ok=$(cat "$KERNEL_SRC"/.config | grep "CONFIG_SMB_SERVER=m")
if [ "z$ok" == "z" ]; then
echo "1"
return 1
fi
echo "0"
return 0
}
function patch_fs_config
{
local ok=$(pwd | grep -c "fs/smbd")
if [ "z$ok" != "z1" ]; then
echo "ERROR: please ``cd`` to fs/smbd"
exit 1
fi
KERNEL_SRC=$(pwd | sed -e 's/fs\/smbd//')
if [ ! -f "$KERNEL_SRC"/fs/Kconfig ]; then
echo "ERROR: please ``cd`` to fs/smbd"
exit 1
fi
ok=$(cat "$KERNEL_SRC"/fs/Makefile | grep smbd)
if [ "z$ok" == "z" ]; then
echo 'obj-$(CONFIG_SMB_SERVER) += smbd/' \
>> "$KERNEL_SRC"/fs/Makefile
fi
ok=$(cat "$KERNEL_SRC"/fs/Kconfig | grep smbd)
if [ "z$ok" == "z" ]; then
ok=$(cat "$KERNEL_SRC"/fs/Kconfig \
| sed -e 's/fs\/cifs\/Kconfig/fs\/cifs\/Kconfig\"\nsource \"fs\/smbd\/Kconfig/' \
> "$KERNEL_SRC"/fs/Kconfig.new)
if [ $? != 0 ]; then
exit 1
fi
mv "$KERNEL_SRC"/fs/Kconfig.new "$KERNEL_SRC"/fs/Kconfig
fi
ok=$(cat "$KERNEL_SRC"/.config | grep "CONFIG_NETWORK_FILESYSTEMS=y")
if [ "z$ok" == "z" ]; then
ok=$(echo "CONFIG_NETWORK_FILESYSTEMS=y" \
>> "$KERNEL_SRC"/.config)
if [ $? != 0 ]; then
exit 1
fi
fi
ok=$(is_module)
if [ "z$ok" == "z1" ]; then
ok=$(echo "CONFIG_SMB_SERVER=m" >> "$KERNEL_SRC"/.config)
if [ $? != 0 ]; then
exit 1
fi
ok=$(echo "CONFIG_SMB_INSECURE_SERVER=y" \
>> "$KERNEL_SRC"/.config)
if [ $? != 0 ]; then
exit 1
fi
fi
}
function ksmbd_module_make
{
echo "Running smbd make"
local c="make "$COMP_FLAGS" -C "$KERNEL_SRC" M="$KERNEL_SRC"/fs/smbd"
rm smbd.ko
cd "$KERNEL_SRC"
echo $c
$c
cd "$KERNEL_SRC"/fs/smbd
if [ $? != 0 ]; then
exit 1
fi
}
function ksmbd_module_install
{
echo "Running smbd install"
local ok=$(lsmod | grep -c smbd)
if [ "z$ok" == "z1" ]; then
sudo rmmod smbd
if [ $? -ne 0 ]; then
echo "ERROR: unable to rmmod smbd"
exit 1
fi
fi
ok=$(is_module)
if [ "z$ok" == "z1" ]; then
echo "It doesn't look like SMB_SERVER is as a kernel module"
exit 1
fi
if [ ! -f "$KERNEL_SRC"/fs/smbd/smbd.ko ]; then
echo "ERROR: smbd.ko was not found"
exit 1
fi
cd "$KERNEL_SRC"
if [ -f "/lib/modules/$(uname -r)/kernel/fs/smbd/smbd.ko*" ]; then
sudo rm /lib/modules/$(uname -r)/kernel/fs/smbd/smbd.ko*
sudo cp "$KERNEL_SRC"/fs/smbd/smbd.ko \
/lib/modules/$(uname -r)/kernel/fs/smbd/smbd.ko
local VER=$(make kernelrelease)
sudo depmod -A $VER
else
sudo make -C "$KERNEL_SRC" M="$KERNEL_SRC"/fs/smbd/ \
modules_install
local VER=$(make kernelrelease)
sudo depmod -A $VER
fi
cd "$KERNEL_SRC"/fs/smbd
}
function ksmbd_module_clean
{
echo "Running smbd clean"
cd "$KERNEL_SRC"
make -C "$KERNEL_SRC" M="$KERNEL_SRC"/fs/smbd/ clean
cd "$KERNEL_SRC"/fs/smbd
}
function main
{
patch_fs_config
COMP_FLAGS="$FLAGS"
case $1 in
clean)
ksmbd_module_clean
exit 0
;;
install)
ksmbd_module_make
ksmbd_module_install
exit 0
;;
make)
ksmbd_module_make
exit 0
;;
help)
echo "Usage: build_ksmbd.sh [clean | make | install]"
exit 0
;;
*)
ksmbd_module_make
exit 0
;;
esac
}
main $1