~ubuntu-branches/ubuntu/karmic/vzctl/karmic

« back to all changes in this revision

Viewing changes to etc/vps-postcreate

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2007-04-10 18:08:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070410180816-0uuzj9fnna7gmzxv
Tags: 3.0.16-4
Etch has been released which means that this version can be uploaded
to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#  Copyright (C) 2000-2006 SWsoft. All rights reserved.
3
 
#
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.
8
 
#
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.
13
 
#
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
17
 
#
18
 
#
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.
23
 
#
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
29
 
 
30
 
function randcrontab()
31
 
{
32
 
FILE=$VE_ROOT"/etc/crontab"
33
 
 
34
 
        if [ ! -f $FILE ]
35
 
        then
36
 
                vzwarning "No such file $FILE"
37
 
                return 1
38
 
        fi
39
 
 
40
 
        FILE_TMP=`mktemp $FILE.XXXXXX` || return 1;
41
 
 
42
 
        cat $FILE | awk '
43
 
BEGIN { srand(); }
44
 
{
45
 
        if ($0 ~ /^[ \t]*#/ || $0 ~ /^[ \t]+*$/) {
46
 
                print $0;
47
 
                next;
48
 
        }
49
 
        if ((n = split($0, ar, /[ \t]/)) < 7) {
50
 
                print $0;
51
 
                next;
52
 
        }
53
 
        # min
54
 
        if (ar[1] ~ /^[0-9]+$/) {
55
 
#               print "->"  $0;
56
 
                ar[1] = int(rand() * 59);
57
 
        }
58
 
        # hour
59
 
        if (ar[2] ~ /^[0-9]+$/) {
60
 
                ar[2] = int(rand() * 6);
61
 
        }
62
 
        # day
63
 
        if (ar[3] ~ /^[0-9]+$/) {
64
 
                ar[3] = int(rand() * 31) + 1;
65
 
        }
66
 
        line = ar[1];
67
 
        for (i = 2; i <= n; i++) {
68
 
                line = line " "  ar[i];
69
 
        }
70
 
        print line;
71
 
72
 
' > $FILE_TMP && cat $FILE_TMP > $FILE
73
 
        rm -f $FILE_TMP
74
 
}
75
 
 
76
 
function disableroot()
77
 
{
78
 
FILE=$VE_ROOT"/etc/passwd"
79
 
 
80
 
        if [ ! -f $FILE ]
81
 
        then
82
 
                vzwarning "No such file $FILE"
83
 
                return 1
84
 
        fi
85
 
 
86
 
        if grep "^root::" $FILE >/dev/null 2>&1
87
 
        then
88
 
                FILE_TMP=`mktemp $FILE.XXXXXX` || return 1;
89
 
                sed 's/^root::/root:!!:/g' < $FILE > $FILE_TMP && cat $FILE_TMP > $FILE
90
 
                rm -f $FILE_TMP
91
 
        fi
92
 
}
93
 
 
94
 
function setupifup()
95
 
{
96
 
        FILE=$VE_ROOT"/sbin/ifup"
97
 
 
98
 
        if [ ! -f $FILE ]; then 
99
 
                return 0
100
 
        fi
101
 
 
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}
107
 
                fi
108
 
                rm -f ${FILE}.$$ 2>/dev/null
109
 
 
110
 
        fi
111
 
}
112
 
 
113
 
[ -z "${VE_ROOT}" ] && exit 20
114
 
 
115
 
randcrontab 
116
 
disableroot
117
 
setupifup
118
 
 
119
 
exit 0
120