-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreebsd_world.subr
102 lines (87 loc) · 3.63 KB
/
freebsd_world.subr
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
if [ ! "$_CBSD_FREEBSD_WORLD_SUBR" ]; then
_CBSD_FREEBSD_WORLD_SUBR=1
###
# test for $customskel variable
# add apply it when directory exist on $data dir
customskel()
{
if [ ! -d "${data}" ]; then
echo "No data dir for customskel"
return 0
fi
if [ -n "${customskel}" ]; then
if [ -d "${customskel}" ]; then
$ECHO "${MAGENTA}Applying custom skel dir template from: ${GREEN}${customskel}${NORMAL}"
cd ${customskel} && /usr/bin/find -E ${customskel} \( -type f -or -type d -or -type l \) -print |/usr/bin/sed s:${customskel}:./:g |/usr/bin/cpio -pdmu ${data} > /dev/null 2>&1
else
${ECHO} "${MAGENTA}customskel dir specified but not found: ${GREEN}${customskel}${NORMAL}"
fi
fi
}
# copy data from base, apply templates
# required: ver, baserw, data, BASE_DIR
# data (or $1) - destination dir
populate_freebsd_world()
{
[ -n "${1}" ] && data="${1}"
[ "${ver}" = "empty" ] && return 0
if [ "${baserw}" = "1" ]; then
#BASE_DIR variable from get_base
if ! populate_cdir ${BASE_DIR} ${data}; then
[ "${mdsize}" != "0" ] && /usr/local/bin/cbsd unmountmd jroot=${data}
err 1 "Can't populate $data from $BASE_DIR"
fi
else
/bin/cp -rP ${BASE_DIR}/boot ${data}/
/bin/cp -rP ${BASE_DIR}/etc ${data}/
/bin/cp -rP ${BASE_DIR}/root ${data}/
[ -f "${BASE_DIR}/etc/mtree/BSD.root.dist" ] && /usr/sbin/mtree -deU -f ${BASE_DIR}/etc/mtree/BSD.root.dist -p ${data} >/dev/null
[ -f "${BASE_DIR}/etc/mtree/BSD.usr.dist" ] && /usr/sbin/mtree -deU -f ${BASE_DIR}/etc/mtree/BSD.usr.dist -p ${data}/usr >/dev/null
[ -f "${BASE_DIR}/etc/mtree/BSD.var.dist" ] && /usr/sbin/mtree -deU -f ${BASE_DIR}/etc/mtree/BSD.var.dist -p ${data}/var >/dev/null
# in FreeBSD10 BIND is go away
if [ -f "${BASE_DIR}/etc/mtree/BIND.chroot.dist" ]; then
[ ! -d "${data}/var/named" ] && mkdir ${data}/var/named
/usr/sbin/mtree -deU -f ${BASE_DIR}/etc/mtree/BIND.chroot.dist -p ${data}/var/named >/dev/null
fi
[ -f "${BASE_DIR}/etc/mtree/BSD.sendmail.dist" ] && /usr/sbin/mtree -deU -f ${BASE_DIR}/etc/mtree/BSD.sendmail.dist -p ${data} >/dev/null
fi
/usr/bin/touch "${data}/etc/fstab"
[ ! -d ${data}/usr/home ] && mkdir ${data}/usr/home
[ ! -d ${data}/usr/local ] && mkdir ${data}/usr/local
[ ! -d ${data}/compat ] && mkdir ${data}/compat
[ ! -d ${data}/usr/ports ] && mkdir ${data}/usr/ports
[ ! -d ${data}/usr/local/etc ] && mkdir -p ${data}/usr/local/etc
if [ ${applytpl} -eq 1 ]; then
/usr/bin/touch ${data}/etc/src.conf
if [ -d "${jailskeldir}" ]; then
${ECHO} "${MAGENTA}Applying skel dir template from: ${GREEN}${jailskeldir}${NORMAL}"
cd ${jailskeldir} && /usr/bin/find -E ${jailskeldir} \( -type f -or -type d -or -type l \) -print |/usr/bin/sed s:${jailskeldir}:./:g |/usr/bin/cpio -pdmu ${data} > /dev/null 2>&1
else
${ECHO} "${MAGENTA}Skel dir template not found: ${GREEN}${jailskeldir}${NORMAL}"
fi
if [ -f ${data}/master.passwd ]; then
/usr/sbin/pwd_mkdb -d ${data}/etc ${data}/etc/master.passwd
fi
[ ! -f "${data}/etc/localtime" -a -f /etc/localtime ] && /bin/cp -a /etc/localtime ${data}/etc
fi
}
# copy data from kernel
# required: ver, baserw, data, KERNEL_DIR
# data (or $1) - destination dir
populate_freebsd_kernel()
{
[ "${ver}" = "empty" ] && return 0
[ -n "${1}" ] && data="${1}"
[ ! -d "${KERNEL_DIR}/boot/kernel" ] && err 1 "No such ${KERNEL_DIR}/boot/kernel"
if [ -d "${data}/boot/kernel" ]; then
# try to remove empty dir. If not empty - rotate
/bin/rmdir ${data}/boot/kernel
if [ -d "${data}/boot/kernel" ]; then
$ECHO "${MAGENTA}Old kernel rotated to: ${GREEN}kernel.old${NORMAL}"
/bin/mv ${data}/boot/kernel ${data}/boot/kernel.old
fi
fi
/bin/cp -a ${KERNEL_DIR}/boot/kernel ${data}/boot
}
###
fi