File: vps-create.in

package info (click to toggle)
vzctl 3.0.22-14
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,340 kB
  • ctags: 4,462
  • sloc: ansic: 15,696; sh: 11,712; makefile: 460
file content (58 lines) | stat: -rwxr-xr-x 2,232 bytes parent folder | download
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
#!/bin/sh
#  Copyright (C) 2000-2007 SWsoft. All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# This script should create VE private area
# For usage info see vz-create_prvt(5) man page.
#
# Parameters are passed in environment variables.
# Required parameters:
#   VE_PRVT		- path to root of VE private areas
#   PRIVATE_TEMPLATE	- path to private template used as a source for copying

. @PKGLIBDIR@/scripts/vps-functions

vzcheckvar VE_PRVT PRIVATE_TEMPLATE

create_prvt()
{
	local TMP AVAIL NEEDED HEADER OPT

	[ -d "$VE_PRVT" ] ||
		vzerror "Destination directory does not exist: $VE_PRVT" ${VZ_FS_NEW_VE_PRVT}
	[ -f "$PRIVATE_TEMPLATE" ] ||
		vzerror "Tarball does not exist: $PRIVATE_TEMPLATE" ${VZ_FS_NEW_VE_PRVT}
	HEADER="$(od -A n -N 2 -t x1 -- "$PRIVATE_TEMPLATE")" ||
		vzerror "Invalid tarball: $PRIVATE_TEMPLATE" ${VZ_FS_NEW_VE_PRVT}
	TMP="$(df -P "$VE_PRVT")" ||
		vzerror "Failed to calculate available disk space on $VE_PRVT" ${VZ_FS_NEW_VE_PRVT}
	AVAIL="$(echo "$TMP" | awk 'END{print $4}')"
	if [ "$HEADER" = ' 1f 8b' ]; then
		NEEDED="$(gzip -l "$PRIVATE_TEMPLATE" | awk 'END{print int($2/1024)}')"
		OPT=-z
	else
		NEEDED="$(find "$PRIVATE_TEMPLATE" -maxdepth 0 -path "$PRIVATE_TEMPLATE" -printf %k)"
		OPT=
	fi
	[ "$AVAIL" -ge "$NEEDED" ] ||
		vzerror "Insufficient disk space in $VE_PRVT; available: $AVAIL, needed: $NEEDED" ${VZ_FS_NO_DISK_SPACE}
	tar -C "$VE_PRVT" ${TAR_OPT} ${OPT} -xf "$PRIVATE_TEMPLATE" ||
		vzerror "Error in tar ${TAR_OPT} ${OPT} -xf $PRIVATE_TEMPLATE" ${VZ_FS_NEW_VE_PRVT}
}

create_prvt
exit 0