-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreebsd_world.subr
103 lines (87 loc) · 3.61 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
103
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 "${N1_COLOR}Applying custom skel dir template from: ${N2_COLOR}${customskel}${N0_COLOR}"
cd ${customskel} && ${FIND_CMD} -E ${customskel} \( -type f -or -type d -or -type l \) -print | ${SED_CMD} s:${customskel}:./:g | ${CPIO_CMD} -pdmu ${data} > /dev/null 2>&1
else
${ECHO} "${N1_COLOR}customskel dir specified but not found: ${N2_COLOR}${customskel}${N0_COLOR}"
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
${CP_CMD} -rP ${BASE_DIR}/boot ${data}/
${CP_CMD} -rP ${BASE_DIR}/etc ${data}/
${CP_CMD} -rP ${BASE_DIR}/root ${data}/
[ -f "${BASE_DIR}/etc/mtree/BSD.root.dist" ] && ${MTREE_CMD} -deU -f ${BASE_DIR}/etc/mtree/BSD.root.dist -p ${data} >/dev/null
[ -f "${BASE_DIR}/etc/mtree/BSD.usr.dist" ] && ${MTREE_CMD} -deU -f ${BASE_DIR}/etc/mtree/BSD.usr.dist -p ${data}/usr >/dev/null
[ -f "${BASE_DIR}/etc/mtree/BSD.var.dist" ] && ${MTREE_CMD} -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
${MTREE_CMD} -deU -f ${BASE_DIR}/etc/mtree/BIND.chroot.dist -p ${data}/var/named >/dev/null
fi
[ -f "${BASE_DIR}/etc/mtree/BSD.sendmail.dist" ] && ${MTREE_CMD} -deU -f ${BASE_DIR}/etc/mtree/BSD.sendmail.dist -p ${data} >/dev/null
fi
${TOUCH_CMD} "${data}/etc/fstab"
for i in ${data}/usr/home ${data}/usr/local ${data}/compat ${data}/usr/ports ${data}/usr/local/etc; do
[ ! -d ${i} ] && ${MKDIR_CMD} -m 0755 -p ${i}
done
if [ ${applytpl} -eq 1 ]; then
${TOUCH_CMD} ${data}/etc/src.conf
if [ -d "${jailskeldir}" ]; then
[ "${quiet}" != "1" ] && ${ECHO} "${N1_COLOR}Applying skel dir template from: ${N2_COLOR}${jailskeldir}${N0_COLOR}"
cd ${jailskeldir} && ${FIND_CMD} -E ${jailskeldir} \( -type f -or -type d -or -type l \) -print | ${SED_CMD} s:${jailskeldir}:./:g | ${CPIO_CMD} -pdmu ${data} > /dev/null 2>&1
else
${ECHO} "${N1_COLOR}Skel dir template not found: ${N2_COLOR}${jailskeldir}${N0_COLOR}"
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 ] && ${CP_CMD} -a /etc/localtime ${data}/etc
fi
# always set root:wheel
${CHOWN_CMD} root:wheel ${data}
}
# 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
${RMDIR_CMD} ${data}/boot/kernel
if [ -d "${data}/boot/kernel" ]; then
$ECHO "${N1_COLOR}Old kernel rotated to: ${N2_COLOR}kernel.old${N0_COLOR}"
${MV_CMD} ${data}/boot/kernel ${data}/boot/kernel.old
fi
fi
${CP_CMD} -a ${KERNEL_DIR}/boot/kernel ${data}/boot
}
###
fi