cookutils view lib/libmodular.sh @ rev 546

libmodular.sh: Make sure $LOG folder exist.
author Christopher Rogers <slaxemulator@gmail.com>
date Mon Oct 15 21:51:38 2012 +0000 (2012-10-15)
parents 2b6720a968c8
children c2a20cfc1197
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 initramfs () {
24 FLAVOR=${1%.flavor}
25 if [ ! -f "$FLAVORS_REPOSITORY/$FLAVOR/receipt" ]; then
26 error "error: $FLAVORS_REPOSITORY/$FLAVOR/receipt doesn't exist, aborting."
27 exit 1
28 fi
30 if [ -d ${INIT} ]; then
31 rm -Rf ${INIT}
32 fi
34 if [ ! -d ${INIT} ]; then
35 mkdir -p $INIT
36 fi
38 if [ -d ${LOG} ]; then
39 rm -Rf $LOG
40 fi
42 if [ ! -d ${LOG} ]; then
43 mkdir -p $LOG
44 fi
46 info "Making bootable image"
47 [ -f $LOG/initramfs.log ] && rm -f $LOG/initramfs.log
48 cat "$FLAVORS_REPOSITORY/$FLAVOR/packages.list" | grep -v "^#" | while read pkgname; do
49 if [ ! -f ${INIT}${INSTALLED}/${pkgname}/files.list ]; then
50 tazpkg get-install $pkgname --root=$INIT 2>/dev/null | tee -a $LOG/initramfs.log
51 sleep 1
52 else
53 info "${pkgname} installed" | tee -a $LOG/initramfs.log
54 fi
55 done
57 if [ -d $INIT ]; then
58 for i in $KEY_FILES; do
59 if [ -f $INIT/$i ]; then
60 cp -af $INIT/$i $INITRAMFS
61 fi
62 done
63 fi
65 if [ -f $INIT/liblinuxlive ]; then
66 sed -i "s|^#MIRROR|MIRROR=$MIRROR_DIR|g" $INIT/liblinuxlive
67 fi
69 }
71 slitaz_union () {
73 if [ -d ${MODULES_DIR}/${mod}${INSTALLED} ]; then
74 echo "${mod} module exist. Moving on."
75 elif [ ! -d ${MODULES_DIR}/${mod}${INSTALLED} ]; then
76 if [ -f "$FLAVORS_REPOSITORY/${mod}/packages.list" ]; then
77 [ -f ${LOG}/${mod}-current.log ] && rm -f ${LOG}/${mod}-current.log
78 cat "$FLAVORS_REPOSITORY/${mod}/packages.list" | grep -v "^#" | while read pkgname; do
79 if [ ! -f ${UNION}${INSTALLED}/${pkgname}/files.list ]; then
80 tazpkg get-install $pkgname --root=${UNION} | tee -a ${LOG}/${mod}-current.log
81 sleep 1
82 else
83 info "${pkgname} installed" | tee -a ${LOG}/${mod}-current.log
84 fi
85 done
86 fi
87 fi
88 }
90 union () {
91 if [ "$FLAVOR_MOD" ]; then
92 UNION_MODULES="$FLAVOR_MOD"
93 else
94 error "Error: no modules assigned in config for profile."
95 exit 1
96 fi
99 mkdir -p $UNION
100 mkdir -p $ROOTCD/${CDNAME}/base
101 mkdir -p $ROOTCD/${CDNAME}/modules
102 mkdir -p $ROOTCD/${CDNAME}/optional
103 mkdir -p $ROOTCD/${CDNAME}/rootcopy
104 mkdir -p $ROOTCD/${CDNAME}/tmp
105 mkdir -p $LASTBR
107 touch $SGNFILE
109 [ -f $INSTALLED/aufs/receipt ] || tazpkg get-install aufs --forced
110 modprobe aufs
111 if [ $? -ne 0 ]; then
112 error "Error loading Union filesystem module. (aufs)"
113 exit 1
114 fi
116 # $INIT is now $LASTBR
117 # This will be copyed to /mnt/memory/changes on boot
118 initramfs init-modular
120 mount -t aufs -o br:${LASTBR}=rw aufs ${UNION}
121 if [ $? -ne 0 ]; then
122 error "Error mounting $union."
123 exit 1
124 fi
126 info "====> Installing packages to '$UNION'"
127 for mod in $UNION_MODULES; do
129 if [ -d $MODULES_DIR/$mod ]; then
130 rm -Rf $MODULES_DIR/$mod
131 fi
133 if [ ! -d $MODULES_DIR/$mod ]; then
134 mkdir -p $MODULES_DIR/$mod
135 fi
136 info "Adding $MODULES_DIR/$mod as top branch of union."
137 mount -t aufs -o remount,add:0:${MODULES_DIR}/${mod}=rw aufs $UNION
138 info "Adding $LASTBR as lower branch of union."
139 mount -t aufs -o remount,mod:${LASTBR}=rr+wh aufs $UNION
140 LASTBR="$MODULES_DIR/${mod}"
142 slitaz_union
143 done
145 if [ -d ${UNION}/${INSTALLED} ]; then
146 ls ${UNION}/${INSTALLED} | sort > $ROOTCD/packages-installed.list
147 fi
149 info "Unmounting union"
150 umount -l "${UNION}"
152 info "Removing unionfs .wh. files."
153 find ${MODULES_DIR} -type f -name ".wh.*" -exec rm {} \;
154 find ${MODULES_DIR} -type d -name ".wh.*" -exec rm -rf {} \;
155 }
157 # _mksquash dirname
158 _mksquash () {
159 if [ ! -d "$1" ]; then
160 error "Error: '$1' is not a directory"
161 return 1
162 fi
164 if [ ! -d "$2" ]; then
165 error "Error: '$2' is not a directory"
166 return 1
167 fi
169 if [ ! -d "${1}${3}" ]; then
170 error "Error: '${1}${3}' is not a directory"
171 return 1
172 fi
174 time_dir="${3}"
175 sqimg="${2}/$(basename ${1}).${EXT}"
176 info "====> Generating SquashFS image for '${1}'"
177 if [ -e "${sqimg}" ]; then
178 dirhaschanged=$(find ${1}${time_dir} -newer ${sqimg})
179 if [ "${dirhaschanged}" != "" ]; then
180 info "SquashFS image '${sqimg}' is not up to date, rebuilding..."
181 rm "${sqimg}"
182 else
183 info "SquashFS image '${sqimg}' is up to date, skipping."
184 return
185 fi
186 fi
188 info "Creating SquashFS image. This may take some time..."
189 start=$(date +%s)
190 if [ "${QUIET}" = "y" ]; then
191 mksquashfs "${1}" "${sqimg}" ${NCPU} -noappend ${MKOPTION} -comp ${COMPRESSION} >/dev/null
192 else
193 mksquashfs "${1}" "${sqimg}" ${NCPU} -noappend ${MKOPTION} -comp ${COMPRESSION}
194 fi
195 minutes=$(echo $start $(date +%s) | awk '{ printf "%0.2f",($2-$1)/60 }')
196 info "Image creation done in $minutes minutes."
197 }