root/morphix/trunk/morph-scripts/morphix-chroot.sh

Revision 2, 2.2 kB (checked in by nextime, 2 years ago)

Initial import, branching from morphix svn

  • Property svn:executable set to
Line 
1 #!/bin/bash
2 #
3 # morphix-chroot
4 #
5 # I knocked it up very quickly heck it may even work......
6 #
7 # Copyleft (c) 2006 Brendan M. Sleight                    #
8 #              <bmsleight@barwap._REMOVE_SPAM_TRAP.com>   #
9 #                                                         #
10 # This script is licensed under the GNU GPL v2 or later.  #
11 #                                                         #
12 # On Debian systems, this license can be obtained via     #
13 # /usr/share/common-licenses/GPL                          #
14 #
15
16 get_global_variables ()
17 {
18  TMP_DIR=/tmp/morphix-chroot.$$
19  TMP_FILE=/tmp/morphix-chroot.$$.tmp
20  mkdir -p $TMP_DIR
21  TMP=$(basename "${GRAPHIC}")
22 }
23
24 am_i_root_exit_if_not ()
25 {
26 if [ `id -u` -ne 0 ]; then
27  echo "Need to have be able to run the mount command, i.e. must be root"
28  exit
29 fi
30 }
31
32 full_path ()
33 {
34 BASENAME=$(basename "${1}")
35 DIRNAME=$(cd $(dirname "${1}") && pwd)
36 FULL_PATH="${DIRNAME}/${BASENAME}"
37 }
38
39 cleanup ()
40 {
41 echo "Cleaning up ..."
42 rm $TMP_DIR -R          2>/dev/null
43 rm $TMP_FILE            2>/dev/null
44 }
45
46 extract_mm ()
47 {
48 echo "Extracting the MainModule ..."
49 module-extractor $MAINMODULE $TMP_DIR
50 }
51
52 prepare_chroot ()
53 {
54 echo "Preparing chroot ..."
55 cp /etc/resolv.conf $TMP_DIR/etc/resolv.conf
56 chroot $TMP_DIR/ mount -t proc /proc proc
57
58 }
59
60 chroot_mm ()
61 {
62 clear
63 echo "Entering root of MainModule filesystem. To exit type:-"
64 echo "exit"
65 chroot $TMP_DIR/ sh
66
67 }
68
69 unprepare_chroot ()
70 {
71 chroot $TMP_DIR/ umount -lf /proc
72 }
73
74 build_mm ()
75 {
76 echo "Building the MainModule ..."
77 module-builder $TMP_DIR $MAINMODULE
78 }
79
80
81 #Main loop
82
83 #Confirm parameters
84 if [ -z "$1" ]; then
85     echo "Usage: $0 MainModule.mod"
86     echo
87     echo " This script extracts a MainModule, then drops you into the root of the file system "
88     echo " We can make any changes we need to the MainModule,  it is just like you are running the compressed file system, rather than the current filesystem. "
89     echo " Once finished we re-compresses the MainModule"
90     echo
91     echo " The MainModule must be on a partition that has been mounted with the option dev, (-o dev)" 
92     exit
93 fi
94
95 am_i_root_exit_if_not
96 full_path $1
97 MAINMODULE=$FULL_PATH
98
99 get_global_variables
100 extract_mm
101 prepare_chroot
102 chroot_mm
103 unprepare_chroot
104 build_mm
105
106 cleanup
Note: See TracBrowser for help on using the browser.