cookutils view lib/libmodular.sh @ rev 539
libmodular.sh: Add _mksquash function.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Sun Sep 23 11:12:02 2012 +0000 (2012-09-23) |
parents | ce37279097b8 |
children | 2b093f098fe2 |
line source
1 #!/bin/sh
4 INIT=$ROOTFS/init
5 FLAVOR_MOD="justx gtkonly core"
6 UNION=$ROOTFS/union
7 LASTBR=$INIT
8 MODULES_DIR=$ROOTFS/modules
9 CDNAME="slitaz"
10 SGNFILE=$ROOTCD/${CDNAME}/livecd.sgn
11 KEY_FILES="init liblinuxlive linuxrc"
12 EXT="xz"
13 COMPRESSION="xz -Xbcj x86"
14 MKOPTION="-b 512k"
15 #NCPU="-processors 3"
17 error () { echo -e "\033[1;31;40m!!! \033[1;37;40m$@\033[1;0m"; }
18 warn () { echo -e "\033[1;33;40m*** \033[1;37;40m$@\033[1;0m"; }
19 info () { echo -e "\033[1;32;40m>>> \033[1;37;40m$@\033[1;0m"; }
21 initramfs () {
23 FLAVOR=${1%.flavor}
24 if [ ! -f "$FLAVORS_REPOSITORY/$FLAVOR/receipt" ]; then
25 error "error: $FLAVORS_REPOSITORY/$FLAVOR/receipt doesn't exist, aborting."
26 exit 1
27 fi
29 if [ -d ${INIT} ]; then
30 rm -Rf ${INIT}
31 fi
33 if [ ! -d ${INIT} ]; then
34 mkdir -p $INIT
35 fi
37 info "Making bootable image"
38 [ -f $LOG/initramfs.log ] && rm -f $LOG/initramfs.log
39 cat "$FLAVORS_REPOSITORY/$FLAVOR/packages.list" | grep -v "^#" | while read pkgname; do
40 if [ ! -f ${INIT}${INSTALLED}/${pkgname}/files.list ]; then
41 tazpkg get-install $pkgname --root=$INIT 2>/dev/null | tee -a $LOG/initramfs.log
42 sleep 1
43 else
44 info "${pkgname} installed" | tee -a $LOG/initramfs.log
45 fi
46 done
48 if [ -d $INIT ]; then
49 for i in $KEY_FILES; do
50 if [ -f $INIT/$i ]; then
51 cp -af $INIT/$i $INITRAMFS
52 fi
53 done
54 fi
56 if [ -f $INIT/liblinuxlive ]; then
57 sed -i "s|^#MIRROR|MIRROR=$MIRROR_DIR|g" $INIT/liblinuxlive
58 fi
60 }
62 slitaz_union () {
64 if [ -d ${MODULES_DIR}/${mod}${INSTALLED} ]; then
65 echo "${mod} module exist. Moving on."
66 elif [ ! -d ${MODULES_DIR}/${mod}${INSTALLED} ]; then
67 if [ -f "$FLAVORS_REPOSITORY/${mod}/packages.list" ]; then
68 [ -f ${LOG}/${mod}-current.log ] && rm -f ${LOG}/${mod}-current.log
69 cat "$FLAVORS_REPOSITORY/${mod}/packages.list" | grep -v "^#" | while read pkgname; do
70 if [ ! -f ${UNION}${INSTALLED}/${pkgname}/files.list ]; then
71 tazpkg get-install $pkgname --root=${UNION} | tee -a ${LOG}/${mod}-current.log
72 sleep 1
73 else
74 info "${pkgname} installed" | tee -a ${LOG}/${mod}-current.log
75 fi
76 done
77 fi
78 fi
79 }
81 union () {
82 if [ "$FLAVOR_MOD" ]; then
83 UNION_MODULES="$FLAVOR_MOD"
84 else
85 error "Error: no modules assigned in config for profile."
86 exit 1
87 fi
90 mkdir -p $UNION
91 mkdir -p $ROOTCD/${CDNAME}/base
92 mkdir -p $ROOTCD/${CDNAME}/modules
93 mkdir -p $ROOTCD/${CDNAME}/optional
94 mkdir -p $ROOTCD/${CDNAME}/rootcopy
95 mkdir -p $ROOTCD/${CDNAME}/tmp
96 mkdir -p $LASTBR
98 touch $SGNFILE
100 [ -f $INSTALLED/aufs/receipt ] || tazpkg get-install aufs --forced
101 modprobe aufs
102 if [ $? -ne 0 ]; then
103 error "Error loading Union filesystem module. (aufs)"
104 exit 1
105 fi
107 # $INIT is now $LASTBR
108 # This will be copyed to /mnt/memory/changes on boot
109 initramfs init-modular
111 mount -t aufs -o br:${LASTBR}=rw aufs ${UNION}
112 if [ $? -ne 0 ]; then
113 error "Error mounting $union."
114 exit 1
115 fi
117 info "====> Installing packages to '$UNION'"
118 for mod in $UNION_MODULES; do
120 if [ -d $MODULES_DIR/$mod ]; then
121 rm -Rf $MODULES_DIR/$mod
122 fi
124 if [ ! -d $MODULES_DIR/$mod ]; then
125 mkdir -p $MODULES_DIR/$mod
126 fi
127 info "Adding $MODULES_DIR/$mod as top branch of union."
128 mount -t aufs -o remount,add:0:${MODULES_DIR}/${mod}=rw aufs $UNION
129 info "Adding $LASTBR as lower branch of union."
130 mount -t aufs -o remount,mod:${LASTBR}=rr+wh aufs $UNION
131 LASTBR="$MODULES_DIR/${mod}"
133 slitaz_union
134 done
136 if [ -d ${UNION}/${INSTALLED} ]; then
137 ls ${UNION}/${INSTALLED} | sort > $ROOTCD/packages-installed.list
138 fi
140 info "Unmounting union"
141 umount -l "${UNION}"
143 info "Removing unionfs .wh. files."
144 find ${MODULES_DIR} -type f -name ".wh.*" -exec rm {} \;
145 find ${MODULES_DIR} -type d -name ".wh.*" -exec rm -rf {} \;
146 }
148 # _mksquash dirname
149 _mksquash () {
150 if [ ! -d "$1" ]; then
151 error "Error: '$1' is not a directory"
152 return 1
153 fi
155 if [ ! -d "$2" ]; then
156 error "Error: '$2' is not a directory"
157 return 1
158 fi
160 if [ ! -d "${1}${3}" ]; then
161 error "Error: '${1}${3}' is not a directory"
162 return 1
163 fi
165 time_dir="${3}"
166 sqimg="${2}/$(basename ${1}).${EXT}"
167 info "====> Generating SquashFS image for '${1}'"
168 if [ -e "${sqimg}" ]; then
169 dirhaschanged=$(find ${1}${time_dir} -newer ${sqimg})
170 if [ "${dirhaschanged}" != "" ]; then
171 info "SquashFS image '${sqimg}' is not up to date, rebuilding..."
172 rm "${sqimg}"
173 else
174 info "SquashFS image '${sqimg}' is up to date, skipping."
175 return
176 fi
177 fi
179 info "Creating SquashFS image. This may take some time..."
180 start=$(date +%s)
181 if [ "${QUIET}" = "y" ]; then
182 mksquashfs "${1}" "${sqimg}" ${NCPU} -noappend ${MKOPTION} -comp ${COMPRESSION} >/dev/null
183 else
184 mksquashfs "${1}" "${sqimg}" ${NCPU} -noappend ${MKOPTION} -comp ${COMPRESSION}
185 fi
186 minutes=$(echo $start $(date +%s) | awk '{ printf "%0.2f",($2-$1)/60 }')
187 info "Image creation done in $minutes minutes."
188 }