source: src-sh/warden/bin/warden @ 1f8e4d7

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

Add initial support for creating new jail templates via the "warden template create"
command-line option

  • Property mode set to 100755
File size: 30.8 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
640Usage:
641
642  warden create <JAILNAME> <flags>
643
644Example:
645
646  warden create jailbird --ipv4 192.168.0.25/24 --src --ports --startauto
647"
648};
649
650
651# Fix old style meta-data, can be removed after 9.1
652fix_old_meta
653
654# Check what the user wants to do
655case "$1" in
656
657   help) case "$2" in
658             auto) help_auto ;;
659          bspkgng) help_bspkgng ;;
660           create) help_create ;;
661           start) help_start ;;
662           stop) help_stop ;;
663           delete) help_delete ;;
664           details) help_details ;;
665           checkup) help_checkup ;;
666           chroot) help_chroot ;;
667           list) help_list ;;
668           export) help_export ;;
669           fstab) help_fstab ;;
670           import) help_import ;;
671           pkgs) help_pkgs ;;
672           pbis) help_pbis ;;
673           template) help_template ;;
674           type) help_type ;;
675           get) help_get ;;
676           set) help_set ;;
677           zfsmksnap) help_zfsmksnap ;;
678           zfslistsnap) help_zfslistsnap ;;
679           zfslistclone) help_zfslistclone ;;
680           zfsrevertsnap) help_zfsrevertsnap ;;
681           zfsclonesnap) help_zfsclonesnap ;;
682           zfscronsnap) help_zfscronsnap ;;
683           zfsrmsnap) help_zfsrmsnap ;;
684           zfsrmclone) help_zfsrmclone ;;
685           *) help_main ;;
686         esac  ;;
687
688
689    pkgs) JAILNAME="${2}"
690         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
691         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
692         set_warden_metadir
693
694         ${PROGDIR}/scripts/backend/listpkgs.sh "${JAILNAME}" 
695         ;;
696details) JAILNAME="${2}"
697         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
698         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
699         set_warden_metadir
700
701         ${PROGDIR}/scripts/backend/details.sh "${JAILNAME}" 
702         ;;
703    pbis) JAILNAME="${2}"
704         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
705         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
706         set_warden_metadir
707
708         ${PROGDIR}/scripts/backend/listpbis.sh "${JAILNAME}" 
709         ;;
710    fstab) JAILNAME="${2}"
711         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
712         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
713         set_warden_metadir
714         if [ ! -e "${JMETADIR}/fstab" ] ; then
715            echo "# Device      Mountpoint      FStype          Options Dump Pass" > ${JMETADIR}/fstab
716         fi
717         if [ -z "$EDITOR" ]; then EDITOR="vi"; fi
718         $EDITOR ${JMETADIR}/fstab
719         exit $?
720         ;;
721template) require_root
722         OPT="$2"
723         case $OPT in
724            create) shift ; shift; ${PROGDIR}/scripts/backend/createtemplate.sh $* ;;
725            delete) delete_template $3 ;;
726              list) list_templates ;;
727                 *) help_template ; exit 1 ;;
728         esac
729         ;;
730    get) require_root
731         OPT="${2}"
732         JAILNAME="${3}"
733         if [ -z "${JAILNAME}" ] ; then exit_err "No jail specified!"; fi
734         if [ ! -e "${JDIR}/${JAILNAME}" ] ; then exit_err "No such jail!"; fi
735         set_warden_metadir
736
737         case $OPT in
738             flags) cat "${JMETADIR}/jail-flags" 2>/dev/null | sed 's| |,|g' ;;
739              ipv4) cat "${JMETADIR}/ipv4"  2>/dev/null | sed 's| |,|g' ;;
740              ipv6) cat "${JMETADIR}/ipv6"  2>/dev/null | sed 's| |,|g' ;;
741        alias-ipv4) cat "${JMETADIR}/alias-ipv4"  2>/dev/null | sed 's| |,|g' ;;
742        alias-ipv6) cat "${JMETADIR}/alias-ipv6"  2>/dev/null | sed 's| |,|g' ;;
743       bridge-ipv4) cat "${JMETADIR}/bridge-ipv4" 2>/dev/null | sed 's| |,|g' ;;
744       bridge-ipv6) cat "${JMETADIR}/bridge-ipv6" 2>/dev/null | sed 's| |,|g' ;;
745 alias-bridge-ipv4) cat "${JMETADIR}/alias-bridge-ipv4" 2>/dev/null | sed 's| |,|g' ;;
746 alias-bridge-ipv6) cat "${JMETADIR}/alias-bridge-ipv6" 2>/dev/null | sed 's| |,|g' ;;
747defaultrouter-ipv4) cat "${JMETADIR}/defaultrouter-ipv4" 2>/dev/null | sed 's| |,|g' ;;
748defaultrouter-ipv6) cat "${JMETADIR}/defaultrouter-ipv6" 2>/dev/null | sed 's| |,|g' ;;
749              *) exit_err "Invalid option!" ;;
750         esac
751         ;;
752
753    set) require_root
754         OPT="${2}" 
755         JAILNAME="${3}"
756         if [ -z "${JAILNAME}" ] ; then exit_err "No jail specified!"; fi
757         if [ ! -e "${JDIR}/${JAILNAME}" ] ; then exit_err "No such jail!"; fi
758         set_warden_metadir
759
760         case $OPT in
761             ipv4) IP4="${4}"
762                 get_ip_and_netmask "${IP4}"
763                 IP4="${JIP}"
764                 MASK4="${JMASK}"
765                 if [ -z "$MASK4" ] ; then MASK4="24"; fi
766                 echo "$IP4/$MASK4" > "${JMETADIR}/ipv4"
767                 ;;
768             ipv6) IP6="${4}"
769                 get_ip_and_netmask "${IP6}"
770                 IP6="${JIP}"
771                 MASK6="${JMASK}"
772                 if [ -z "$MASK6" ] ; then MASK4="64"; fi
773                 echo "$IP6/$MASK6" > "${JMETADIR}/ipv6"
774                 ;;
775       alias-ipv4) EXTRAIPS="${4}"
776                 IPS=`echo $EXTRAIPS | sed 's|,| |g'`
777                 rm "${JMETADIR}/alias-ipv4" >/dev/null 2>/dev/null
778                 for _ip in $IPS
779                 do
780                    echo "$_ip" >> "${JMETADIR}/alias-ipv4"
781                 done
782                ;;
783       alias-ipv6) EXTRAIPS="${4}"
784                 IPS=`echo $EXTRAIPS | sed 's|,| |g'`
785                 rm "${JMETADIR}/alias-ipv6" >/dev/null 2>/dev/null
786                 for _ip in $IPS
787                 do
788                    echo "$_ip" >> "${JMETADIR}/alias-ipv6"
789                 done
790                ;;
791       bridge-ipv4) BIP4="${4}"
792                 echo "$BIP4" > "${JMETADIR}/bridge-ipv4"
793                 ;;
794       bridge-ipv6) BIP6="${4}"
795                 echo "$BIP6" > "${JMETADIR}/bridge-ipv6"
796                 ;;
797 alias-bridge-ipv4) EXTRAIPS="${4}"
798                 IPS=`echo $EXTRAIPS | sed 's|,| |g'`
799                 rm "${JMETADIR}/alias-bridge-ipv4" >/dev/null 2>/dev/null
800                 for _ip in $IPS
801                 do
802                    echo "$_ip" >> "${JMETADIR}/alias-bridge-ipv4"
803                 done
804                ;;
805 alias-bridge-ipv6) EXTRAIPS="${4}"
806                 IPS=`echo $EXTRAIPS | sed 's|,| |g'`
807                 rm "${JMETADIR}/alias-bridge-ipv6" >/dev/null 2>/dev/null
808                 for _ip in $IPS
809                 do
810                    echo "$_ip" >> "${JMETADIR}/alias-bridge-ipv6"
811                 done
812                ;;
813defaultrouter-ipv4) DEFAULTROUTER="${4}"
814                 echo "$DEFAULTROUTER" > "${JMETADIR}/defaultrouter-ipv4"
815                 ;;
816defaultrouter-ipv6) DEFAULTROUTER="${4}"
817                 echo "$DEFAULTROUTER" > "${JMETADIR}/defaultrouter-ipv6"
818                 ;;
819          flags) EXTRAFLAGS="${4}"
820                 echo $EXTRAFLAGS | sed 's|,| |g' > "${JMETADIR}/jail-flags"
821                ;;
822              *) exit_err "Invalid option!" ;;
823           esac
824         ;;
825
826   type) require_root
827         JAILNAME="${2}"
828         TYPE="${3}"
829         JAILDIR="${JDIR}/${JAILNAME}"
830
831         if [ -z "${JAILNAME}" ] ; then exit_err "No jail specified!"; fi
832         if [ ! -e "${JAILDIR}" ] ; then exit_err "No such jail!"; fi
833
834         set_warden_metadir
835         if [ -e "${JMETADIR}/jail-linux" ] ; then exit_err "Cannot change type on Linux jail!"; fi
836
837         case $TYPE in
838           portjail)
839              rm ${JMETADIR}/jail-pluginjail > /dev/null 2>/dev/null
840              mkportjail "${JAILDIR}"
841              ;;
842           standard)
843              rm ${JMETADIR}/jail-pluginjail > /dev/null 2>/dev/null
844              rm ${JMETADIR}/jail-portjail >/dev/null 2>/dev/null
845              ;;
846           pluginjail)
847              mkpluginjail "${JAILDIR}"
848              ;;
849           *) exit_err "Invalid TYPE" ;;
850         esac
851         ;;
852
853 bspkgng) require_root
854    JAILNAME="${2}"
855         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
856         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
857         bootstrap_pkgng "${JDIR}/${JAILNAME}"
858         ;;
859
860   auto) require_root
861         JAILNAME="${2}"
862
863         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
864
865         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
866         set_warden_metadir
867
868         if [ -e "${JMETADIR}/autostart" ]
869         then
870            rm "${JMETADIR}/autostart"
871            echo "Disabled autostart for ${JAILNAME}"
872         else
873            touch "${JMETADIR}/autostart"
874            echo "Enabled autostart for ${JAILNAME}"
875         fi 
876
877         ;;
878
879    gui) require_root
880          ${PROGDIR}/bin/warden-gui ;;
881
882    list) require_root
883        shift
884        ${PROGDIR}/scripts/backend/listjails.sh $* ;;
885   
886   start) require_root
887          # Time to startup the jail
888          JAILNAME="${2}"
889
890          if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
891          if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
892          set_warden_metadir
893         
894          # Check if this jail is already running
895          ${PROGDIR}/scripts/backend/checkstatus.sh "${JAILNAME}"
896          if [ "$?" = "0" ]; then exit_err "This jail is already running!"; fi
897 
898          ${PROGDIR}/scripts/backend/startjail.sh "${JAILNAME}" 
899          ;;
900   stop)  require_root
901          # Time to stop the jail
902          JAILNAME="${2}"
903
904          if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
905          if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
906          set_warden_metadir
907         
908          ${PROGDIR}/scripts/backend/stopjail.sh "${JAILNAME}" 
909          ;;
910
911 checkup) # Log a user into chroot session
912          JAILNAME="${2}"
913
914          if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
915          if [ ! -e "${JDIR}/${JAILNAME}" -a "${JAILNAME}" != "all" ]; then exit_err "No such jail!"; fi
916
917          ${PROGDIR}/scripts/backend/checkupdates.sh "${JAILNAME}"
918          ;;
919
920
921 chroot) # Log a user into chroot session
922          JAILNAME="${2}"
923
924          if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
925          if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
926          set_warden_metadir
927
928          ${PROGDIR}/scripts/backend/chrootjail.sh "${JAILNAME}" "${3}"
929          ;;
930
931 import) require_root
932         # The user wants to import a jail, lets do it!
933         IFILE="$2"
934         if [ ! -e "$IFILE" ]; then exit_err "Invalid filename: ${IFILE}"; fi
935
936         HOST=`basename "${IFILE}" | sed 's|\.wdn$||'`
937
938         IP4="OFF"
939         IP6="OFF"
940         HOST="OFF"
941         for i in "$@"
942         do
943           # Check if we have a new IPv4 address for this import
944           echo "${i}" | grep '\-\-ipv4=' >/dev/null 2>/dev/null
945           if [ "$?" = "0" ]
946           then
947              tmp="`echo ${i} | cut -d '=' -f 2`"
948              IP4="`echo ${tmp} | cut -d '/' -f 1 -s`"
949              MASK4="`echo ${tmp} | cut -d '/' -f 2 -s`"
950
951              #Sanity check on the IP
952              if ! is_ipv4 "${IP4}" ; then
953                 exit_err "Invalid IPv4 address!"
954              fi
955
956              for i in `ls -d ${JDIR}/.*.meta 2>/dev/null`
957              do
958                if [ "`cat ${i}/ipv4 2>/dev/null`" = "${IP4}/${MASK4}" ] ; then
959                  exit_err "A jail with this IPv4 address already exists!"
960                fi
961              done
962           fi
963
964           # Check if we have a new IPv4 address for this import
965           echo "${i}" | grep '\-\-ipv6=' >/dev/null 2>/dev/null
966           if [ "$?" = "0" ]
967           then
968              tmp="`echo ${i} | cut -d '=' -f 2`"
969              IP6="`echo ${tmp} | cut -d '/' -f 1 -s`"
970              MASK6="`echo ${tmp} | cut -d '/' -f 2 -s`"
971
972              #Sanity check on the IP
973              if ! is_ipv6 "${IP6}" ; then
974                 exit_err "Invalid IPv6 address!"
975              fi
976
977              for i in `ls -d ${JDIR}/.*.meta 2>/dev/null`
978              do
979                _ipv6=`cat ${i}/ipv6 2>/dev/null | tr a-z A-Z`
980                _nipv6="`echo ${IP6}|tr a-z A-Z`/${MASK6}"
981               
982                if [ "${_ipv6}" = "${_nipv6}" ] ; then
983                  exit_err "A jail with this IPv6 address already exists!"
984                fi
985              done
986           fi
987 
988           # Check if we have a new hostname for this jail
989           echo ${i} | grep '\-\-host=' >/dev/null 2>/dev/null
990           if [ "$?" = "0" ]
991           then
992              HOST="`echo ${i} | cut -d '=' -f 2`"
993           fi
994
995         done
996
997         if [ "${IP4}" != "OFF" ] ; then
998            IP4="${IP4}/${MASK4}"
999         fi
1000         if [ "${IP6}" != "OFF" ] ; then
1001            IP6="${IP6}/${MASK6}"
1002         fi
1003
1004         # Import the jail now!
1005         ${PROGDIR}/scripts/backend/importjail.sh "${IFILE}" "${HOST}" "${IP4}" "${IP6}"
1006        ;;
1007
1008 export) require_root
1009         # The user wants to export a jail, lets do it!
1010         JAILNAME="$2"
1011         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1012         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1013         set_warden_metadir
1014
1015         # Check if the user wants to place the file in their own DIR
1016         DIR=""
1017         for i in "$@"
1018         do
1019           echo ${i} | grep "\-\-dir=" >/dev/null 2>/dev/null
1020           if [ "$?" = "0" ]
1021           then
1022              DIR="`echo ${i} | cut -d '=' -f 2`"
1023              # Check if the directory exists
1024              if [ ! -d "${DIR}" ]; then exit_err "No such directory ${DIR}!"; fi
1025           fi
1026
1027         done
1028
1029         # Export the jail now
1030         ${PROGDIR}/scripts/backend/exportjail.sh "${JAILNAME}" "${DIR}"
1031
1032         ;;
1033
1034 zfsmksnap) require_root
1035         JAILNAME="$2"
1036         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1037         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1038         set_warden_metadir
1039         ${PROGDIR}/scripts/backend/zfsmksnap.sh "${JAILNAME}"
1040         ;;
1041
1042 zfslistclone) require_root
1043         JAILNAME="$2"
1044         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1045         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1046         set_warden_metadir
1047         ${PROGDIR}/scripts/backend/zfslistclone.sh "${JAILNAME}"
1048         ;;
1049
1050 zfslistsnap) require_root
1051         JAILNAME="$2"
1052         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1053         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1054         set_warden_metadir
1055         ${PROGDIR}/scripts/backend/zfslistsnap.sh "${JAILNAME}"
1056         ;;
1057
1058 zfsclonesnap) require_root
1059         JAILNAME="$2"
1060         SNAP="$3"
1061         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1062         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1063         set_warden_metadir
1064         ${PROGDIR}/scripts/backend/zfsclonesnap.sh "${JAILNAME}" "${SNAP}"
1065         ;;
1066
1067 zfscronsnap) require_root
1068         JAILNAME="$2"
1069         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1070         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1071         set_warden_metadir
1072         ${PROGDIR}/scripts/backend/zfscronsnap.sh "${JAILNAME}" "$3" "$4" "$5"
1073         ;;
1074
1075
1076 zfsrevertsnap) require_root
1077         JAILNAME="$2"
1078         SNAP="$3"
1079         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1080         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1081         set_warden_metadir
1082         ${PROGDIR}/scripts/backend/zfsrevertsnap.sh "${JAILNAME}" "$SNAP"
1083         ;;
1084
1085 zfsrmclone) require_root
1086         JAILNAME="$2"
1087         CLONE="$3"
1088         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1089         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1090         set_warden_metadir
1091         ${PROGDIR}/scripts/backend/zfsrmclone.sh "${JAILNAME}" "${CLONE}"
1092         ;;
1093
1094 zfsrmsnap) require_root
1095         JAILNAME="$2"
1096         SNAP="$3"
1097         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1098         if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1099         set_warden_metadir
1100         ${PROGDIR}/scripts/backend/zfsrmsnap.sh "${JAILNAME}" "${SNAP}"
1101         ;;
1102
1103 create) require_root
1104         # The user wants to create a new jail, do error checking
1105         JAILNAME="$2"
1106         if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1107
1108         HOST="$2"
1109
1110         #Now check for the presence of the optional flags
1111         IP4="OFF"
1112         IP6="OFF"
1113         SRC="NO"
1114         PORTS="NO"
1115         AUTOSTART="NO"
1116         VANILLA="NO"
1117         VERSION=
1118         JAILTYPE="standard"
1119         ARCHIVE_FILE= 
1120         while [ $# -gt 0 ]; do
1121           case $1 in
1122             --ipv4) shift
1123                          if [ -z "$1" ] ; then exit_err "No IPv4 address specified!"; fi
1124                          IP4="${1}"
1125                          ;;
1126             --ipv6) shift
1127                          if [ -z "$1" ] ; then exit_err "No IPv6 address specified!"; fi
1128                          IP6="${1}"
1129                          ;;
1130
1131             --src) SRC="YES" ;;
1132             --ports) PORTS="YES" ;;
1133             --startauto) AUTOSTART="YES" ;;
1134             --vanilla) VANILLA="YES" ;;
1135             --portjail) JAILTYPE="portjail" ;;
1136             --pluginjail) JAILTYPE="pluginjail" ; VANILLA="YES" ;;
1137             --linuxjail) JAILTYPE="linuxjail" ; shift
1138                          if [ -z "$1" ] ; then exit_err "No linux setup script specified!"; fi
1139                          LINUX_JAIL_SCRIPT="$1" ; export LINUX_JAIL_SCRIPT
1140                          if [ -n "$LINUXARCHIVE_FILE" ] ; then
1141                             exit_err "--linuxjail and --linuxarchive are mutually exclusive!"
1142                          fi
1143                          ;;
1144                     -32) if [ "$REALARCH" != "amd64" ] ; then
1145                                exit_err "-32 can only be used on amd64 host"
1146                          fi
1147                          ARCH=i386
1148                          export ARCH
1149                          ;;
1150             --archive) shift
1151                          if [ -z "$1" ] ; then exit_err "No archive file specified!"; fi
1152                          ARCHIVE_FILE="$1" ; export ARCHIVE_FILE
1153                          if [ ! -e "$ARCHIVE_FILE" ] ; then
1154                             exit_err "No such file: $ARCHIVE_FILE"
1155                          fi
1156                          ;;
1157             --linuxarchive) JAILTYPE="linuxjail" ; shift
1158                          if [ -z "$1" ] ; then exit_err "No archive file specified!"; fi
1159                          LINUXARCHIVE_FILE="$1" ; export LINUXARCHIVE_FILE
1160                          if [ ! -e "$LINUXARCHIVE_FILE" ] ; then
1161                             exit_err "No such file: $LINUXARCHIVE_FILE"
1162                          fi
1163                          if [ -n "$LINUX_JAIL_SCRIPT" ] ; then
1164                             exit_err "--linuxjail and --linuxarchive are mutually exclusive!"
1165                          fi
1166                          ;;
1167             --version) shift
1168                          if [ -z "$1" ] ; then exit_err "No version string specified!"; fi
1169                          VERSION="${1}"
1170                          ;;
1171           esac
1172           shift
1173         done
1174
1175         # Check to ensure this jail does not already exist
1176         if [ -e "${JDIR}/${JAILNAME}" ]; then exit_err "A jail with this name already exists!"; fi 
1177
1178          #
1179          # Redonkulous number of parameters that exceeds 9,
1180          # export into environment
1181          #
1182          export IP4
1183          export IP6
1184          export SRC
1185          export PORTS
1186          export AUTOSTART
1187          export JAILTYPE
1188          export ARCHIVE_FILE
1189          export VERSION
1190          export VANILLA
1191
1192          # Passed all tests, create the jail now
1193          ${PROGDIR}/scripts/backend/createjail.sh "${JAILNAME}"
1194
1195        ;;
1196  delete) require_root
1197          # Time to delete a jail
1198          JAILNAME="${2}"
1199
1200          if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
1201          if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
1202          set_warden_metadir
1203
1204          if [ "$3" != "--confirm" ]
1205          then
1206            echo "Are you sure you want to delete ${JAILNAME}?"
1207            echo -e "Choice: (y/n)\c"
1208            read confirm
1209            if [ "$confirm" != "y" ]; then exit_err "Canceled!"; fi
1210          fi
1211
1212          # Check if this jail is running
1213          ${PROGDIR}/scripts/backend/checkstatus.sh "${JAILNAME}"
1214          if [ "$?" = "0" ] ; then
1215            ${PROGDIR}/scripts/backend/stopjail.sh "${JAILNAME}"
1216          fi
1217
1218          # Check if this jail is STILL running
1219          ${PROGDIR}/scripts/backend/checkstatus.sh "${JAILNAME}"
1220          if [ "$?" = "0" ] ; then exit_err "Jail still is running or has leftovers.."; fi
1221
1222          # Delete it now
1223          ${PROGDIR}/scripts/backend/deletejail.sh "${JAILNAME}"
1224        ;;
1225   *) help_main ;;
1226esac
1227
1228exit 0
Note: See TracBrowser for help on using the repository browser.