source: src-sh/warden/bin/warden @ 80fe156

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

Fix some variable names preventing us from creating new jails

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