]> git.proxmox.com Git - mirror_lxc.git/blob - templates/lxc-slackware.in
confile: lxc.rootfs --> lxc.rootfs.path
[mirror_lxc.git] / templates / lxc-slackware.in
1 #!/bin/bash
2
3 #
4 # lxc: linux Container library
5
6 # Authors:
7 # Daniel Lezcano <daniel.lezcano@free.fr>
8
9 # Template for slackware by Matteo Bernardini <ponce@slackbuilds.org>
10 # some parts are taken from the debian one (used as model)
11
12 # This library is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU Lesser General Public
14 # License as published by the Free Software Foundation; either
15 # version 2.1 of the License, or (at your option) any later version.
16
17 # This library is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # Lesser General Public License for more details.
21
22 # You should have received a copy of the GNU Lesser General Public
23 # License along with this library; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
26 # Detect use under userns (unsupported)
27 for arg in "$@"; do
28 [ "$arg" = "--" ] && break
29 if [ "$arg" = "--mapped-uid" -o "$arg" = "--mapped-gid" ]; then
30 echo "This template can't be used for unprivileged containers." 1>&2
31 echo "You may want to try the \"download\" template instead." 1>&2
32 exit 1
33 fi
34 done
35
36 # Add some directories to PATH in case we create containers with sudo
37 export PATH=/sbin:/usr/sbin:$PATH
38
39 cache=${cache:-/var/cache/lxc/slackware}
40
41 # Use the primary Slackware site by default, but please consider changing
42 # this to a closer mirror site.
43 MIRROR=${MIRROR:-http://ftp.slackware.com/pub/slackware}
44
45 if [ -z "$arch" ]; then
46 case "$( uname -m )" in
47 i?86) arch=i486 ;;
48 arm*) arch=arm ;;
49 *) arch=$( uname -m ) ;;
50 esac
51 fi
52
53 LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
54
55 configure_slackware()
56 {
57 rootfs=$1
58 hostname=$2
59
60 echo "Configuring..." ; echo
61
62 # The next part contains excerpts taken from SeTconfig (written by
63 # Patrick Volkerding) from the slackware setup disk.
64 # But before pasting them just set a variable to use them as they are
65 T_PX=$rootfs
66
67 ( cd $T_PX ; chmod 755 ./ )
68 ( cd $T_PX ; chmod 755 ./var )
69 if [ -d $T_PX/usr/src/linux ]; then
70 chmod 755 $T_PX/usr/src/linux
71 fi
72 if [ ! -d $T_PX/proc ]; then
73 mkdir $T_PX/proc
74 chown root.root $T_PX/proc
75 fi
76 if [ ! -d $T_PX/sys ]; then
77 mkdir $T_PX/sys
78 chown root.root $T_PX/sys
79 fi
80 chmod 1777 $T_PX/tmp
81 if [ ! -d $T_PX/var/spool/mail ]; then
82 mkdir -p $T_PX/var/spool/mail
83 chmod 755 $T_PX/var/spool
84 chown root.mail $T_PX/var/spool/mail
85 chmod 1777 $T_PX/var/spool/mail
86 fi
87
88 echo "#!/bin/sh" > $T_PX/etc/rc.d/rc.keymap
89 echo "# Load the keyboard map. More maps are in /usr/share/kbd/keymaps." \
90 >> $T_PX/etc/rc.d/rc.keymap
91 echo "if [ -x /usr/bin/loadkeys ]; then" >> $T_PX/etc/rc.d/rc.keymap
92 echo " /usr/bin/loadkeys us" >> $T_PX/etc/rc.d/rc.keymap
93 echo "fi" >> $T_PX/etc/rc.d/rc.keymap
94 chmod 755 $T_PX/etc/rc.d/rc.keymap
95
96 # Network configuration is left to the user, that have to edit
97 # /etc/rc.d/rc.inet1.conf and /etc/resolv.conf of the container
98 # just set the hostname
99 cat <<EOF > $rootfs/etc/HOSTNAME
100 $hostname.example.net
101 EOF
102 cp $rootfs/etc/HOSTNAME $rootfs/etc/hostname
103
104 # make needed devices, from Chris Willing's MAKEDEV.sh
105 # http://www.vislab.uq.edu.au/howto/lxc/MAKEDEV.sh
106 DEV=$rootfs/dev
107 mkdir -p ${DEV}
108 mknod -m 666 ${DEV}/null c 1 3
109 mknod -m 666 ${DEV}/zero c 1 5
110 mknod -m 666 ${DEV}/random c 1 8
111 mknod -m 666 ${DEV}/urandom c 1 9
112 mkdir -m 755 ${DEV}/pts
113 mkdir -m 1777 ${DEV}/shm
114 mknod -m 666 ${DEV}/tty c 5 0
115 mknod -m 600 ${DEV}/console c 5 1
116 mknod -m 666 ${DEV}/tty0 c 4 0
117 mknod -m 666 ${DEV}/tty1 c 4 1
118 mknod -m 666 ${DEV}/tty2 c 4 2
119 mknod -m 666 ${DEV}/tty3 c 4 3
120 mknod -m 666 ${DEV}/tty4 c 4 4
121 mknod -m 666 ${DEV}/tty5 c 4 5
122 mknod -m 666 ${DEV}/full c 1 7
123 mknod -m 600 ${DEV}/initctl p
124 mknod -m 660 ${DEV}/loop0 b 7 0
125 mknod -m 660 ${DEV}/loop1 b 7 1
126 ln -s pts/ptmx ${DEV}/ptmx
127 ln -s /proc/self/fd ${DEV}/fd
128
129 echo "Adding an etc/fstab"
130 cat >$rootfs/etc/fstab <<EOF
131 none /run tmpfs defaults,mode=0755 0 0
132 EOF
133
134 # simplify rc.6 and rc.S, http://www.vislab.uq.edu.au/howto/lxc/create_container.html
135 # and some other small fixes for a clean boot
136 cat >$rootfs/tmp/rcs.patch <<'EOF'
137 --- ./etc/rc.orig/rc.6 2012-08-15 01:03:12.000000000 +0200
138 +++ ./etc/rc.d/rc.6 2013-02-17 10:26:30.888839354 +0100
139 @@ -9,6 +9,12 @@
140 # Author: Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
141 # Modified by: Patrick J. Volkerding, <volkerdi@slackware.com>
142 #
143 +# minor tweaks for an lxc container
144 +# by Matteo Bernardini <ponce@slackbuilds.org>,
145 +# based also on Chris Willing's modifications
146 +# http://www.vislab.uq.edu.au/howto/lxc/rc.6
147 +# a check for a container variable is made to jump sections
148 +container="lxc"
149
150 # Set the path.
151 PATH=/sbin:/etc:/bin:/usr/bin
152 @@ -37,6 +43,9 @@
153 ;;
154 esac
155
156 +# lxc container check
157 +if [ ! $container = "lxc" ]; then
158 +
159 # Save the system time to the hardware clock using hwclock --systohc.
160 if [ -x /sbin/hwclock ]; then
161 # Check for a broken motherboard RTC clock (where ioports for rtc are
162 @@ -53,6 +62,8 @@
163 fi
164 fi
165
166 +fi # end container check
167 +
168 # Run any local shutdown scripts:
169 if [ -x /etc/rc.d/rc.local_shutdown ]; then
170 /etc/rc.d/rc.local_shutdown stop
171 @@ -148,6 +159,9 @@
172 sleep 2
173 fi
174
175 +# lxc container check
176 +if [ ! $container = "lxc" ]; then
177 +
178 # Shut down PCMCIA devices:
179 if [ -x /etc/rc.d/rc.pcmcia ]; then
180 . /etc/rc.d/rc.pcmcia stop
181 @@ -155,11 +169,16 @@
182 /bin/sleep 5
183 fi
184
185 +fi # end container check
186 +
187 # Turn off process accounting:
188 if [ -x /sbin/accton -a -r /var/log/pacct ]; then
189 /sbin/accton off
190 fi
191
192 +# lxc container check
193 +if [ ! $container = "lxc" ]; then
194 +
195 # Terminate acpid before syslog:
196 if [ -x /etc/rc.d/rc.acpid -a -r /var/run/acpid.pid ]; then # quit
197 . /etc/rc.d/rc.acpid stop
198 @@ -170,6 +189,8 @@
199 sh /etc/rc.d/rc.udev force-stop
200 fi
201
202 +fi # end container check
203 +
204 # Kill all remaining processes.
205 if [ ! "$1" = "fast" ]; then
206 echo "Sending all processes the SIGTERM signal."
207 @@ -179,6 +200,9 @@
208 /sbin/killall5 -9
209 fi
210
211 +# lxc container check
212 +if [ ! $container = "lxc" ]; then
213 +
214 # Try to turn off quota.
215 if /bin/grep -q quota /etc/fstab ; then
216 if [ -x /sbin/quotaoff ]; then
217 @@ -187,6 +211,8 @@
218 fi
219 fi
220
221 +fi # end container check
222 +
223 # Carry a random seed between reboots.
224 echo "Saving random seed from /dev/urandom in /etc/random-seed."
225 # Use the pool size from /proc, or 512 bytes:
226 @@ -205,6 +231,9 @@
227 rm -f /var/lock/subsys/*
228 fi
229
230 +# lxc container check
231 +if [ ! $container = "lxc" ]; then
232 +
233 # Turn off swap:
234 echo "Turning off swap."
235 /sbin/swapoff -a
236 @@ -216,6 +245,8 @@
237 echo "Remounting root filesystem read-only."
238 /bin/mount -v -n -o remount,ro /
239
240 +fi # end container check
241 +
242 # This never hurts:
243 /bin/sync
244
245 @@ -240,12 +271,17 @@
246 done
247 fi
248
249 +# lxc container check
250 +if [ ! $container = "lxc" ]; then
251 +
252 # Deactivate LVM volume groups:
253 if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then
254 echo "Deactivating LVM volume groups:"
255 /sbin/vgchange -an --ignorelockingfailure
256 fi
257
258 +fi # end container check
259 +
260 # This never hurts again (especially since root-on-LVM always fails
261 # to deactivate the / logical volume... but at least it was
262 # remounted as read-only first)
263 @@ -258,6 +294,9 @@
264 # This is to ensure all processes have completed on SMP machines:
265 wait
266
267 +# lxc container check
268 +if [ ! $container = "lxc" ]; then
269 +
270 if [ -x /sbin/genpowerd ]; then
271 # See if this is a powerfail situation:
272 if /bin/egrep -q "FAIL|SCRAM" /etc/upsstatus 2> /dev/null ; then
273 @@ -274,6 +313,13 @@
274 fi
275 fi
276
277 +else
278 +
279 +# confirm successful shutdown of the container
280 +echo ; echo "* container stopped. *" ; echo
281 +
282 +fi # end container check
283 +
284 # Now halt (poweroff with APM or ACPI enabled kernels) or reboot.
285 if [ "$command" = "reboot" ]; then
286 echo "Rebooting."
287 --- ./etc/rc.orig/rc.S 2012-09-13 21:38:34.000000000 +0200
288 +++ ./etc/rc.d/rc.S 2013-02-17 09:39:41.579799641 +0100
289 @@ -4,9 +4,18 @@
290 #
291 # Mostly written by: Patrick J. Volkerding, <volkerdi@slackware.com>
292 #
293 +# minor tweaks for an lxc container
294 +# by Matteo Bernardini <ponce@slackbuilds.org>,
295 +# based also on Chris Willing's modifications
296 +# http://www.vislab.uq.edu.au/howto/lxc/rc.S
297 +# a check for a container variable is made to jump sections
298 +container="lxc"
299
300 PATH=/sbin:/usr/sbin:/bin:/usr/bin
301
302 +# lxc container check
303 +if [ ! $container = "lxc" ]; then
304 +
305 # Try to mount /proc:
306 /sbin/mount -v proc /proc -n -t proc 2> /dev/null
307
308 @@ -254,10 +263,27 @@
309 read junk;
310 fi # Done checking root filesystem
311
312 +else
313 + # We really don't want to start udev in the container
314 + if [ -f /etc/rc.d/rc.udev ]; then
315 + chmod -x /etc/rc.d/rc.udev
316 + fi
317 + # Alsa won't work
318 + if [ -f /etc/rc.d/rc.alsa ]; then
319 + chmod -x /etc/rc.d/rc.alsa
320 + fi
321 + # This too
322 + if [ -f /etc/rc.d/rc.loop ]; then
323 + chmod -x /etc/rc.d/rc.loop
324 + fi
325 +fi # end container check
326
327 # Any /etc/mtab that exists here is old, so we start with a new one:
328 /bin/rm -f /etc/mtab{,~,.tmp} && /bin/touch /etc/mtab
329
330 +# lxc container check
331 +if [ ! $container = "lxc" ]; then
332 +
333 # Add entry for / to /etc/mtab:
334 /sbin/mount -f -w /
335
336 @@ -337,6 +363,8 @@
337 # mounted read-write.
338 /sbin/swapon -a 2> /dev/null
339
340 +fi # end container check
341 +
342 # Clean up some temporary files:
343 rm -f /var/run/* /var/run/*/* /var/run/*/*/* /etc/nologin \
344 /etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot \
345 @@ -364,7 +392,7 @@
346 # if the first line of that file begins with the word 'Linux'.
347 # You are free to modify the rest of the file as you see fit.
348 if [ -x /bin/sed ]; then
349 - /bin/sed -i "{1s/^Linux.*/$(/bin/uname -sr)\./}" /etc/motd
350 + /bin/sed -i "{1s/^Linux.*/$(/bin/uname -sr) lxc container\./}" /etc/motd
351 fi
352
353 # If there are SystemV init scripts for this runlevel, run them.
354 @@ -372,6 +400,9 @@
355 . /etc/rc.d/rc.sysvinit
356 fi
357
358 +# lxc container check
359 +if [ ! $container = "lxc" ]; then
360 +
361 # Run serial port setup script:
362 # CAREFUL! This can make some systems hang if the rc.serial script isn't
363 # set up correctly. If this happens, you may have to edit the file from a
364 @@ -380,6 +411,8 @@
365 sh /etc/rc.d/rc.serial start
366 fi
367
368 +fi # end container check
369 +
370 # Carry an entropy pool between reboots to improve randomness.
371 if [ -f /etc/random-seed ]; then
372 echo "Using /etc/random-seed to initialize /dev/urandom."
373 --- ./etc/rc.orig/rc.M 2012-09-25 19:47:07.000000000 +0200
374 +++ ./etc/rc.d/rc.M 2013-02-17 09:39:41.579799641 +0100
375 @@ -10,6 +10,10 @@
376 # Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
377 # Heavily modified by Patrick Volkerding <volkerdi@slackware.com>
378 #
379 +# minor tweaks for an lxc container
380 +# by Matteo Bernardini <ponce@slackbuilds.org>:
381 +# a check for a container variable is made to jump sections
382 +container="lxc"
383
384 # Tell the viewers what's going to happen.
385 echo "Going multiuser..."
386 @@ -20,6 +24,9 @@
387 /sbin/ldconfig &
388 fi
389
390 +# lxc container check
391 +if [ ! $container = "lxc" ]; then
392 +
393 # Screen blanks after 15 minutes idle time, and powers down in one hour
394 # if the kernel supports APM or ACPI power management:
395 /bin/setterm -blank 15 -powersave powerdown -powerdown 60
396 @@ -33,6 +40,8 @@
397 /bin/hostname darkstar
398 fi
399
400 +fi # end container check
401 +
402 # Set the permissions on /var/log/dmesg according to whether the kernel
403 # permits non-root users to access kernel dmesg information:
404 if [ -r /proc/sys/kernel/dmesg_restrict ]; then
405 @@ -135,6 +144,9 @@
406 chmod 755 / 2> /dev/null
407 chmod 1777 /tmp /var/tmp
408
409 +# lxc container check
410 +if [ ! $container = "lxc" ]; then
411 +
412 # Start APM or ACPI daemon.
413 # If APM is enabled in the kernel, start apmd:
414 if [ -e /proc/apm ]; then
415 @@ -146,6 +158,8 @@
416 . /etc/rc.d/rc.acpid start
417 fi
418
419 +fi # end container check
420 +
421 # Update any existing icon cache files:
422 if find /usr/share/icons 2> /dev/null | grep -q icon-theme.cache ; then
423 for theme_dir in /usr/share/icons/* ; do
424 --- ./etc/rc.orig/rc.inet1 2012-08-05 19:13:27.000000000 +0200
425 +++ ./etc/rc.d/rc.inet1 2013-02-17 09:39:41.579799641 +0100
426 @@ -3,6 +3,11 @@
427 # This script is used to bring up the various network interfaces.
428 #
429 # @(#)/etc/rc.d/rc.inet1 10.2 Sun Jul 24 12:45:56 PDT 2005 (pjv)
430 +#
431 +# minor tweaks for an lxc container
432 +# by Matteo Bernardini <ponce@slackbuilds.org>:
433 +# a check for a container variable is made to jump sections
434 +container="lxc"
435
436 ############################
437 # READ NETWORK CONFIG FILE #
438 @@ -105,6 +110,10 @@
439 [ "${IFNAME[$i]}" = "${1}" ] && break
440 i=$(($i+1))
441 done
442 +
443 + # lxc container check
444 + if [ ! $container = "lxc" ]; then
445 +
446 # If the interface is a bridge, then create it first:
447 [ -n "${BRNICS[$i]}" ] && br_open $i
448 # If the interface isn't in the kernel yet (but there's an alias for it in
449 @@ -115,6 +124,9 @@
450 /sbin/modprobe ${1}
451 fi
452 fi
453 +
454 + fi # end container check
455 +
456 if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then # interface exists
457 if ! /sbin/ifconfig | grep -w "${1}" 1>/dev/null || \
458 ! /sbin/ifconfig ${1} | grep -w inet 1> /dev/null ; then # interface not up or not configured
459 EOF
460 ( cd $rootfs ; patch -p1 < tmp/rcs.patch ; rm tmp/rcs.patch )
461
462 # restart rc.inet1 to have routing for the loop device
463 echo "/etc/rc.d/rc.inet1 restart" >> $rootfs/etc/rc.d/rc.local
464
465 # reduce the number of local consoles: two should be enough
466 sed -i '/^c3\|^c4\|^c5\|^c6/s/^/# /' $rootfs/etc/inittab
467
468 # better not use this in a container
469 sed -i 's/.*genpowerfail.*//' $rootfs/etc/inittab
470
471 # add a message to rc.local that confirms successful container startup
472 echo "echo ; echo \"* container $name started. *\" ; echo" >> $rootfs/etc/rc.d/rc.local
473
474 # borrow the time configuration from the local machine
475 cp -a /etc/localtime $rootfs/etc/localtime
476
477 return 0
478 }
479
480 copy_slackware()
481 {
482 rootfs=$1
483
484 # make a local copy of the installed filesystem
485 echo -n "Copying rootfs to $rootfs..."
486 mkdir -p $rootfs
487 cp -a $cache/rootfs-$release-$arch/* $rootfs/ || exit 1
488
489 # fix fstab with the actual path
490 sed -i "s|$cache/rootfs-$release-$arch|$rootfs|" $rootfs/etc/fstab
491
492 return 0
493 }
494
495 install_slackware()
496 {
497 rootfs=$1
498 mkdir -p /var/lock/subsys/
499 (
500 flock -n -x 9
501 if [ $? -ne 0 ]; then
502 echo "Cache repository is busy."
503 return 1
504 fi
505
506 if [ "$arch" == "x86_64" ]; then
507 PKGMAIN=slackware64
508 elif [ "$arch" == "arm" ]; then
509 PKGMAIN=slackwarearm
510 else
511 PKGMAIN=slackware
512 fi
513
514 export CONF=$cache/slackpkg-conf
515 export ROOT=$cache/rootfs-$release-$arch
516
517 mkdir -p $cache/cache-$release-$arch $cache/rootfs-$release-$arch \
518 $cache/slackpkg-$release-$arch $CONF/templates
519
520 echo "$MIRROR/$PKGMAIN-$release/" > $CONF/mirrors
521 touch $CONF/blacklist
522
523 cat <<EOF > $CONF/slackpkg.conf
524 # v2.8
525 ARCH=$arch
526 TEMP=$cache/cache-$release-$arch
527 WORKDIR=$cache/slackpkg-$release-$arch
528 DELALL=off
529 CHECKMD5=on
530 CHECKGPG=on
531 CHECKSIZE=off
532 PRIORITY=( patches %PKGMAIN extra pasture testing )
533 POSTINST=on
534 ONLY_NEW_DOTNEW=off
535 ONOFF=on
536 DOWNLOAD_ALL=on
537 DIALOG=off
538 BATCH=on
539 DEFAULT_ANSWER=y
540 USE_INCLUDES=on
541 SPINNING=off
542 EOF
543
544 # thanks to Vincent Batts for this list of packages
545 # (that I modified a little :P)
546 # http://connie.slackware.com/~vbatts/minimal/
547 cat <<EOF > $CONF/templates/minimal-lxc.template
548 aaa_base
549 aaa_elflibs
550 aaa_terminfo
551 bash
552 bin
553 bzip2
554 coreutils
555 dhcpcd
556 dialog
557 diffutils
558 e2fsprogs
559 elvis
560 etc
561 findutils
562 gawk
563 glibc-solibs
564 gnupg
565 grep
566 gzip
567 iputils
568 logrotate
569 mpfr
570 net-tools
571 network-scripts
572 ncurses
573 openssh
574 openssl-solibs
575 pkgtools
576 procps-ng
577 sed
578 shadow
579 sharutils
580 slackpkg
581 sysklogd
582 sysvinit
583 sysvinit-functions
584 sysvinit-scripts
585 tar
586 udev
587 util-linux
588 wget
589 which
590 xz
591 EOF
592
593 TEMPLATE=${TEMPLATE:-minimal-lxc}
594 if [ ! "$TEMPLATE" = "minimal-lxc" ]; then
595 if [ -f /etc/slackpkg/templates/$TEMPLATE.template ]; then
596 cat /etc/slackpkg/templates/$TEMPLATE.template \
597 > $CONF/templates/$TEMPLATE.template
598 else
599 TEMPLATE="minimal-lxc"
600 fi
601 fi
602
603 # clean previous installs
604 rm -fR $ROOT/*
605
606 slackpkg -default_answer=n update
607 slackpkg install-template $TEMPLATE
608
609 # add a slackpkg default mirror
610 echo "$MIRROR/$PKGMAIN-$release/" >> $ROOT/etc/slackpkg/mirrors
611
612 # blacklist the devs package (we have to use our premade devices).
613 # do the same with the kernel packages (we use the host's one),
614 # but leave available headers and sources
615 echo "devs" >> $ROOT/etc/slackpkg/blacklist
616 sed -i \
617 -e "s|^#kernel-|kernel-|" \
618 -e "s|^kernel-headers|#kernel-headers|" \
619 -e "s|^kernel-source|#kernel-source|" \
620 $ROOT/etc/slackpkg/blacklist
621
622 # force klog to use the system call interface to the kernel message
623 # buffers - needed for unprivileged containers
624 sed -i 's|3\ \-x|3 -x -s|' $ROOT/etc/rc.d/rc.syslog || true
625
626 return 0
627
628 ) 9>/var/lock/subsys/lxc
629
630 return $?
631 }
632
633 copy_configuration()
634 {
635 path=$1
636 rootfs=$2
637 name=$3
638
639 cat <<EOF >> $path/config
640
641 lxc.uts.name = $name
642 lxc.arch = $arch
643
644 lxc.mount = $rootfs/etc/fstab
645
646 lxc.include = ${LXC_TEMPLATE_CONFIG}/slackware.common.conf
647 EOF
648
649 if [ $? -ne 0 ]; then
650 echo "Failed to add configuration."
651 return 1
652 fi
653
654 return 0
655 }
656
657 clean()
658 {
659 if [ ! -e $cache ]; then
660 exit 0
661 fi
662
663 # lock, so we won't purge while someone is creating a repository
664 (
665 flock -n -x 9
666 if [ $? != 0 ]; then
667 echo "Cache repository is busy."
668 exit 1
669 fi
670
671 echo -n "Purging the download cache..."
672 rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
673 exit 0
674
675 ) 9>/var/lock/subsys/lxc
676 }
677
678 usage()
679 {
680 cat <<EOF
681 $1 -h|--help -p|--path=<path> --clean
682 EOF
683 return 0
684 }
685
686 options=$(getopt -o hp:n:a:r:c -l help,rootfs:,path:,name:,arch:,release:,clean -- "$@")
687 if [ $? -ne 0 ]; then
688 usage $(basename $0)
689 exit 1
690 fi
691 eval set -- "$options"
692
693 while true
694 do
695 case "$1" in
696 -h|--help) usage $0 && exit 0;;
697 -p|--path) path=$2; shift 2;;
698 --rootfs) rootfs=$2; shift 2;;
699 -a|--arch) arch=$2; shift 2;;
700 -r|--release) release=$2; shift 2;;
701 -n|--name) name=$2; shift 2;;
702 -c|--clean) clean=$2; shift 2;;
703 --) shift 1; break ;;
704 *) break ;;
705 esac
706 done
707
708 if [ ! -z "$clean" -a -z "$path" ]; then
709 clean || exit 1
710 exit 0
711 fi
712
713 type installpkg
714 if [ $? -ne 0 ]; then
715 echo "'installpkg' command is missing."
716 exit 1
717 fi
718
719 type slackpkg
720 if [ $? -ne 0 ]; then
721 echo "'slackpkg' command is missing."
722 exit 1
723 fi
724
725 if [ -z "$path" ]; then
726 echo "'path' parameter is required."
727 exit 1
728 fi
729
730 if [ "$(id -u)" != "0" ]; then
731 echo "This script should be run as 'root'."
732 exit 1
733 fi
734
735 # If no release version was specified, use current
736 release=${release:-current}
737
738 if [ -z "$name" ]; then
739 # no name given? set a default one
740 name=slackwarecontainer
741 fi
742
743 # detect rootfs
744 config="$path/config"
745 if [ -z "$rootfs" ]; then
746 if grep -q '^lxc.rootfs.path' $config 2>/dev/null ; then
747 rootfs=$(awk -F= '/^lxc.rootfs.path =/{ print $2 }' $config)
748 else
749 rootfs=$path/rootfs
750 fi
751 fi
752
753 echo
754
755 set -e
756
757 install_slackware $rootfs
758 if [ $? -ne 0 ]; then
759 echo "Failed to install slackware."
760 exit 1
761 fi
762
763 echo
764
765 configure_slackware $cache/rootfs-$release-$arch $name
766 if [ $? -ne 0 ]; then
767 echo "Failed to configure slackware for a container."
768 exit 1
769 fi
770
771 echo
772
773 rootfs=$path/rootfs
774 copy_slackware $rootfs
775 if [ $? -ne 0 ]; then
776 echo "Failed to copy rootfs."
777 exit 1
778 fi
779
780 echo
781
782 copy_configuration $path $rootfs $name
783 if [ $? -ne 0 ]; then
784 echo "Failed to write configuration file."
785 exit 1
786 fi
787
788 if [ ! -z $clean ]; then
789 clean || exit 1
790 exit 0
791 fi