/
postinst
executable file
·157 lines (142 loc) · 5.64 KB
/
postinst
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
#!/bin/bash
set -e
mkdir -p /var/spool/greyhole
chmod 777 /var/spool/greyhole
/usr/bin/greyhole --create-mem-spool >/dev/null
mkdir -p /var/cache/greyhole-dfree
chmod 777 /var/cache/greyhole-dfree
if [ -d /usr/lib/x86_64-linux-gnu/samba/vfs ]; then
SOURCE_LIBDIR="/usr/lib64" # Makefile will always install Greyhole .so files in /usr/lib64, for x86_64 CPUs. @see Makefile
TARGET_LIBDIR="/usr/lib/x86_64-linux-gnu"
elif [ "`uname -m`" = "x86_64" ]; then
SOURCE_LIBDIR="/usr/lib64"
TARGET_LIBDIR="/usr/lib64"
# For Ubuntu, where even x86_64 install use /usr/lib
if [ -d /usr/lib/samba/vfs/ ]; then
TARGET_LIBDIR="/usr/lib"
fi
else
SOURCE_LIBDIR="/usr/lib"
TARGET_LIBDIR="/usr/lib"
fi
if [ ! -d ${TARGET_LIBDIR}/samba/vfs/ ]; then
# Maybe samba-vfs-modules is missing?
if [ -d /usr/lib/x86_64-linux-gnu ]; then
SOURCE_LIBDIR="/usr/lib64" # Makefile will always install Greyhole .so files in /usr/lib64, for x86_64 CPUs. @see Makefile
TARGET_LIBDIR="/usr/lib/x86_64-linux-gnu"
else
SOURCE_LIBDIR="/usr/lib"
TARGET_LIBDIR="/usr/lib"
fi
fi
if [ ! -d ${TARGET_LIBDIR}/samba/vfs/ ]; then
mkdir ${TARGET_LIBDIR}/samba/vfs/
fi
TARGET_SYMLINK="${TARGET_LIBDIR}/samba/vfs/greyhole.so"
SMB_VERSION="`smbd --version | awk '{print $2}' | awk -F'-' '{print $1}' | awk -F'.' '{print $1,$2}'`"
if [ "${SMB_VERSION}" = "3 4" ]; then
LIB_FILE="greyhole-samba34.so"
elif [ "${SMB_VERSION}" = "3 5" ]; then
LIB_FILE="greyhole-samba35.so"
elif [ "${SMB_VERSION}" = "3 6" ]; then
LIB_FILE="greyhole-samba36.so"
elif [ "${SMB_VERSION}" = "4 0" ]; then
LIB_FILE="greyhole-samba40.so"
elif [ "${SMB_VERSION}" = "4 1" ]; then
LIB_FILE="greyhole-samba41.so"
elif [ "${SMB_VERSION}" = "4 2" ]; then
LIB_FILE="greyhole-samba42.so"
elif [ "${SMB_VERSION}" = "4 3" ]; then
LIB_FILE="greyhole-samba43.so"
elif [ "${SMB_VERSION}" = "4 4" ]; then
LIB_FILE="greyhole-samba44.so"
else
echo "Warning: Greyhole doesn't include a VFS module for your version of Samba (${SMB_VERSION})."
echo "We will try to use the VFS for Samba 4.4, but that might not work."
LIB_FILE="greyhole-samba44.so"
fi
SOURCE_LIB="${SOURCE_LIBDIR}/greyhole/${LIB_FILE}"
rm -f ${TARGET_SYMLINK}
ln -s ${SOURCE_LIB} ${TARGET_SYMLINK}
# Bugfix for Ubuntu / Debian that are missing symlinks in ${TARGET_LIBDIR}/samba/
MAJOR_SMB_VERSION="`smbd --version | awk '{print $2}' | awk -F'-' '{print $1}' | awk -F'.' '{print $1}'`"
if [ "${MAJOR_SMB_VERSION}" = "4" ]; then
if [ -f ${TARGET_LIBDIR}/samba/libsmbd_base.so.0 ]; then
if [ ! -f ${TARGET_LIBDIR}/samba/libsmbd_base.so ]; then
ln -s ${TARGET_LIBDIR}/samba/libsmbd_base.so.0 ${TARGET_LIBDIR}/samba/libsmbd_base.so
fi
else
if [ ! -f ${TARGET_LIBDIR}/samba/libsmbd-base-samba4.so ]; then
if [ -f ${TARGET_LIBDIR}/samba/libsmbd-base.so.0 ]; then
ln -s ${TARGET_LIBDIR}/samba/libsmbd-base.so.0 ${TARGET_LIBDIR}/samba/libsmbd-base-samba4.so
else
echo "Error: missing dependent library libsmbd-base.so.0 (libsmbd-base-samba4.so)"
exit -1
fi
fi
if [ ! -f ${TARGET_LIBDIR}/samba/libsamba-debug-samba4.so ]; then
if [ -f ${TARGET_LIBDIR}/samba/libsamba-debug.so.0 ]; then
ln -s ${TARGET_LIBDIR}/samba/libsamba-debug.so.0 ${TARGET_LIBDIR}/samba/libsamba-debug-samba4.so
elif [ -f ${TARGET_LIBDIR}/libsamba-util.so.0 ]; then
ln -s ${TARGET_LIBDIR}/libsamba-util.so.0 ${TARGET_LIBDIR}/samba/libsamba-debug-samba4.so
else
echo "Error: missing dependent library libsamba-debug.so.0 (libsamba-debug-samba4.so)"
exit -1
fi
fi
fi
fi
if [ -f /proc/fs/cifs/OplockEnabled ]; then
# cifs client workaround
# Ref: http://blog.dhampir.no/content/cifs-vfs-no-response-for-cmd-n-mid
modprobe cifs
echo 0 > /proc/fs/cifs/OplockEnabled
fi
if [ -f /sys/module/cifs/parameters/enable_oplocks ]; then
# cifs client workaround
# Ref: http://blog.dhampir.no/content/cifs-vfs-no-response-for-cmd-n-mid
modprobe cifs enable_oplocks=0
echo 0 > /sys/module/cifs/parameters/enable_oplocks
fi
uses_systemd=`stat -c '%N' /proc/1/exe | grep systemd | wc -l`
running=0
if [ -f /sbin/start -a $uses_systemd -eq 0 ]; then
# Using Upstart instead of SYSV init.d
rm -f /etc/init.d/greyhole
if [ -f /etc/init/greyhole.conf ]; then
if [ "`status greyhole | grep running | wc -l`" = "1" ]; then
restart greyhole
running=1
fi
fi
else
# (SYSV) Service install & start
rm -f /etc/init/greyhole.conf
if [ -f /etc/init.d/mysql ]; then
sed -i 's/mysqld/mysql/' /etc/init.d/greyhole
fi
if [ -f /etc/init.d/smbd ]; then
sed -i 's/smb$/smbd/' /etc/init.d/greyhole
elif [ -f /etc/init.d/samba ]; then
sed -i 's/smb/samba/' /etc/init.d/greyhole
fi
if [ -f /sbin/chkconfig ]; then
/sbin/chkconfig --add greyhole
/sbin/chkconfig greyhole on
else
/usr/sbin/update-rc.d greyhole defaults
fi
if [ -f /etc/init.d/greyhole ]; then
if [ "`service greyhole stat 2> /dev/null | grep 'is running' | wc -l`" = "1" ]; then
service greyhole restart
running=1
fi
fi
fi
if [ $running -eq 0 ]; then
echo "==========================================================================="
echo "See /usr/share/greyhole/USAGE to learn how to configure and start Greyhole."
echo "==========================================================================="
fi
man logrotate > /dev/null 2>&1 || echo "Warning! logrotate is not installed. You should install logrotate to make sure the Greyhole logs don't fill your root partition.
Greyhole already installed the necessary conf file for logrotate; simply installing the logrotate package is enough."