wok view mirror-tools/stuff/usr/bin/mkpkgiso @ rev 2119
mkpkgiso: do hg update website
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Jan 31 14:36:40 2009 +0000 (2009-01-31) |
parents | 2452b18a0620 |
children | b49b77ea5976 |
line source
1 #!/bin/sh
2 # mkpkgiso, build packages ISO image.
3 # (C) 2007-TODAY SliTaz - GNU General Public License v3.
4 #
5 # Authors : Eric Joseph-Alexandre <erjo@slitaz.org>
6 # Pascal Bellard <pascal.bellard@slitaz.org>
8 VERSION=0.3
10 ROOT=/home/slitaz/iso
11 TEMP_DIR=${ROOT}/_iso.$$
12 PKG_VER=$1
13 shift
14 OPTIONS=$@
15 PKG_DIR=$TEMP_DIR/packages/$PKG_VER
16 REPOS=/var/www/slitaz/mirror/packages/$PKG_VER
17 ISO_DIR=/var/www/slitaz/mirror/iso/$PKG_VER
18 LOG=$PWD/$(basename $0).log
20 #
21 VOLUME_ID="packages-${PKG_VER}"
22 PUBLISHER="SliTaz http://www.slitaz.org/"
23 IMAGE="packages-${PKG_VER}.iso"
24 OUTPUT="$ROOT/$IMAGE"
26 # Check command line option.
27 if [ -z $PKG_VER ]; then
28 echo "Usage: $(basename $0) <Version> [--boot|--webboot][--filter]"
29 exit 1
30 fi
32 # Check if we provide a valide version
33 if [ ! -d $REPOS ]; then
34 echo "Boooh! $PKG_VER is not a valid version."
35 exit 1
36 fi
38 # Status function.
39 status()
40 {
41 local CHECK=$?
42 echo -en "\\033[70G[ "
43 if [ $CHECK = 0 ]; then
44 echo -en "\\033[1;33mOK"
45 else
46 echo -en "\\033[1;31mFailed"
47 fi
48 echo -e "\\033[0;39m ]"
49 }
51 # Create temp directory
52 mkdir -p $TEMP_DIR/packages/$PKG_VER
54 # Prepare evrything for ISO
56 echo ""
57 echo "Building ISO for packages $PKG_VER"
58 echo "==============================================================================="
59 echo -n "Creating working dir $(basename $TEMP_DIR)"
60 status
61 echo -n "Creating symlink"
62 status
64 # Link every packages to temp dir
65 cd $PKG_DIR
66 for i in $REPOS/*
67 do
68 ln -s $i >> $LOG 2>&1
69 done
71 echo -n "Creating install script"
72 # Create install script as suggested by Pascal.
73 cat >$TEMP_DIR/install.sh<<EOF
74 #!/bin/sh
75 #
77 DIR=\$(cd \$(dirname \$0); pwd)
79 [ -d /var/cache/tazpkg ] || mkdir -p /var/cache/tazpkg
80 ls -d \$DIR/packages/* > /var/lib/tazpkg/mirror
81 ln -fs \$DIR/packages/*/*.tazpkg /var/cache/tazpkg/
82 ln -fs \$DIR/packages/*/packages.* /var/lib/tazpkg
83 EOF
84 [ -e files.list.lzma ] && cat >>$TEMP_DIR/install.sh<<EOF
85 ln -fs \$DIR/packages/*/files.list.lzma /var/lib/tazpkg
86 EOF
88 status
89 chmod 755 $TEMP_DIR/install.sh
91 case " $OPTIONS " in
92 *\ --filter\ *)
93 SIZE=0
94 for i in *.tazpkg; do
95 while read f; do
96 case "$i" in
97 $f*) continue 2;;
98 esac
99 done < packages.list
100 echo -n "Filter out $i ($(du -hs $(readlink $i) | awk '{ print $1 }'))..."
101 SIZE=$(( $SIZE + $(stat -c %s $(readlink $i)) ))
102 rm $i
103 status
104 done
105 UNIT=" bytes"
106 if [ $SIZE -gt 10240 ]; then
107 SIZE=$(( $SIZE / 1024 ))
108 UNIT="K"
109 fi
110 if [ $SIZE -gt 10240 ]; then
111 SIZE=$(( $SIZE / 1024 ))
112 UNIT="M"
113 fi
114 echo "$SIZE$UNIT removed.";;
115 esac
116 case " $OPTIONS " in
117 *\ --website\ *)
118 if [ -d /slitaz/home/slitaz/hg/website ]; then
119 echo -n "Adding web site"
120 chroot /slitaz hg --repository /home/slitaz/hg/website pull >/dev/null
121 chroot /slitaz hg --repository /home/slitaz/hg/website update >/dev/null
122 mkdir $TEMP_DIR/website
123 cp -a /slitaz/home/slitaz/hg/website/* $TEMP_DIR/website
124 cat >>$TEMP_DIR/install.sh<<EOF
125 [ -d /var/www ] || mkdir -p /var/www
126 ln -s \$DIR/website /var/www
127 EOF
128 status
129 echo "$(du -hs $TEMP_DIR/website | awk '{ print $1 }') used by web site."
130 fi;;
131 esac
133 # Extract boot package function
134 extract_boot()
135 {
136 f=$(ls $REPOS/$1-[0-9]*.tazpkg 2> /dev/null)
137 [ -f "$f" ] || return 1
138 [ -d $TEMP_DIR/boot ] || mkdir $TEMP_DIR/boot
139 ( cd $TEMP_DIR/boot ; cpio -i fs.cpio.gz < $f 2> /dev/null )
140 ( cd $TEMP_DIR/boot ; zcat fs.cpio.gz | cpio -id 2> /dev/null )
141 mv $TEMP_DIR/boot/fs/boot/* $TEMP_DIR/boot
142 rm -rf $TEMP_DIR/boot/fs.cpio.gz $TEMP_DIR/boot/fs
143 return 0
144 }
146 # Gen boot part
147 BOOT_OPT=""
148 iso=$ISO_DIR/slitaz-$PKG_VER.iso
149 case " $OPTIONS " in
150 *\ --boot\ *)
151 echo -n "Creating boot tree"
152 isoinfo -R -l -i $iso | awk '/^Directory/ { path=$4 } /^-/ { print path$12 }' | while read file; do
153 [ "$(basename $file)" == ".." ] && continue
154 [ "$file" = "/boot/isolinux/boot.cat" ] && continue
155 [ -d "$(dirname $TEMP_DIR/$file)" ] ||
156 mkdir -p "$(dirname $TEMP_DIR/$file)"
157 isoinfo -R -x "$file" -i $iso > "$TEMP_DIR/$file"
158 done
159 status
160 BOOT_OPT="-b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
161 -no-emul-boot -boot-load-size 4 -boot-info-table"
162 ;;
163 *\ --webboot\ *)
164 if extract_boot gpxe; then
165 echo -n "Creating web boot tree"
166 mkdir $TEMP_DIR/boot/isolinux/
167 isoinfo -x "/BOOT/ISOLINUX/ISOLINUX.BIN;1" -i $iso > \
168 $TEMP_DIR/boot/isolinux/isolinux.bin
169 mv $TEMP_DIR/boot/gpxe $TEMP_DIR/boot/isolinux
170 cat > $TEMP_DIR/boot/isolinux/isolinux.cfg <<EOT
171 default gpxe
172 append http://mirror.slitaz.org/pxe/pxelinux.0
173 EOT
174 status
175 BOOT_OPT="-b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
176 -no-emul-boot -boot-load-size 4 -boot-info-table"
177 fi
178 ;;
179 esac
181 if [ -n "$BOOT_OPT" ]; then
182 echo "$(du -hs $TEMP_DIR/boot | awk '{ print $1 }') used by boot."
183 fi
185 # Gen ISO
186 echo -n "Generating iso image"
187 /usr/bin/genisoimage -R -J -f -V $VOLUME_ID \
188 -P "$PUBLISHER" -md5-list $REPOS/packages.md5 \
189 -quiet -o $OUTPUT $BOOT_OPT $TEMP_DIR
190 status
192 echo "$(du -hs $OUTPUT | awk '{ print $1 }') used by iso image."
194 cd ${ROOT}
195 echo -n "Create hybrid DVD/CDROM"
196 [ -x /usr/bin/isohybrid ] && /usr/bin/isohybrid $IMAGE 2> /dev/null
197 status
199 echo -n "Calculate md5sum"
200 /usr/bin/md5sum $IMAGE > $(basename $IMAGE .iso).md5
201 status
203 echo -n "Moving file to mirror"
204 mv $IMAGE $ISO_DIR
205 mv $(basename $IMAGE .iso).md5 $ISO_DIR
206 status
209 # Cleaning temp files
210 rm -rf $TEMP_DIR