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

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since e50ac20 was e50ac20, checked in by Kris Moore <kris@…>, 16 months ago

Add support to warden CLI for editing and using a custom 'fstab'
for each jail. Will allow us to setup nullfs mounts, among others

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