2
# Copyright (C) 2000-2006 SWsoft. All rights reserved.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
# This scripts performe postinstall tasks:
20
# 1. Randomizes crontab for given VPS so all crontab tasks
21
# of all VPSs will not start at the same time.
22
# 2. Disables root password if it is empty.
24
# Parameters are passed in environment variables.
25
# Required parameters:
26
# VE_ROOT - root directory of this VPS
27
# Optional parameters:
28
# DIST - name of the distro this VPS runs
30
function randcrontab()
32
FILE=$VE_ROOT"/etc/crontab"
36
vzwarning "No such file $FILE"
40
FILE_TMP=`mktemp $FILE.XXXXXX` || return 1;
45
if ($0 ~ /^[ \t]*#/ || $0 ~ /^[ \t]+*$/) {
49
if ((n = split($0, ar, /[ \t]/)) < 7) {
54
if (ar[1] ~ /^[0-9]+$/) {
56
ar[1] = int(rand() * 59);
59
if (ar[2] ~ /^[0-9]+$/) {
60
ar[2] = int(rand() * 6);
63
if (ar[3] ~ /^[0-9]+$/) {
64
ar[3] = int(rand() * 31) + 1;
67
for (i = 2; i <= n; i++) {
68
line = line " " ar[i];
72
' > $FILE_TMP && cat $FILE_TMP > $FILE
76
function disableroot()
78
FILE=$VE_ROOT"/etc/passwd"
82
vzwarning "No such file $FILE"
86
if grep "^root::" $FILE >/dev/null 2>&1
88
FILE_TMP=`mktemp $FILE.XXXXXX` || return 1;
89
sed 's/^root::/root:!!:/g' < $FILE > $FILE_TMP && cat $FILE_TMP > $FILE
96
FILE=$VE_ROOT"/sbin/ifup"
98
if [ ! -f $FILE ]; then
102
if grep 'if \[ "\${DEVICE}" = "lo" \]; then' $FILE >/dev/null 2>&1; then
103
cp -fp $FILE $FILE.$$
104
/bin/sed -e "s/if \[ "\${DEVICE}" = "lo" \]; then/if \[ "${IPADDR}" = "127.0.0.1" \]; then/" < $FILE > $FILE.$$
105
if [ $? -eq 0 ]; then
106
mv -f ${FILE}.$$ ${FILE}
108
rm -f ${FILE}.$$ 2>/dev/null
113
[ -z "${VE_ROOT}" ] && exit 20