]> git.mxchange.org Git - secure-linux-project.git/blob - encrypt/cpio.sh
Initial import from 0.5a version.
[secure-linux-project.git] / encrypt / cpio.sh
1 #!/bin/sh
2 ##############################################
3 # Script for Secure Linux Project            #
4 # Copyright(c) 2005, 2006 by Roland Haeder   #
5 ##############################################
6 # Purpose: Copys choosen directories/files   #
7 #          to the asset                      #
8 ##############################################
9 # This software is licensed under the GNU    #
10 # General Public License Version 2 or either #
11 # and comes with ABSOLUTELY NO WARRANTY      #
12 # neither implied nor explicit.              #
13 ##############################################
14
15 . ./.settings.sh || exit 3
16
17 cd /
18 #find bin dev etc home lib mnt opt root sbin sys tmp usr var -print0 | \
19 if test "$FORCE_CPIO" != "1"; then
20         # Check size of given targets
21         ALL_TOTAL="0"
22         for target in $CPIO_FILES; do
23                 TOTAL="0"
24                 if test -d "$target"; then
25                         # Directory
26                         if test "$VERBOSE" == "-v"; then
27                                 echo "$0: $target is a directory."
28                         fi
29                         sh $BASEDIR/sizes.sh $target
30                 elif test -f "$target"; then
31                         # File
32                         TOTAL=`stat --format="%s" $target`
33                         if test "$VERBOSE" == "-v"; then
34                                 echo "$0: $target is $TOTAL Bytes large."
35                         fi
36                 else
37                         # Something else is not counted
38                         if test "$VERBOSE" == "-v"; then
39                                 echo "$0: $target is no file/directory -> 0 Bytes forced."
40                         fi
41                 fi
42                 ALL_TOTAL="$(($ALL_TOTAL + $TOTAL))"
43         done
44         echo
45         # Size for below if command
46         CHECK="$((ALL_TOTAL/1024))"
47
48         # Begin looking for right unit (GB/MB/kB/Bytes)
49         UNIT="GByte"
50         SIZE="$((ALL_TOTAL/1024/1024/1024))"
51         if test "$SIZE" == "0"; then
52                 UNIT="MByte"
53                 SIZE="$((ALL_TOTAL/1024/1024))"
54                 if test "$SIZE" == "0"; then
55                         UNIT="kByte"
56                         SIZE="$((ALL_TOTAL/1024))"
57                         if test "$SIZE" == "0"; then
58                                 UNIT="Bytes"
59                                 SIZE="$ALL_TOTAL"
60                         fi
61                 fi
62         fi
63
64         echo -n "$0: Total size: $SIZE $UNIT -> "
65         if test $SIZE_ROOT -gt $CHECK; then
66                 echo "okay"
67         else
68                 echo "warning!"
69         fi
70         echo
71         echo "$0: Press RETURN if this is also okay for you."
72         read dummy
73 else
74         # Do not check sizes of targets in CPIO_FILES
75         echo "$0: Warning: Will copy targets in CPIO_FILES regardless if you have"
76         echo "$0: enough space on $BASEDIR/root/!"
77         echo
78         echo "Press RETURN to begin copy process or CTRL+C to abort..."
79         read dummy
80 fi
81
82
83 # Shall I copy files?
84 if test "$CPIO_FILES" != ""; then
85         TEST=`grep "$BASEDIR" $CPIO_FILES` 
86         if test "$TEST" != ""; then
87                 echo "$0: Found my own path $BASEDIR in CPIO_FILES! Aborting..."
88                 exit 6
89         fi
90
91         find $CPIO_FILES -print0 | \
92                 cpio --pass-through --make-directories --null --reset-access-time \
93                 --make-directories --preserve-modification-time --verbose $BASEDIR/root/
94
95         # Do some extra sync
96         sync
97 fi
98
99 # Create additional directories
100 mkdir $VERBOSE $BASEDIR/root/{boot,cdrom,floppy,proc}
101
102 echo "$0: When no error ('no space left on device' may"
103 echo "$0: occur on testing images) then please continue"
104 echo "$0: with stick.sh to setup your USB stick(s)!"