source: src-sh/warden/bin/warden @ fda1ea4

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since fda1ea4 was fda1ea4, checked in by Kris Moore <kris@…>, 20 months ago

Add --template option to warden create, now you can use any old template
for making a new jail :)

  • Property mode set to 100755
File size: 31.3 KB
Line 
1#!/bin/sh
2# Command-line interaction script for the warden
3# Author: Kris Moore
4# License: BSD
5# "The Warden" Copyright 2013 PC-BSD Software (iXsystems)
6######################################################################
7
8# Source external functions
9. /usr/local/share/pcbsd/scripts/functions.sh
10
11require_root() 
12{
13  UTEST="`whoami`"
14  if [ "$UTEST" != "root" ] ; then
15     exit_err "This command must be run as root!"
16  fi
17}
18
19# Source our functions
20PROGDIR="/usr/local/share/warden"
21
22# Source our variables
23. ${PROGDIR}/scripts/backend/functions.sh
24
25title()
26{
27  echo "Warden version ${WARDENVER}
28---------------------------------"
29};
30
31
32# Function to display help information
33help_main()
34{
35  title
36  echo "Available commands
37
38Type in help <command> for information and usage about that command
39
40         help - This help file"
41
42if [ -e "${PROGDIR}/bin/warden-gui" ] ; then
43   echo "          gui - Launch the GUI menu"
44fi
45
46cat<<__EOF__
47         auto - Toggles the autostart flag for a jail
48      bspkgng - BootStrap pkgng and setup TrueOS repo
49      checkup - Check for updates to a jail
50       chroot - Launches chroot into a jail
51       create - Creates a new jail
52      details - Display usage details about a jail
53       delete - Deletes a jail
54       export - Exports a jail to a .wdn file
55        fstab - Start users \$EDITOR on jails custom fstab
56          get - Gets options list for a jail
57       import - Imports a jail from a .wdn file
58         list - Lists the installed jails
59         pkgs - Lists the installed packages in a jail
60         pbis - Lists the installed pbi's in a jail
61          set - Sets options for a jail
62        start - Start a jail
63         stop - Stops a jail
64         type - Set the jail type (portjail|pluginjail|standard)
65     template - Manage jail templates
66    zfsmksnap - Create a ZFS snapshot of a jail
67 zfslistclone - List clones of jail snapshots
68  zfslistsnap - List snapshots of a jail
69 zfsclonesnap - Clone a jail snapshot
70  zfscronsnap - Schedule snapshot creation via cron
71zfsrevertsnap - Revert jail to a snapshot
72   zfsrmclone - Remove a clone directory
73    zfsrmsnap - Remove snapshot of a jail
74__EOF__
75};
76
77help_get()
78{
79 title
80 echo "Help get
81
82Lets you get options for your jail
83
84Available options:
85
86              ipv4: Lets you see the IPv4 address for this jail
87              ipv6: Lets you see the IPv6 address for this jail
88        alias-ipv4: Lets you see additional IPv4 addresses for this jail
89        alias-ipv6: Lets you see additional IPv6 addresses for this jail
90       bridge-ipv4: Lets you see the vnet bridge IPv4 address for this jail
91       bridge-ipv6: Lets you see the vnet bridge IPv6 address for this jail
92 alias-bridge-ipv4: Lets you see additional vnet bridge IPv4 addresses for this jail
93 alias-bridge-ipv6: Lets you see additional vnet bridge IPv6 addresses for this jail
94defaultrouter-ipv4: Lets you see the default IPv4 router for this jail
95defaultrouter-ipv6: Lets you see the default IPv6 router for this jail
96             flags: Lets you see additional flags to pass to the 'jail' command at startup
97
98Usage:
99
100  warden get ipv4 <Jail>
101
102  warden get flags <Jail>
103
104Example:
105
106  warden get ipv4 myjail
107
108  warden get flags myjail
109"
110};
111
112help_set()
113{
114 title
115 echo "Help set
116
117Lets you set options for your jail
118
119Available options:
120
121              ipv4: Lets you set the IPv4 address for this jail
122              ipv6: Lets you set the IPv6 address for this jail
123        alias-ipv4: Lets you set additional IPv4 addresses for this jail
124        alias-ipv6: Lets you set additional IPv6 addresses for this jail
125       bridge-ipv4: Lets you set the vnet bridge IPv4 address for this jail
126       bridge-ipv6: Lets you set the vnet bridge IPv6 address for this jail
127 alias-bridge-ipv4: Lets you set additional vnet bridge IPv4 addresses for this jail
128 alias-bridge-ipv6: Lets you set additional vnet bridge IPv6 addresses for this jail
129defaultrouter-ipv4: Lets you set the default IPv4 router for this jail
130defaultrouter-ipv6: Lets you set the default IPv6 router for this jail
131        flags: Lets you set additional flags to pass to the 'jail' command at startup
132
133Usage:
134
135  warden set ipv4 <Jail> <IP1>,<IP2>,<IP3>
136
137  warden set flags <Jail> <Flag1>,<Flag2>,<Flag3>
138
139Example:
140
141  warden set ipv4 myjail 192.168.1.50,192.168.2.10
142
143  warden set ipv6 myjail fe80::8e89:a5ff:fe52:ad19,fe80::8e89:a5ff:fe52:ad21
144
145  warden set flags myjail allow.raw_sockets=true,allow.chflags=true
146"
147};
148
149help_checkup()
150{
151 title
152 echo "Help checkup
153
154Check for updates to a jail(s)
155
156Usage:
157
158  warden checkup <Jail>
159   or
160  warden checkup all
161
162Example:
163
164  warden checkup myjail
165"
166};
167
168help_zfslistclone()
169{
170 title
171 echo "Help zfslistclone
172
173List ZFS clones of a jail
174
175Usage:
176
177  warden zfslistclone <Jail>
178
179Example:
180
181  warden zfslistclone myjail
182"
183};
184
185help_zfslistsnap()
186{
187 title
188 echo "Help zfslistsnap
189
190List ZFS snapshots of a jail
191
192Usage:
193
194  warden zfslistsnap <Jail>
195
196Example:
197
198  warden zfslistsnap myjail
199"
200};
201
202help_zfsclonesnap()
203{
204 title
205 echo "Help zfsclonesnap
206
207Clone a ZFS jail snapshot
208
209Usage:
210
211  warden zfsclonesnap <Jail> <SNAP>
212
213Example:
214
215  warden zfsclonesnap myjail 20120505-140510
216"
217};
218
219help_zfscronsnap()
220{
221 title
222 echo "Help zfscronsnap
223
224Schedule a ZFS jail snapshot
225
226Usage:
227
228  warden zfscronsnap <Jail> <action> <frequency> <daysToKeep>
229 
230  action = start / stop
231  frequency = daily / hourly
232  daysToKeep = Number of days to keep snapshots
233
234Example:
235
236  warden zfscronsnap myjail start daily 10
237
238  or
239
240  warden zfscronsnap myjail stop
241"
242};
243
244help_zfsrevertsnap()
245{
246 title
247 echo "Help zfsrevertsnap
248
249Revert ZFS snapshot of a jail
250
251Usage:
252
253  warden zfsrevertsnap <Jail> <SNAP>
254
255Example:
256
257  warden zfsrevertsnap myjail 20120505-140510
258"
259};
260
261help_zfsrmclone()
262{
263 title
264 echo "Help zfsrmclone
265
266Remove ZFS clone of a jail
267
268Usage:
269
270  warden zfsrmclone <Jail> <CLONE>
271
272Example:
273
274  warden zfsrmclone myjail 20120505-140510
275"
276};
277
278help_zfsrmsnap()
279{
280 title
281 echo "Help zfsrmsnap
282
283Remove ZFS snapshot of a jail
284
285Usage:
286
287  warden zfsrmsnap <Jail> <SNAP>
288
289Example:
290
291  warden zfsrmsnap myjail 20120505-140510
292"
293};
294
295
296help_zfsmksnap()
297{
298 title
299 echo "Help zfsmksnap
300
301Create a new ZFS snapshot of a jail
302
303Usage:
304
305  warden zfsmksnap <Jail>
306
307Example:
308
309  warden zfsmksnap myjail
310"
311};
312
313help_details()
314{
315 title
316 echo "Help details
317
318View usage details about a jail
319
320Usage:
321
322  warden details <Jail>
323
324Example:
325
326  warden details myjail
327"
328};
329
330help_template()
331{
332 title
333 echo "Help template
334
335Manage the jail templates used to create new FreeBSD jails
336
337Required subcommands:
338
339  create - Create a new jail template
340  delete - Delete a jail template
341    list - List jail templates on system
342
343Flags:
344
345  create:
346     -fbsd <version>   - FreeBSD Version, 9.1-RELEASE, 9.0-RELEASE, etc
347     -trueos <version> - TrueOS Version, 9-TRUEOS, 10-TRUEOS, etc
348     -arch <arch type> - System architecture, i386/amd64
349     -tar <file>       - Use tar archive as template contents (Ignores -arch / -fbsd)
350     -nick <nickname>  - Template nickname for creating jails / deleting templates
351
352Usage:
353
354  warden template create <flags>
355   or
356  warden template delete <template nickname>
357   or
358  warden template list
359
360Example:
361
362  warden template create -fbsd 9.1-RELEASE -arch amd64 -nick 91amd64
363"
364};
365
366
367help_type()
368{
369 title
370 echo "Help type
371
372Lets you set the type of jail to these options:
373
374portjail: Jail with access to your home directories and Xorg
375pluginjail: Jail that can be used to install FreeNAS plugins
376standard: Normal FreeBSD secure jail environment
377
378The flag status can be checked with 'warden list'.
379
380Usage:
381
382  warden type <Jail> <type>
383
384Example:
385
386  warden type myjail portjail
387"
388};
389
390
391help_bspkgng()
392{
393 title
394 echo "Help bspkgng
395
396BootStraps the pkgng package system, and installs the TrueOS repository
397and utilities into a jail.
398
399Usage:
400
401  warden bspkgng <Jail>
402
403Example:
404
405  warden bspkgng myjail
406"
407};
408
409
410
411help_auto()
412{
413 title
414 echo "Help auto
415
416Toggles the autostart flag for a specified jail. If the flag is
417enabled, then the jail will be started at system bootup automatically.
418The flag status can be checked with 'warden list'.
419
420Usage:
421
422  warden auto <Jail>
423
424Example:
425
426  warden auto myjail
427"
428};
429
430help_pkgs()
431{
432 title
433 echo "Help pkgs
434
435Generates a listing of the installed ports in a jail.
436
437Usage:
438
439  warden pkgs <Jail>
440
441Example:
442
443  warden pkgs myjail
444"
445};
446
447help_pbis()
448{
449 title
450 echo "Help pbis
451
452Generates a listing of the installed pbi's in a jail.
453
454Usage:
455
456  warden pbis <Jail>
457
458Example:
459
460  warden pbis myjail
461"
462};
463
464help_list()
465{
466 title
467 echo "Help list
468
469Generates a quick listing of the installed jails, including the running
470status.
471
472Available Flags:
473  -v           (Verbose listing)
474
475Usage:
476
477  warden list [flags] [hosts]
478"
479};
480
481help_export()
482{
483 title
484 echo "Help export
485
486Export will backup a full copy of your jail, compressing it and
487saving it to a .wdn file. This file can then be taken and
488imported on another system to migrate the jail to new hardware.
489Also a .wdn file may be imported on the same system, in order to
490'clone' an existing jail with a new IP address.
491
492Available Flags:
493  --dir=<DIR>  (Specify the directory you want to place the finished .wdn file)
494
495Usage:
496
497  warden export <Jail> --dir=<path>
498
499Example:
500
501  warden export myjail --dir=/tmp
502"
503};
504
505help_fstab()
506{
507 title
508 echo "Help fstab
509
510Runs the users \$EDITOR on the jails custom fstab file. Can be used to setup
511nullfs mounts and others for a specific jail
512
513Usage:
514
515  warden fstab [hosts]
516"
517};
518
519help_import()
520{
521 title
522 echo "Help import
523
524Imports a jail from a .wdn file. Can assign a new IP / Hostname to
525the imported jail on the fly using optional flags. 
526
527Available Flags:
528  --ipv4=<IP/NETMASK> (Specify a new IPv4/NETMASK address to assign to this jail)
529  --ipv6=<IP/NETMASK> (Specify a new IPv6/NETMASK address to assign to this jail)
530  --host=<HOST>       (Specify a new host name to assign to this jail)
531
532Usage:
533
534  warden import <.wdn file>
535
536Example:
537
538  warden import /home/kris/myjail.wdn
539"
540};
541
542
543
544help_chroot()
545{
546 title
547 echo "Help chroot
548
549Logs into a jail using chroot, or runs the supplied command.
550
551Usage:
552
553  warden chroot <Jail> <optional cmd>
554
555Example:
556
557  warden chroot myjail
558"
559};
560
561
562help_start()
563{
564 title
565 echo "Help start
566
567Starts a stopped jail
568
569Usage:
570
571  warden start <Jail>
572
573Example:
574
575  warden start myjail
576"
577};
578
579help_stop()
580{
581 title
582 echo "Help stop
583
584Stops a running jail
585
586Usage:
587  warden stop <Jail>
588
589Example:
590
591  warden stop myjail
592"
593};
594
595
596help_delete()
597{
598 title
599 echo "Help delete
600
601Stops and deletes a jail
602
603Available Flags:
604  --confirm       (Does not prompt to confirm deletion. DANGEROUS)
605
606Usage:
607
608  warden delete <Jail>
609
610Example:
611
612  warden delete myjail
613"
614};
615
616
617
618help_create()
619{
620 title
621 echo "Help create
622
623Creates a new jail, with options for system source, ports and autostarting.
624
625Available Flags:
626  -32                          (Create 32bit jail on 64bit system)
627  --ipv4 <ip/mask>             (Set primary IPv4 address for jail)
628  --ipv6 <ip/mask>             (Set primary IPv6 address for jail)
629  --src                        (Includes /usr/src system source)
630  --ports                      (Includes the ports tree)
631  --vanilla                    (Don't install PC-BSD pkgng repo and utilities)
632  --startauto                  (Start this jail at system boot)
633  --portjail                   (Make this a portjail)
634  --pluginjail                 (Make this a pluginjail)
635  --linuxjail <script>         (Make this a linux jail and use supplied script for installation)
636  --archive <tar>              (Use specified tar file for BSD jail creation)
637  --linuxarchive <tar>         (Use specified tar file for Linux jail creation)
638  --version <string>           (Use this instead of /etc/version)
639  --template <string>          (Specify a jail template to build with)
640
641Usage:
642
643  warden create <JAILNAME> <flags>
644
645Example:
646
647  warden create jailbird --ipv4 192.168.0.25/24 --src --ports --startauto
648"
649};
650
651
652# Fix old style meta-data, can be removed after 9.1
653fix_old_meta
654
655# Check what the user wants to do
656case "$1" in
657
658   help) case "$2" in
659             auto) help_auto ;;
660          bspkgng) help_bspkgng ;;
661           create) help_create ;;
662           start) help_start ;;
663           stop) help_stop ;;
664           delete) help_delete ;;
665           details) help_details ;;
666           checkup) help_checkup ;;
667           chroot) help_chroot ;;
668           list) help_list ;;
669           export) help_export ;;
670           fstab) help_fstab ;;
671           import) help_import ;;
672           pkgs) help_pkgs ;;
673           pbis) help_pbis ;;
674           template) help_template ;;
675           type) help_type ;;
676           get) help_get ;;
677           set) help_set ;;
678           zfsmksnap) help_zfsmksnap ;;
679           zfslistsnap) help_zfslistsnap ;;
680           zfslistclone) help_zfslistclone ;;
681           zfsrevertsnap) help_zfsrevertsnap ;;
682           zfsclonesnap) help_zfsclonesnap ;;
683           zfscronsnap) help_zfscronsnap ;;
684           zfsrmsnap) help_zfsrmsnap ;;
685           zfsrmclone) help_zfsrmclone ;;
686           *) help_main ;;
687         esac  ;;
688
689
690    pkgs) JAILNAME="${2}"
691         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
692         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
693         set_warden_metadir
694
695         ${PROGDIR}/scripts/backend/listpkgs.sh "${JAILNAME}" 
696         ;;
697details) JAILNAME="${2}"
698         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
699         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
700         set_warden_metadir
701
702         ${PROGDIR}/scripts/backend/details.sh "${JAILNAME}" 
703         ;;
704    pbis) JAILNAME="${2}"
705         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
706         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
707         set_warden_metadir
708
709         ${PROGDIR}/scripts/backend/listpbis.sh "${JAILNAME}" 
710         ;;
711    fstab) JAILNAME="${2}"
712         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
713         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
714         set_warden_metadir
715         if [ ! -e "${JMETADIR}/fstab" ] ; then
716            echo "# Device      Mountpoint      FStype          Options Dump Pass" > ${JMETADIR}/fstab
717         fi
718         if [ -z "$EDITOR" ]; then EDITOR="vi"; fi
719         $EDITOR ${JMETADIR}/fstab
720         exit $?
721         ;;
722template) require_root
723         OPT="$2"
724         case $OPT in
725            create) shift ; shift; ${PROGDIR}/scripts/backend/createtemplate.sh $* ;;
726            delete) delete_template $3 ;;
727              list) list_templates ;;
728                 *) help_template ; exit 1 ;;
729         esac
730         ;;
731    get) require_root
732         OPT="${2}"
733         JAILNAME="${3}"
734         if [ -z "${JAILNAME}" ] ; then exit_err "No jail specified!"; fi
735         if [ ! -e "${JDIR}/${JAILNAME}" ] ; then exit_err "No such jail!"; fi
736         set_warden_metadir
737
738         case $OPT in
739             flags) cat "${JMETADIR}/jail-flags" 2>/dev/null | sed 's| |,|g' ;;
740              ipv4) cat "${JMETADIR}/ipv4"  2>/dev/null | sed 's| |,|g' ;;
741              ipv6) cat "${JMETADIR}/ipv6"  2>/dev/null | sed 's| |,|g' ;;
742        alias-ipv4) cat "${JMETADIR}/alias-ipv4"  2>/dev/null | sed 's| |,|g' ;;
743        alias-ipv6) cat "${JMETADIR}/alias-ipv6"  2>/dev/null | sed 's| |,|g' ;;
744       bridge-ipv4) cat "${JMETADIR}/bridge-ipv4" 2>/dev/null | sed 's| |,|g' ;;
745       bridge-ipv6) cat "${JMETADIR}/bridge-ipv6" 2>/dev/null | sed 's| |,|g' ;;
746 alias-bridge-ipv4) cat "${JMETADIR}/alias-bridge-ipv4" 2>/dev/null | sed 's| |,|g' ;;
747 alias-bridge-ipv6) cat "${JMETADIR}/alias-bridge-ipv6" 2>/dev/null | sed 's| |,|g' ;;
748defaultrouter-ipv4) cat "${JMETADIR}/defaultrouter-ipv4" 2>/dev/null | sed 's| |,|g' ;;
749defaultrouter-ipv6) cat "${JMETADIR}/defaultrouter-ipv6" 2>/dev/null | sed 's| |,|g' ;;
750              *) exit_err "Invalid option!" ;;
751         esac
752         ;;
753
754    set) require_root
755         OPT="${2}" 
756         JAILNAME="${3}"
757         if [ -z "${JAILNAME}" ] ; then exit_err "No jail specified!"; fi
758         if [ ! -e "${JDIR}/${JAILNAME}" ] ; then exit_err "No such jail!"; fi
759         set_warden_metadir
760
761         case $OPT in
762             ipv4) IP4="${4}"
763                 get_ip_and_netmask "${IP4}"
764                 IP4="${JIP}"
765                 MASK4="${JMASK}"
766                 if [ -z "$MASK4" ] ; then MASK4="24"; fi
767                 echo "$IP4/$MASK4" > "${JMETADIR}/ipv4"
768                 ;;
769             ipv6) IP6="${4}"
770                 get_ip_and_netmask "${IP6}"
771                 IP6="${JIP}"
772                 MASK6="${JMASK}"
773                 if [ -z "$MASK6" ] ; then MASK4="64"; fi
774                 echo "$IP6/$MASK6" > "${JMETADIR}/ipv6"
775                 ;;
776       alias-ipv4) EXTRAIPS="${4}"
777                 IPS=`echo $EXTRAIPS | sed 's|,| |g'`
778                 rm "${JMETADIR}/alias-ipv4" >/dev/null 2>/dev/null
779                 for _ip in $IPS
780                 do
781                    echo "$_ip" >> "${JMETADIR}/alias-ipv4"
782                 done
783                ;;
784       alias-ipv6) EXTRAIPS="${4}"
785                 IPS=`echo $EXTRAIPS | sed 's|,| |g'`
786                 rm "${JMETADIR}/alias-ipv6" >/dev/null 2>/dev/null
787                 for _ip in $IPS
788                 do
789                    echo "$_ip" >> "${JMETADIR}/alias-ipv6"
790                 done
791                ;;
792       bridge-ipv4) BIP4="${4}"
793                 echo "$BIP4" > "${JMETADIR}/bridge-ipv4"
794                 ;;
795       bridge-ipv6) BIP6="${4}"
796                 echo "$BIP6" > "${JMETADIR}/bridge-ipv6"
797                 ;;
798 alias-bridge-ipv4) EXTRAIPS="${4}"
799                 IPS=`echo $EXTRAIPS | sed 's|,| |g'`
800                 rm "${JMETADIR}/alias-bridge-ipv4" >/dev/null 2>/dev/null
801                 for _ip in $IPS
802                 do
803                    echo "$_ip" >> "${JMETADIR}/alias-bridge-ipv4"
804                 done
805                ;;
806 alias-bridge-ipv6) EXTRAIPS="${4}"
807                 IPS=`echo $EXTRAIPS | sed 's|,| |g'`
808                 rm "${JMETADIR}/alias-bridge-ipv6" >/dev/null 2>/dev/null
809                 for _ip in $IPS
810                 do
811                    echo "$_ip" >> "${JMETADIR}/alias-bridge-ipv6"
812                 done
813                ;;
814defaultrouter-ipv4) DEFAULTROUTER="${4}"
815                 echo "$DEFAULTROUTER" > "${JMETADIR}/defaultrouter-ipv4"
816                 ;;
817defaultrouter-ipv6) DEFAULTROUTER="${4}"
818                 echo "$DEFAULTROUTER" > "${JMETADIR}/defaultrouter-ipv6"
819                 ;;
820          flags) EXTRAFLAGS="${4}"
821                 echo $EXTRAFLAGS | sed 's|,| |g' > "${JMETADIR}/jail-flags"
822                ;;
823              *) exit_err "Invalid option!" ;;
824           esac
825         ;;
826
827   type) require_root
828         JAILNAME="${2}"
829         TYPE="${3}"
830         JAILDIR="${JDIR}/${JAILNAME}"
831
832         if [ -z "${JAILNAME}" ] ; then exit_err "No jail specified!"; fi
833         if [ ! -e "${JAILDIR}" ] ; then exit_err "No such jail!"; fi
834
835         set_warden_metadir
836         if [ -e "${JMETADIR}/jail-linux" ] ; then exit_err "Cannot change type on Linux jail!"; fi
837
838         case $TYPE in
839           portjail)
840              rm ${JMETADIR}/jail-pluginjail > /dev/null 2>/dev/null
841              mkportjail "${JAILDIR}"
842              ;;
843           standard)
844              rm ${JMETADIR}/jail-pluginjail > /dev/null 2>/dev/null
845              rm ${JMETADIR}/jail-portjail >/dev/null 2>/dev/null
846              ;;
847           pluginjail)
848              mkpluginjail "${JAILDIR}"
849              ;;
850           *) exit_err "Invalid TYPE" ;;
851         esac
852         ;;
853
854 bspkgng) require_root
855    JAILNAME="${2}"
856         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
857         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
858         bootstrap_pkgng "${JDIR}/${JAILNAME}"
859         ;;
860
861   auto) require_root
862         JAILNAME="${2}"
863
864         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
865
866         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
867         set_warden_metadir
868
869         if [ -e "${JMETADIR}/autostart" ]
870         then
871            rm "${JMETADIR}/autostart"
872            echo "Disabled autostart for ${JAILNAME}"
873         else
874            touch "${JMETADIR}/autostart"
875            echo "Enabled autostart for ${JAILNAME}"
876         fi 
877
878         ;;
879
880    gui) require_root
881          ${PROGDIR}/bin/warden-gui ;;
882
883    list) require_root
884        shift
885        ${PROGDIR}/scripts/backend/listjails.sh $* ;;
886   
887   start) require_root
888          # Time to startup the jail
889          JAILNAME="${2}"
890
891          if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
892          if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
893          set_warden_metadir
894         
895          # Check if this jail is already running
896          ${PROGDIR}/scripts/backend/checkstatus.sh "${JAILNAME}"
897          if [ "$?" = "0" ]; then exit_err "This jail is already running!"; fi
898 
899          ${PROGDIR}/scripts/backend/startjail.sh "${JAILNAME}" 
900          ;;
901   stop)  require_root
902          # Time to stop the jail
903          JAILNAME="${2}"
904
905          if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
906          if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
907          set_warden_metadir
908         
909          ${PROGDIR}/scripts/backend/stopjail.sh "${JAILNAME}" 
910          ;;
911
912 checkup) # Log a user into chroot session
913          JAILNAME="${2}"
914
915          if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
916          if [ ! -e "${JDIR}/${JAILNAME}" -a "${JAILNAME}" != "all" ]; then exit_err "No such jail!"; fi
917
918          ${PROGDIR}/scripts/backend/checkupdates.sh "${JAILNAME}"
919          ;;
920
921
922 chroot) # Log a user into chroot session
923          JAILNAME="${2}"
924
925          if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
926          if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
927          set_warden_metadir
928
929          ${PROGDIR}/scripts/backend/chrootjail.sh "${JAILNAME}" "${3}"
930          ;;
931
932 import) require_root
933         # The user wants to import a jail, lets do it!
934         IFILE="$2"
935         if [ ! -e "$IFILE" ]; then exit_err "Invalid filename: ${IFILE}"; fi
936
937         HOST=`basename "${IFILE}" | sed 's|\.wdn$||'`
938
939         IP4="OFF"
940         IP6="OFF"
941         HOST="OFF"
942         for i in "$@"
943         do
944           # Check if we have a new IPv4 address for this import
945           echo "${i}" | grep '\-\-ipv4=' >/dev/null 2>/dev/null
946           if [ "$?" = "0" ]
947           then
948              tmp="`echo ${i} | cut -d '=' -f 2`"
949              IP4="`echo ${tmp} | cut -d '/' -f 1 -s`"
950              MASK4="`echo ${tmp} | cut -d '/' -f 2 -s`"
951
952              #Sanity check on the IP
953              if ! is_ipv4 "${IP4}" ; then
954                 exit_err "Invalid IPv4 address!"
955              fi
956
957              for i in `ls -d ${JDIR}/.*.meta 2>/dev/null`
958              do
959                if [ "`cat ${i}/ipv4 2>/dev/null`" = "${IP4}/${MASK4}" ] ; then
960                  exit_err "A jail with this IPv4 address already exists!"
961                fi
962              done
963           fi
964
965           # Check if we have a new IPv4 address for this import
966           echo "${i}" | grep '\-\-ipv6=' >/dev/null 2>/dev/null
967           if [ "$?" = "0" ]
968           then
969              tmp="`echo ${i} | cut -d '=' -f 2`"
970              IP6="`echo ${tmp} | cut -d '/' -f 1 -s`"
971              MASK6="`echo ${tmp} | cut -d '/' -f 2 -s`"
972
973              #Sanity check on the IP
974              if ! is_ipv6 "${IP6}" ; then
975                 exit_err "Invalid IPv6 address!"
976              fi
977
978              for i in `ls -d ${JDIR}/.*.meta 2>/dev/null`
979              do
980                _ipv6=`cat ${i}/ipv6 2>/dev/null | tr a-z A-Z`
981                _nipv6="`echo ${IP6}|tr a-z A-Z`/${MASK6}"
982               
983                if [ "${_ipv6}" = "${_nipv6}" ] ; then
984                  exit_err "A jail with this IPv6 address already exists!"
985                fi
986              done
987           fi
988 
989           # Check if we have a new hostname for this jail
990           echo ${i} | grep '\-\-host=' >/dev/null 2>/dev/null
991           if [ "$?" = "0" ]
992           then
993              HOST="`echo ${i} | cut -d '=' -f 2`"
994           fi
995
996         done
997
998         if [ "${IP4}" != "OFF" ] ; then
999            IP4="${IP4}/${MASK4}"
1000         fi
1001         if [ "${IP6}" != "OFF" ] ; then
1002            IP6="${IP6}/${MASK6}"
1003         fi
1004
1005         # Import the jail now!
1006         ${PROGDIR}/scripts/backend/importjail.sh "${IFILE}" "${HOST}" "${IP4}" "${IP6}"
1007        ;;
1008
1009 export) require_root
1010         # The user wants to export a jail, lets do it!
1011         JAILNAME="$2"
1012         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1013         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1014         set_warden_metadir
1015
1016         # Check if the user wants to place the file in their own DIR
1017         DIR=""
1018         for i in "$@"
1019         do
1020           echo ${i} | grep "\-\-dir=" >/dev/null 2>/dev/null
1021           if [ "$?" = "0" ]
1022           then
1023              DIR="`echo ${i} | cut -d '=' -f 2`"
1024              # Check if the directory exists
1025              if [ ! -d "${DIR}" ]; then exit_err "No such directory ${DIR}!"; fi
1026           fi
1027
1028         done
1029
1030         # Export the jail now
1031         ${PROGDIR}/scripts/backend/exportjail.sh "${JAILNAME}" "${DIR}"
1032
1033         ;;
1034
1035 zfsmksnap) require_root
1036         JAILNAME="$2"
1037         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1038         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1039         set_warden_metadir
1040         ${PROGDIR}/scripts/backend/zfsmksnap.sh "${JAILNAME}"
1041         ;;
1042
1043 zfslistclone) require_root
1044         JAILNAME="$2"
1045         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1046         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1047         set_warden_metadir
1048         ${PROGDIR}/scripts/backend/zfslistclone.sh "${JAILNAME}"
1049         ;;
1050
1051 zfslistsnap) require_root
1052         JAILNAME="$2"
1053         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1054         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1055         set_warden_metadir
1056         ${PROGDIR}/scripts/backend/zfslistsnap.sh "${JAILNAME}"
1057         ;;
1058
1059 zfsclonesnap) require_root
1060         JAILNAME="$2"
1061         SNAP="$3"
1062         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1063         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1064         set_warden_metadir
1065         ${PROGDIR}/scripts/backend/zfsclonesnap.sh "${JAILNAME}" "${SNAP}"
1066         ;;
1067
1068 zfscronsnap) require_root
1069         JAILNAME="$2"
1070         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1071         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1072         set_warden_metadir
1073         ${PROGDIR}/scripts/backend/zfscronsnap.sh "${JAILNAME}" "$3" "$4" "$5"
1074         ;;
1075
1076
1077 zfsrevertsnap) require_root
1078         JAILNAME="$2"
1079         SNAP="$3"
1080         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1081         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1082         set_warden_metadir
1083         ${PROGDIR}/scripts/backend/zfsrevertsnap.sh "${JAILNAME}" "$SNAP"
1084         ;;
1085
1086 zfsrmclone) require_root
1087         JAILNAME="$2"
1088         CLONE="$3"
1089         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1090         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1091         set_warden_metadir
1092         ${PROGDIR}/scripts/backend/zfsrmclone.sh "${JAILNAME}" "${CLONE}"
1093         ;;
1094
1095 zfsrmsnap) require_root
1096         JAILNAME="$2"
1097         SNAP="$3"
1098         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1099         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1100         set_warden_metadir
1101         ${PROGDIR}/scripts/backend/zfsrmsnap.sh "${JAILNAME}" "${SNAP}"
1102         ;;
1103
1104 create) require_root
1105         # The user wants to create a new jail, do error checking
1106         JAILNAME="$2"
1107         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1108
1109         HOST="$2"
1110
1111         #Now check for the presence of the optional flags
1112         IP4="OFF"
1113         IP6="OFF"
1114         SRC="NO"
1115         PORTS="NO"
1116         AUTOSTART="NO"
1117         VANILLA="NO"
1118         VERSION=
1119         JAILTYPE="standard"
1120         ARCHIVE_FILE= 
1121         while [ $# -gt 0 ]; do
1122           case $1 in
1123             --ipv4) shift
1124                          if [ -z "$1" ] ; then exit_err "No IPv4 address specified!"; fi
1125                          IP4="${1}"
1126                          ;;
1127             --ipv6) shift
1128                          if [ -z "$1" ] ; then exit_err "No IPv6 address specified!"; fi
1129                          IP6="${1}"
1130                          ;;
1131
1132             --src) SRC="YES" ;;
1133             --ports) PORTS="YES" ;;
1134             --startauto) AUTOSTART="YES" ;;
1135             --vanilla) VANILLA="YES" ;;
1136             --portjail) JAILTYPE="portjail" ;;
1137             --pluginjail) JAILTYPE="pluginjail" ; VANILLA="YES" ;;
1138             --linuxjail) JAILTYPE="linuxjail" ; shift
1139                          if [ -z "$1" ] ; then exit_err "No linux setup script specified!"; fi
1140                          LINUX_JAIL_SCRIPT="$1" ; export LINUX_JAIL_SCRIPT
1141                          if [ -n "$LINUXARCHIVE_FILE" ] ; then
1142                             exit_err "--linuxjail and --linuxarchive are mutually exclusive!"
1143                          fi
1144                          ;;
1145                     -32) if [ "$REALARCH" != "amd64" ] ; then
1146                                exit_err "-32 can only be used on amd64 host"
1147                          fi
1148                          ARCH=i386
1149                          export ARCH
1150                          ;;
1151             --archive) shift
1152                          if [ -z "$1" ] ; then exit_err "No archive file specified!"; fi
1153                          ARCHIVE_FILE="$1" ; export ARCHIVE_FILE
1154                          if [ ! -e "$ARCHIVE_FILE" ] ; then
1155                             exit_err "No such file: $ARCHIVE_FILE"
1156                          fi
1157                          ;;
1158             --linuxarchive) JAILTYPE="linuxjail" ; shift
1159                          if [ -z "$1" ] ; then exit_err "No archive file specified!"; fi
1160                          LINUXARCHIVE_FILE="$1" ; export LINUXARCHIVE_FILE
1161                          if [ ! -e "$LINUXARCHIVE_FILE" ] ; then
1162                             exit_err "No such file: $LINUXARCHIVE_FILE"
1163                          fi
1164                          if [ -n "$LINUX_JAIL_SCRIPT" ] ; then
1165                             exit_err "--linuxjail and --linuxarchive are mutually exclusive!"
1166                          fi
1167                          ;;
1168             --version) shift
1169                          if [ -z "$1" ] ; then exit_err "No version string specified!"; fi
1170                          VERSION="${1}"
1171                          ;;
1172             --template) shift
1173                          if [ -z "$1" ] ; then exit_err "No template string specified!"; fi
1174                          isDirZFS "${JDIR}"
1175                          if [ $? -eq 0 ] ; then
1176                             TDIR="${JDIR}/.warden-template-$1"
1177                          else
1178                             TDIR="${JDIR}/.warden-template-$1.tbz"
1179                          fi
1180                          if [ ! -e "$TDIR" ] ; then
1181                             exit_err "Invalid template specified: $1"
1182                          fi
1183                          TEMPLATE="${1}"
1184                          ;;
1185           esac
1186           shift
1187         done
1188
1189         # Check to ensure this jail does not already exist
1190         if [ -e "${JDIR}/${JAILNAME}" ]; then exit_err "A jail with this name already exists!"; fi 
1191
1192          #
1193          # Redonkulous number of parameters that exceeds 9,
1194          # export into environment
1195          #
1196          export IP4
1197          export IP6
1198          export SRC
1199          export PORTS
1200          export AUTOSTART
1201          export JAILTYPE
1202          export ARCHIVE_FILE
1203          export VERSION
1204          export VANILLA
1205          export TEMPLATE
1206
1207          # Passed all tests, create the jail now
1208          ${PROGDIR}/scripts/backend/createjail.sh "${JAILNAME}"
1209
1210        ;;
1211  delete) require_root
1212          # Time to delete a jail
1213          JAILNAME="${2}"
1214
1215          if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1216          if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1217          set_warden_metadir
1218
1219          if [ "$3" != "--confirm" ]
1220          then
1221            echo "Are you sure you want to delete ${JAILNAME}?"
1222            echo -e "Choice: (y/n)\c"
1223            read confirm
1224            if [ "$confirm" != "y" ]; then exit_err "Canceled!"; fi
1225          fi
1226
1227          # Check if this jail is running
1228          ${PROGDIR}/scripts/backend/checkstatus.sh "${JAILNAME}"
1229          if [ "$?" = "0" ] ; then
1230            ${PROGDIR}/scripts/backend/stopjail.sh "${JAILNAME}"
1231          fi
1232
1233          # Check if this jail is STILL running
1234          ${PROGDIR}/scripts/backend/checkstatus.sh "${JAILNAME}"
1235          if [ "$?" = "0" ] ; then exit_err "Jail still is running or has leftovers.."; fi
1236
1237          # Delete it now
1238          ${PROGDIR}/scripts/backend/deletejail.sh "${JAILNAME}"
1239        ;;
1240   *) help_main ;;
1241esac
1242
1243exit 0
Note: See TracBrowser for help on using the repository browser.