source: src-sh/warden/bin/warden @ 58a4795

releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 58a4795 was 58a4795, checked in by Kris Moore <kris@…>, 11 months ago

Fix some bugs importing jails via the Warden GUI, in particular when we try to set a new
ipv4 address.

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