source: src-sh/warden/scripts/backend/listjails.sh

Last change on this file was 2c39b15, checked in by Kris Moore <kris@…>, 15 months ago

Remove experimental pbibox functionality, not going to be used.

  • Property mode set to 100755
File size: 3.6 KB
Line 
1#!/bin/sh
2# Prints a listing of the installed jails
3######################################################################
4
5# Source our functions
6PROGDIR="/usr/local/share/warden"
7
8# Source our variables
9. ${PROGDIR}/scripts/backend/functions.sh
10
11# Check if we have any jails
12if [ ! -d "${JDIR}" ]
13then
14  echo "Error: No jails found!"
15  exit 4
16fi
17
18line()
19{
20  len="${1}"
21
22  i=0
23  while [ "${i}" -lt "${len}" ] ; do
24    i=`expr ${i} + 1`
25    echo -n '-' 
26  done
27  echo 
28}
29
30lineline=0
31VERBOSE="NO"
32JAILS=
33while [ "$#" -gt "0" ] ; do
34  case "$1" in
35    -v) VERBOSE="YES" ;;
36     *) JAILS="${JAILS} .$1.meta" ;;
37  esac
38  shift
39done
40
41if [ "${VERBOSE}" != "YES" ] ; then
42# Prints a listing of the available jails
43  printf "%-24s%-12s%-12s%-12s\n" ID AUTOSTART STATUS TYPE
44  line "75"
45fi
46
47cd ${JDIR}
48if [ -z "${JAILS}" ] ; then
49  JAILS=`ls -d .*.meta 2>/dev/null`
50fi
51
52for i in ${JAILS}
53do
54  AUTO="Disabled" 
55  STATUS="<unknown>"
56
57  if [ ! -e "${i}/id" ] ; then 
58     # Check if its an old-style jail
59     if [ ! -e "${i}/ip" ] ; then
60        continue
61     fi
62     # This is an old style jail, lets convert it
63     cp ${i}/ip ${i}/ipv4
64     oIP=`cat ${i}/ipv4`
65     echo "${oIP}/24" > ${i}/ipv4
66
67     # Get next unique ID
68     META_ID=0
69     for iDir in `ls -d ${JDIR}/.*.meta 2>/dev/null`
70     do
71       if [ ! -e "${iDir}/id" ] ; then continue ; fi
72       id=`cat ${iDir}/id`
73       if [ "${id}" -gt "${META_ID}" ] ; then
74          META_ID="${id}"
75       fi
76     done
77     : $(( META_ID += 1 ))
78     echo "$META_ID" > ${i}/id
79
80  fi
81
82  ID="`cat ${i}/id 2>/dev/null`"
83  HOST="`cat ${i}/host 2>/dev/null`"
84  if [ -e "${i}/vnet" ] ; then
85    VNET="Enabled"
86  else
87    VNET="Disabled"
88  fi
89
90  #
91  # IPv4 networking
92  #
93  IPS4=
94  IP4=`cat ${i}/ipv4 2>/dev/null`
95  if [ -e "${i}/alias-ipv4" ] ; then
96    while read line
97    do
98      IPS4="${IPS4} ${line}" 
99    done < "${i}/alias-ipv4"
100  fi
101
102  BRIDGEIPS4=
103  BRIDGEIP4=`cat ${i}/bridge-ipv4 2>/dev/null`
104  if [ -e "${i}/alias-bridge-ipv4" ] ; then
105    while read line
106    do
107      BRIDGEIPS4="${BRIDGEIPS4} ${line}" 
108    done < "${i}/alias-bridge-ipv4"
109  fi
110
111  GATEWAY4=`cat ${i}/defaultrouter-ipv4 2>/dev/null`
112
113  #
114  # IPv6 networking
115  #
116  IPS6=
117  IP6=`cat ${i}/ipv6 2>/dev/null`
118  if [ -e "${i}/alias-ipv6" ] ; then
119    while read line
120    do
121      IPS6="${IPS6} ${line}" 
122    done < "${i}/alias-ipv6"
123  fi
124
125  BRIDGEIPS6=
126  BRIDGEIP6=`cat ${i}/bridge-ipv6 2>/dev/null`
127  if [ -e "${i}/alias-bridge-ipv6" ] ; then
128    while read line
129    do
130      BRIDGEIPS6="${BRIDGEIPS6} ${line}" 
131    done < "${i}/alias-bridge-ipv6"
132  fi
133
134  GATEWAY6=`cat ${i}/defaultrouter-ipv6 2>/dev/null`
135
136  # Check if we are autostarting this jail
137  if [ -e "${i}/autostart" ] ; then
138    AUTO="Enabled"
139  fi
140 
141  # Figure out the type of jail
142  if [ -e "${i}/jail-portjail" ] ; then
143    TYPE="portjail"
144  elif [ -e "${i}/jail-pluginjail" ] ; then
145    TYPE="pluginjail"
146  elif [ -e "${i}/jail-linux" ] ; then
147    TYPE="linuxjail"
148  else
149    TYPE="standard"
150  fi
151
152  JAILNAME=`echo ${i}|sed 's|.meta$||'|sed 's|^.||'`
153
154  ${PROGDIR}/scripts/backend/checkstatus.sh ${JAILNAME} 2>/dev/null
155  if [ "$?" = "0" ]
156  then
157    STATUS="Running"
158  else
159    STATUS="Stopped"
160  fi
161
162  if [ "${VERBOSE}" = "YES" ] ; then
163    cat<<__EOF__
164
165id: ${ID}
166host: ${HOST}
167ipv4: ${IP4}
168alias-ipv4: ${IPS4}
169bridge-ipv4: ${BRIDGEIP4}
170alias-bridge-ipv4: ${BRIDGEIPS4}
171defaultrouter-ipv4: ${GATEWAY4}
172ipv6: ${IP6}
173alias-ipv6: ${IPS6}
174bridge-ipv6: ${BRIDGEIP6}
175alias-bridge-ipv6: ${BRIDGEIPS6}
176defaultrouter-ipv6: ${GATEWAY6}
177autostart: ${AUTO}
178vnet: ${VNET}
179status: ${STATUS}
180type: ${TYPE}
181
182__EOF__
183
184  else
185    printf "%-24s%-12s%-12s%-12s\n" ${JAILNAME} ${AUTO} ${STATUS} ${TYPE}
186  fi
187done
188
Note: See TracBrowser for help on using the repository browser.