diff options
author | erdgeist <erdgeist@erdgeist.org> | 2012-01-14 07:17:24 +0000 |
---|---|---|
committer | erdgeist <erdgeist@erdgeist.org> | 2012-01-14 07:17:24 +0000 |
commit | 38d54fde17372842f80ba2915ca040c7b956a6bc (patch) | |
tree | c287563ffb961e0a02c3e063a9119ec96d8606d5 | |
parent | 7e51a9b14e7d3c7b3f0672c6ae7c244ef4421547 (diff) |
Tiny script to help import Servers into ezjail
-rw-r--r-- | ezjail-clone.sh | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ezjail-clone.sh b/ezjail-clone.sh new file mode 100644 index 0000000..dc39065 --- /dev/null +++ b/ezjail-clone.sh | |||
@@ -0,0 +1,46 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | ezjail_dirlist="bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/libdata usr/libexec usr/sbin usr/src usr/share usr/lib32" | ||
4 | |||
5 | ezjail_name=`uname -n` | ||
6 | ezjail_safename=`echo -n "${ezjail_name}" | tr -c '[:alnum:]' _` | ||
7 | ezjail_archive_tag="${ezjail_safename}-`date +%Y%m%d%H%M.%S`" | ||
8 | ezjail_archive="${ezjail_archive_tag}.tar.gz" | ||
9 | ezjail_archive_opt="-f `pwd -P`/${ezjail_archive}" | ||
10 | |||
11 | # Create soft links needed in all ezjails | ||
12 | mkdir -p /tmp/ezjail_fakeroot/usr /tmp/ezjail_fakeroot/basejail | ||
13 | for dir in ${ezjail_dirlist}; do | ||
14 | ln -s /basejail/${dir} /tmp/ezjail_fakeroot/${dir} | ||
15 | done | ||
16 | |||
17 | # Construct regex that excludes directories from newjail | ||
18 | # Also excludes the directories themself, they will be added as softlinks | ||
19 | repl="" | ||
20 | for dir in ${ezjail_dirlist}; do | ||
21 | repl="${repl} -s:^./${dir}/.*::p -s:^./${dir}$::p" | ||
22 | done | ||
23 | |||
24 | # Do not want to archive the archive itself | ||
25 | repl="${repl} -s:.*/${ezjail_archive}$::p" | ||
26 | |||
27 | # Must not archive content of /dev and /proc | ||
28 | repl="${repl} -s:^./dev/.*::p -s:^./proc/.*::p" | ||
29 | |||
30 | # Map the softlinks found in our fake root into the jails root | ||
31 | # exclude fakeroot's /usr | ||
32 | repl="${repl} -s:^./tmp/ezjail_fakeroot/usr$::p -s:^./tmp/ezjail_fakeroot/:ezjail/:p" | ||
33 | |||
34 | # Finally re-locate all files under ezjail/ so that the restore command find them | ||
35 | repl="${repl} -s:^\.:ezjail:p" | ||
36 | |||
37 | echo $repl | ||
38 | |||
39 | cd / | ||
40 | pax -wt -x cpio ${ezjail_archive_opt} ${repl} . | ||
41 | ezjail_paxresult=$? | ||
42 | |||
43 | rm -rf /tmp/ezjail_fakeroot/ | ||
44 | |||
45 | #unset LANG LC_CTYPE | ||
46 | #find -dE / ! -regex "/(dev|proc|${ezjail_dirlist})/.*" -a ! -regex "/(${ezjail_dirlist})" -a ! -path /tmp/ezjail_fakeroot/usr -a ! -name "${ezjail_archive}" \ | ||