cookutils view lib/libmodular.sh @ rev 551
libmodular.sh: Add some comments.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Tue Oct 16 16:06:34 2012 +0000 (2012-10-16) |
parents | 2b093f098fe2 |
children | ddf33a57e7dc |
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 LOG=$DISTRO/log
13 EXT="xz"
14 COMPRESSION="xz -Xbcj x86"
15 MKOPTION="-b 512k"
16 #NCPU="-processors 3"
18 error () { echo -e "\033[1;31;40m!!! \033[1;37;40m$@\033[1;0m"; }
19 warn () { echo -e "\033[1;33;40m*** \033[1;37;40m$@\033[1;0m"; }
20 info () { echo -e "\033[1;32;40m>>> \033[1;37;40m$@\033[1;0m"; }
22 # build initramfs based one flavor
23 # $1 = flavor file
24 initramfs () {
26 FLAVOR=${1%.flavor}
27 if [ ! -f "$FLAVORS_REPOSITORY/$FLAVOR/receipt" ]; then
28 error "error: $FLAVORS_REPOSITORY/$FLAVOR/receipt doesn't exist, aborting."
29 exit 1
30 fi
32 if [ -d ${INIT} ]; then
33 rm -Rf ${INIT}
34 fi
36 if [ ! -d ${INIT} ]; then
37 mkdir -p $INIT
38 fi
40 if [ -d ${LOG} ]; then
41 rm -Rf $LOG
42 fi
44 if [ ! -d ${LOG} ]; then
45 mkdir -p $LOG
46 fi
48 info "Making bootable image"
49 [ -f $LOG/initramfs.log ] && rm -f $LOG/initramfs.log
50 cat "$FLAVORS_REPOSITORY/$FLAVOR/packages.list" | grep -v "^#" | while read pkgname; do
51 if [ ! -f ${INIT}${INSTALLED}/${pkgname}/files.list ]; then
52 tazpkg get-install $pkgname --root=$INIT 2>/dev/null | tee -a $LOG/initramfs.log
53 sleep 1
54 else
55 info "${pkgname} installed" | tee -a $LOG/initramfs.log
56 fi
57 done
59 if [ -d $INIT ]; then
60 for i in $KEY_FILES; do
61 if [ -f $INIT/$i ]; then
62 cp -af $INIT/$i $INITRAMFS
63 fi
64 done
65 fi
67 if [ -f $INIT/liblinuxlive ]; then
68 sed -i "s|^#MIRROR|MIRROR=$MIRROR_DIR|g" $INIT/liblinuxlive
69 fi
71 }
73 # build slitaz union
74 slitaz_union () {
76 if [ -d ${MODULES_DIR}/${mod}${INSTALLED} ]; then
77 echo "${mod} module exist. Moving on."
78 elif [ ! -d ${MODULES_DIR}/${mod}${INSTALLED} ]; then
79 if [ -f "$FLAVORS_REPOSITORY/${mod}/packages.list" ]; then
80 [ -f ${LOG}/${mod}-current.log ] && rm -f ${LOG}/${mod}-current.log
81 cat "$FLAVORS_REPOSITORY/${mod}/packages.list" | grep -v "^#" | while read pkgname; do
82 if [ ! -f ${UNION}${INSTALLED}/${pkgname}/files.list ]; then
83 tazpkg get-install $pkgname --root=${UNION} | tee -a ${LOG}/${mod}-current.log
84 sleep 1
85 else
86 info "${pkgname} installed" | tee -a ${LOG}/${mod}-current.log
87 fi
88 done
89 fi
90 fi
91 }
93 # build aufs union
94 union () {
95 if [ "$FLAVOR_MOD" ]; then
96 UNION_MODULES="$FLAVOR_MOD"
97 else
98 error "Error: no modules assigned in config for profile."
99 exit 1
100 fi
103 mkdir -p $UNION
104 mkdir -p $ROOTCD/${CDNAME}/base
105 mkdir -p $ROOTCD/${CDNAME}/modules
106 mkdir -p $ROOTCD/${CDNAME}/optional
107 mkdir -p $ROOTCD/${CDNAME}/rootcopy
108 mkdir -p $ROOTCD/${CDNAME}/tmp
109 mkdir -p $LASTBR
111 touch $SGNFILE
113 [ -f $INSTALLED/aufs/receipt ] || tazpkg get-install aufs --forced
114 modprobe aufs
115 if [ $? -ne 0 ]; then
116 error "Error loading Union filesystem module. (aufs)"
117 exit 1
118 fi
120 # $INIT is now $LASTBR
121 # This will be copyed to /mnt/memory/changes on boot
122 initramfs init-modular
124 mount -t aufs -o br:${LASTBR}=rw aufs ${UNION}
125 if [ $? -ne 0 ]; then
126 error "Error mounting $union."
127 exit 1
128 fi
130 info "====> Installing packages to '$UNION'"
131 for mod in $UNION_MODULES; do
133 if [ -d $MODULES_DIR/$mod ]; then
134 rm -Rf $MODULES_DIR/$mod
135 fi
137 if [ ! -d $MODULES_DIR/$mod ]; then
138 mkdir -p $MODULES_DIR/$mod
139 fi
140 info "Adding $MODULES_DIR/$mod as top branch of union."
141 mount -t aufs -o remount,add:0:${MODULES_DIR}/${mod}=rw aufs $UNION
142 info "Adding $LASTBR as lower branch of union."
143 mount -t aufs -o remount,mod:${LASTBR}=rr+wh aufs $UNION
144 LASTBR="$MODULES_DIR/${mod}"
146 slitaz_union
147 done
149 if [ -d ${UNION}/${INSTALLED} ]; then
150 ls ${UNION}/${INSTALLED} | sort > $ROOTCD/packages-installed.list
151 fi
153 info "Unmounting union"
154 umount -l "${UNION}"
156 info "Removing unionfs .wh. files."
157 find ${MODULES_DIR} -type f -name ".wh.*" -exec rm {} \;
158 find ${MODULES_DIR} -type d -name ".wh.*" -exec rm -rf {} \;
159 }
161 # _mksquash dirname
162 _mksquash () {
163 if [ ! -d "$1" ]; then
164 error "Error: '$1' is not a directory"
165 return 1
166 fi
168 if [ ! -d "$2" ]; then
169 error "Error: '$2' is not a directory"
170 return 1
171 fi
173 if [ ! -d "${1}${3}" ]; then
174 error "Error: '${1}${3}' is not a directory"
175 return 1
176 fi
178 time_dir="${3}"
179 sqimg="${2}/$(basename ${1}).${EXT}"
180 info "====> Generating SquashFS image for '${1}'"
181 if [ -e "${sqimg}" ]; then
182 dirhaschanged=$(find ${1}${time_dir} -newer ${sqimg})
183 if [ "${dirhaschanged}" != "" ]; then
184 info "SquashFS image '${sqimg}' is not up to date, rebuilding..."
185 rm "${sqimg}"
186 else
187 info "SquashFS image '${sqimg}' is up to date, skipping."
188 return
189 fi
190 fi
192 info "Creating SquashFS image. This may take some time..."
193 start=$(date +%s)
194 if [ "${QUIET}" = "y" ]; then
195 mksquashfs "${1}" "${sqimg}" ${NCPU} -noappend ${MKOPTION} -comp ${COMPRESSION} >/dev/null
196 else
197 mksquashfs "${1}" "${sqimg}" ${NCPU} -noappend ${MKOPTION} -comp ${COMPRESSION}
198 fi
199 minutes=$(echo $start $(date +%s) | awk '{ printf "%0.2f",($2-$1)/60 }')
200 info "Image creation done in $minutes minutes."
201 }