summaryrefslogtreecommitdiff
path: root/usr/src/cmd
diff options
context:
space:
mode:
authorJohn Levon <john.levon@joyent.com>2019-08-01 13:52:59 +0000
committerJohn Levon <john.levon@joyent.com>2019-08-01 13:52:59 +0000
commitd0ca2b08e18a06d653279357d3fa022c0e12b0bf (patch)
treee092c37e6937874abecc2e7dc42246c53651b188 /usr/src/cmd
parent7f874eb65f07035e3f808d58a70ad712248fde0a (diff)
downloadillumos-joyent-d0ca2b08e18a06d653279357d3fa022c0e12b0bf.tar.gz
OS-7685 smartos-live overlay should be merged into illumos-joyent
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Mike Gerdts <mike.gerdts@joyent.com> Approved by: Mike Gerdts <mike.gerdts@joyent.com>
Diffstat (limited to 'usr/src/cmd')
-rw-r--r--usr/src/cmd/Adm/sun/Makefile33
-rw-r--r--usr/src/cmd/Adm/sun/issue.in14
-rw-r--r--usr/src/cmd/auditd/auditd.xml6
-rw-r--r--usr/src/cmd/cmd-crypto/etc/pkcs11.conf2
-rw-r--r--usr/src/cmd/cmd-inet/etc/services701
-rw-r--r--usr/src/cmd/coreadm/coreadm.xml16
-rw-r--r--usr/src/cmd/cron/Makefile23
-rw-r--r--usr/src/cmd/cron/crontab.root18
-rw-r--r--usr/src/cmd/cron/svc-cron42
-rw-r--r--usr/src/cmd/dispadmin/Makefile32
-rw-r--r--usr/src/cmd/dispadmin/dispadmin.conf1
-rw-r--r--usr/src/cmd/dumpadm/Makefile9
-rw-r--r--usr/src/cmd/dumpadm/dumpadm.conf11
-rw-r--r--usr/src/cmd/init/init.dfl3
-rw-r--r--usr/src/cmd/ipf/etc/Makefile27
-rw-r--r--usr/src/cmd/ipf/etc/smartos_version1
-rw-r--r--usr/src/cmd/ipf/svc/ipfilter20
-rw-r--r--usr/src/cmd/ipf/svc/ipfilter.xml7
-rw-r--r--usr/src/cmd/localedef/Makefile10
-rw-r--r--usr/src/cmd/localedef/UTF-8.x114
-rw-r--r--usr/src/cmd/logadm/logadm.conf11
-rw-r--r--usr/src/cmd/login/login.dfl17
-rw-r--r--usr/src/cmd/netfiles/Makefile4
-rw-r--r--usr/src/cmd/netfiles/nsswitch.conf4
-rw-r--r--usr/src/cmd/netfiles/resolv.conf0
-rw-r--r--usr/src/cmd/nsadmin/Makefile78
-rwxr-xr-xusr/src/cmd/nsadmin/bash/bash_completion9417
-rw-r--r--usr/src/cmd/nsadmin/bash/bash_completion.d/dladm34
-rw-r--r--usr/src/cmd/nsadmin/bash/bash_completion.d/machines19
-rw-r--r--usr/src/cmd/nsadmin/bash/bash_completion.d/vms62
-rw-r--r--usr/src/cmd/nsadmin/bash/bash_completion.d/zones41
-rw-r--r--usr/src/cmd/nsadmin/bashrc.sh5
-rw-r--r--usr/src/cmd/nsadmin/dot-bash_profile.sh12
-rw-r--r--usr/src/cmd/nsadmin/dot-bashrc.sh57
-rw-r--r--usr/src/cmd/nsadmin/dot-profile.sh20
-rw-r--r--usr/src/cmd/nsadmin/etc-profile.sh24
-rw-r--r--usr/src/cmd/nsadmin/etc-skel-bashrc.sh7
-rw-r--r--usr/src/cmd/nsadmin/system68
-rw-r--r--usr/src/cmd/nsadmin/zshrc31
-rw-r--r--usr/src/cmd/svc/milestone/Makefile19
-rw-r--r--usr/src/cmd/svc/milestone/console-login40
-rwxr-xr-xusr/src/cmd/svc/milestone/fs-joyent288
-rw-r--r--usr/src/cmd/svc/milestone/fs-root98
-rw-r--r--usr/src/cmd/svc/milestone/fs-usr155
-rw-r--r--usr/src/cmd/svc/milestone/identity-node150
-rw-r--r--usr/src/cmd/svc/milestone/joyent-fs.xml85
-rw-r--r--usr/src/cmd/svc/milestone/make-console-login-xml41
-rw-r--r--usr/src/cmd/svc/milestone/manifest-import31
-rwxr-xr-xusr/src/cmd/svc/milestone/mdata-execute53
-rwxr-xr-xusr/src/cmd/svc/milestone/mdata-fetch477
-rw-r--r--usr/src/cmd/svc/milestone/mdata.xml39
-rw-r--r--usr/src/cmd/svc/milestone/minimal-fs.xml4
-rw-r--r--usr/src/cmd/svc/milestone/net-early-admin214
-rw-r--r--usr/src/cmd/svc/milestone/net-physical1244
-rw-r--r--usr/src/cmd/svc/milestone/network-early-admin.xml73
-rw-r--r--usr/src/cmd/svc/milestone/network-location.xml10
-rw-r--r--usr/src/cmd/svc/milestone/network-physical.xml110
-rwxr-xr-xusr/src/cmd/svc/milestone/smartdc-config211
-rw-r--r--usr/src/cmd/svc/milestone/smartdc-config.xml145
-rwxr-xr-xusr/src/cmd/svc/milestone/smartdc-init246
-rw-r--r--usr/src/cmd/svc/milestone/smartdc-init.xml124
-rwxr-xr-xusr/src/cmd/svc/milestone/smartdc-ur79
-rw-r--r--usr/src/cmd/svc/milestone/smartdc-ur.xml62
-rwxr-xr-xusr/src/cmd/svc/milestone/sysidtool-net5
-rwxr-xr-xusr/src/cmd/svc/milestone/sysidtool-system5
-rw-r--r--usr/src/cmd/svc/profile/Makefile6
-rw-r--r--usr/src/cmd/svc/profile/generic.xml392
-rw-r--r--usr/src/cmd/syslogd/syslog.conf4
-rw-r--r--usr/src/cmd/syslogd/system-log102
-rw-r--r--usr/src/cmd/zoneadm/svc-resource-mgmt14
-rw-r--r--usr/src/cmd/zoneadm/svc-zones141
71 files changed, 14486 insertions, 1182 deletions
diff --git a/usr/src/cmd/Adm/sun/Makefile b/usr/src/cmd/Adm/sun/Makefile
index db3cd6c931..e249952dcc 100644
--- a/usr/src/cmd/Adm/sun/Makefile
+++ b/usr/src/cmd/Adm/sun/Makefile
@@ -21,9 +21,11 @@
#
# Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2010 Nexenta Systems, Inc. All rights reserved.
+# Copyright 2019 Joyent, Inc.
#
-ETCFILES= ioctl.syscon passwd shadow motd
+ETCGENFILES=motd issue
+ETCFILES= ioctl.syscon passwd shadow $(ETCGENFILES)
FTPDFILES= ftpusers
KVMFILES= README
SMBFILES= smbpasswd
@@ -39,41 +41,32 @@ FILEMODE= 0644
ROOTETCFTPUSERSLINK= $(ROOTETC)/ftpusers
-$(ROOTETC)/shadow := FILEMODE = 400
+$(ROOTETC)/shadow := FILEMODE = 400
$(ROOTVARSMB)/smbpasswd := FILEMODE = 0400
.KEEP_STATE:
-$(ROOTETCFTPUSERSLINK): $(ROOTETCFTPDFILES)
- $(RM) $@; $(SYMLINK) ftpd/ftpusers $@
-
all: $(ETCFILES) $(KVMFILES) $(SMBFILES) $(FTPDFILES)
install: all $(ROOTETCFILES) $(ROOTETCFTPDFILES) $(ROOTUSRKVMFILES) $(ROOTVARSMBFILES) $(ROOTETCFTPUSERSLINK)
clean:
- $(RM) $(ROOTETCFTPUSERSLINK)
+ $(RM) $(ROOTETCFTPUSERSLINK) $(ETCGENFILES) $(SMBFILES)
-lint:
+clobber: clean
-clobber:
+$(ROOTETCFTPUSERSLINK): $(ROOTETCFTPDFILES)
+ $(RM) $@; $(SYMLINK) ftpd/ftpusers $@
-motd: FRC
+motd: $(ROOT)/buildstamp
@-$(ECHO) "rebuilding motd"
- @$(RELEASE_BUILD)-$(ECHO) "The Illumos Project\tSunOS $(RELEASE)\t$(VERSION)\t$(RELEASE_DATE)" > motd
- @$(NOT_RELEASE_BUILD)-$(ECHO) "The Illumos Project\tSunOS $(RELEASE)\t$(VERSION)\t`date +'%h. %d, %Y'`" > motd
- @$(NOT_RELEASE_BUILD)-$(ECHO) $(DEV_CM) | sed -e "s/@(#)//" >> motd
- @-$(CAT) release_info >> motd
+ @$(ECHO) "SmartOS (build: $$(cat $(ROOT)/buildstamp))" >$@
+
+issue: issue.in $(ROOT)/buildstamp
+ sed "s+build: 00000000T000000Z+$$(cat $(ROOT)/buildstamp)+" issue.in >$@
smbpasswd:
$(TOUCH) smbpasswd
-clean:
-
-lint:
-
-clobber:
- $(RM) motd smbpasswd
-
FRC:
diff --git a/usr/src/cmd/Adm/sun/issue.in b/usr/src/cmd/Adm/sun/issue.in
new file mode 100644
index 0000000000..d9957b7a0d
--- /dev/null
+++ b/usr/src/cmd/Adm/sun/issue.in
@@ -0,0 +1,14 @@
+
+
+ *--+--*--*
+ |\ |\ |\ |\ J O Y E N T
+ | \| \| \| \ ##### #### # ##### ### # # TM
+ +--*--+--*--* # # # # # # # ## #
+ |\ |\ |\ |\ | # #### # # # # # # #
+ | \| \| \| \| # # # # # # # # ##
+ *--+--+--+--+ # # # # # ### # #
+ \ |\ |\ |\ |
+ \| \| \| \| SmartOS
+ *--+--*--* build: 00000000T000000Z
+
+
diff --git a/usr/src/cmd/auditd/auditd.xml b/usr/src/cmd/auditd/auditd.xml
index 88632647f5..ac0600c9e1 100644
--- a/usr/src/cmd/auditd/auditd.xml
+++ b/usr/src/cmd/auditd/auditd.xml
@@ -142,7 +142,7 @@
-->
<property_group name='preselection' type='application'>
<propval name='flags' type='astring'
- value='lo' />
+ value='lo,ex' />
<propval name='naflags' type='astring'
value='lo' />
<propval name='read_authorization' type='astring'
@@ -188,7 +188,7 @@
<propval name='arge' type='boolean'
value='false' />
<propval name='argv' type='boolean'
- value='false' />
+ value='true' />
<propval name='cnt' type='boolean'
value='true' />
<propval name='group' type='boolean'
@@ -196,7 +196,7 @@
<propval name='path' type='boolean'
value='false' />
<propval name='perzone' type='boolean'
- value='false' />
+ value='true' />
<propval name='public' type='boolean'
value='false' />
<propval name='seq' type='boolean'
diff --git a/usr/src/cmd/cmd-crypto/etc/pkcs11.conf b/usr/src/cmd/cmd-crypto/etc/pkcs11.conf
index 2b8971a85e..835e61f777 100644
--- a/usr/src/cmd/cmd-crypto/etc/pkcs11.conf
+++ b/usr/src/cmd/cmd-crypto/etc/pkcs11.conf
@@ -20,6 +20,7 @@
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
+# Copyright 2011 Joyent, Inc. All rights reserved.
#
# /etc/crypto/pkcs11.conf
#
@@ -39,5 +40,4 @@
metaslot:metaslot_status=enabled;metaslot_auto_key_migrate=enabled;metaslot_token=Sun Software PKCS#11 softtoken;metaslot_slot=Sun Crypto Softtoken
/usr/lib/security/$ISA/pkcs11_kernel.so
/usr/lib/security/$ISA/pkcs11_softtoken.so
-/usr/lib/security/$ISA/pkcs11_tpm.so
# End SUNWcsr
diff --git a/usr/src/cmd/cmd-inet/etc/services b/usr/src/cmd/cmd-inet/etc/services
index 25ccc7cc43..1029745480 100644
--- a/usr/src/cmd/cmd-inet/etc/services
+++ b/usr/src/cmd/cmd-inet/etc/services
@@ -1,7 +1,6 @@
-#
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
-# Copyright 2015 Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
#
# CDDL HEADER START
#
@@ -23,9 +22,18 @@
# CDDL HEADER END
#
# Network services, Internet style
-# Look at http://www.iana.org/assignments/port-numbers for more
#
-tcpmux 1/tcp
+# Note that it is presently the policy of IANA to assign a single well-known
+# port number for both TCP and UDP; hence, officially ports have two entries
+# even if the protocol doesn't support UDP operations.
+#
+# Updated from http://www.iana.org/assignments/port-numbers and other
+# sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services .
+# New ports will be added on request if they have been officially assigned
+# by IANA and used in the real-world or are needed by a debian package.
+# If you need a huge list of used numbers please install the nmap package.
+
+tcpmux 1/tcp # TCP port service multiplexer
echo 7/tcp
echo 7/udp
discard 9/tcp sink null
@@ -34,209 +42,614 @@ systat 11/tcp users
daytime 13/tcp
daytime 13/udp
netstat 15/tcp
-qotd 17/tcp # Quote of the Day
+qotd 17/tcp quote
+msp 18/tcp # message send protocol
+msp 18/udp
chargen 19/tcp ttytst source
chargen 19/udp ttytst source
ftp-data 20/tcp
ftp 21/tcp
ftp 21/sctp
-ssh 22/tcp # Secure Shell
+fsp 21/udp fspd
+ssh 22/tcp # SSH Remote Login Protocol
ssh 22/sctp
+ssh 22/udp
telnet 23/tcp
smtp 25/tcp mail
time 37/tcp timserver
time 37/udp timserver
rlp 39/tcp # Resource Location Protocol
-rlp 39/udp # Resource Location Protocol
-name 42/udp nameserver
-whois 43/tcp nicname # usually to sri-nic
-tacacs 49/tcp
+rlp 39/udp resource # resource location
+nameserver 42/tcp name # IEN 116
+nameserver 42/udp name
+whois 43/tcp nicname
+tacacs 49/tcp # Login Host Protocol (TACACS)
tacacs 49/udp
+re-mail-ck 50/tcp # Remote Mail Checking Protocol
+re-mail-ck 50/udp
+domain 53/tcp # name-domain server
domain 53/udp
-domain 53/tcp
-tacacs-ds 65/tcp
+mtp 57/tcp # deprecated
+tacacs-ds 65/tcp # TACACS-Database Service
tacacs-ds 65/udp
-bootps 67/udp # BOOTP/DHCP server
-bootpc 68/udp # BOOTP/DHCP client
-http 80/tcp www www-http
-http 80/udp www www-http
-http 80/sctp
-kerberos 88/udp kdc # Kerberos V5 KDC
-kerberos 88/tcp kdc # Kerberos V5 KDC
-hostnames 101/tcp hostname # usually to sri-nic
-pop2 109/tcp pop-2 # Post Office Protocol - V2
-pop3 110/tcp # Post Office Protocol - Version 3
-sunrpc 111/udp rpcbind
-sunrpc 111/tcp rpcbind
+bootps 67/tcp # BOOTP server
+bootps 67/udp
+bootpc 68/tcp # BOOTP client
+bootpc 68/udp
+tftp 69/udp
+gopher 70/tcp # Internet Gopher
+gopher 70/udp
+rje 77/tcp netrjs
+finger 79/tcp
+www 80/tcp http # WorldWideWeb HTTP
+www 80/sctp http
+www 80/udp # HyperText Transfer Protocol
+link 87/tcp ttylink
+kerberos 88/tcp kerberos5 krb5 kerberos-sec # Kerberos v5
+kerberos 88/udp kerberos5 krb5 kerberos-sec # Kerberos v5
+supdup 95/tcp
+hostnames 101/tcp hostname # usually from sri-nic
+iso-tsap 102/tcp tsap # part of ISODE
+x400 103/tcp # ISO Mail
+acr-nema 104/tcp dicom # Digital Imag. & Comm. 300
+acr-nema 104/udp dicom # Digital Imag. & Comm. 300
+csnet-ns 105/tcp cso-ns # also used by CSO name server
+csnet-ns 105/udp cso-ns
+rtelnet 107/tcp # Remote Telnet
+rtelnet 107/udp
+pop2 109/tcp postoffice pop-2 # POP version 2
+pop2 109/udp pop-2
+pop3 110/tcp pop-3 # POP version 3
+pop3 110/udp pop-3
+sunrpc 111/tcp portmapper # RPC 4.0 portmapper
+sunrpc 111/udp portmapper
+auth 113/tcp authentication tap ident
sftp 115/tcp
-imap 143/tcp imap2 # Internet Mail Access Protocol v2
+uucp-path 117/tcp
+nntp 119/tcp readnews untp # USENET News Transfer Protocol
+ntp 123/tcp
+ntp 123/udp # Network Time Protocol
+pwdgen 129/tcp # PWDGEN service
+pwdgen 129/udp # PWDGEN service
+loc-srv 135/tcp epmap # Location Service
+loc-srv 135/udp epmap
+netbios-ns 137/tcp # NETBIOS Name Service
+netbios-ns 137/udp
+netbios-dgm 138/tcp # NETBIOS Datagram Service
+netbios-dgm 138/udp
+netbios-ssn 139/tcp # NETBIOS session service
+netbios-ssn 139/udp
+imap2 143/tcp imap # Interim Mail Access P 2 and 4
+imap2 143/udp imap
+snmp 161/tcp # Simple Net Mgmt Protocol
+snmp 161/udp # Simple Net Mgmt Protocol
+snmp-trap 162/tcp snmptrap # Traps for SNMP
+snmp-trap 162/udp snmptrap # Traps for SNMP
+cmip-man 163/tcp # ISO mgmt over IP (CMOT)
+cmip-man 163/udp
+cmip-agent 164/tcp
+cmip-agent 164/udp
+mailq 174/tcp # Mailer transport queue for Zmailer
+mailq 174/udp # Mailer transport queue for Zmailer
+xdmcp 177/tcp # X Display Mgr. Control Proto
+xdmcp 177/udp
+nextstep 178/tcp NeXTStep NextStep # NeXTStep window
+nextstep 178/udp NeXTStep NextStep # server
bgp 179/tcp # Border Gateway Protocol
-bgp 179/udp
bgp 179/sctp
-irc 194/tcp
+bgp 179/udp
+prospero 191/tcp # Cliff Neuman's Prospero
+prospero 191/udp
+irc 194/tcp # Internet Relay Chat
irc 194/udp
-smux 199/tcp
+smux 199/tcp # SNMP Unix Multiplexer
smux 199/udp
-imap3 220/tcp
-imap3 220/udp
-clearcase 371/tcp
-clearcase 371/udp
-ldap 389/tcp # Lightweight Directory Access Protocol
-ldap 389/udp # Lightweight Directory Access Protocol
-https 443/tcp
+at-rtmp 201/tcp # AppleTalk routing
+at-rtmp 201/udp
+at-nbp 202/tcp # AppleTalk name binding
+at-nbp 202/udp
+at-echo 204/tcp # AppleTalk echo
+at-echo 204/udp
+at-zis 206/tcp # AppleTalk zone information
+at-zis 206/udp
+qmtp 209/tcp # Quick Mail Transfer Protocol
+qmtp 209/udp # Quick Mail Transfer Protocol
+z3950 210/tcp wais # NISO Z39.50 database
+z3950 210/udp wais
+ipx 213/tcp # IPX
+ipx 213/udp
+imap3 220/tcp # Interactive Mail Access
+imap3 220/udp # Protocol v3
+pawserv 345/tcp # Perf Analysis Workbench
+pawserv 345/udp
+zserv 346/tcp # Zebra server
+zserv 346/udp
+fatserv 347/tcp # Fatmen Server
+fatserv 347/udp
+rpc2portmap 369/tcp
+rpc2portmap 369/udp # Coda portmapper
+codaauth2 370/tcp
+codaauth2 370/udp # Coda authentication server
+clearcase 371/tcp Clearcase
+clearcase 371/udp Clearcase
+ulistserv 372/tcp # UNIX Listserv
+ulistserv 372/udp
+ldap 389/tcp # Lightweight Directory Access Protocol
+ldap 389/udp
+imsp 406/tcp # Interactive Mail Support Protocol
+imsp 406/udp
+slp 427/tcp slp # Service Location Protocol, V2
+slp 427/udp slp # Service Location Protocol, V2
+mobile-ip 434/udp mobile-ip # Mobile-IP
+cvc_hostd 442/tcp # Network Console
+https 443/tcp # http protocol over TLS/SSL
https 443/udp
https 443/sctp
+snpp 444/tcp # Simple Network Paging Protocol
+snpp 444/udp
+microsoft-ds 445/tcp # Microsoft Naked CIFS
+microsoft-ds 445/udp
kpasswd 464/tcp
kpasswd 464/udp
+saft 487/tcp # Simple Asynchronous File Transfer
+saft 487/udp
+isakmp 500/tcp # IPsec - Internet Security Association
+isakmp 500/udp # and Key Management Protocol
dhcpv6-client 546/udp dhcpv6c # DHCPv6 Client (RFC 3315)
dhcpv6-client 546/tcp
dhcpv6-server 547/udp dhcpv6s # DHCPv6 Server (RFC 3315)
dhcpv6-server 547/tcp
-rtsp 554/tcp
-rtsp 554/udp
-nntps 563/tcp snntp
-nntps 563/udp snntp
-submission 587/tcp # Mail Message Submission
-submission 587/udp # see RFC 2476
-ipp 631/tcp
+rtsp 554/tcp # Real Time Stream Control Protocol
+rtsp 554/udp # Real Time Stream Control Protocol
+nqs 607/tcp # Network Queuing system
+nqs 607/udp
+npmp-local 610/tcp dqs313_qmaster # npmp-local / DQS
+npmp-local 610/udp dqs313_qmaster
+npmp-gui 611/tcp dqs313_execd # npmp-gui / DQS
+npmp-gui 611/udp dqs313_execd
+hmmp-ind 612/tcp dqs313_intercell # HMMP Indication / DQS
+hmmp-ind 612/udp dqs313_intercell
+qmqp 628/tcp
+qmqp 628/udp
+ipp 631/tcp # Internet Printing Protocol
ipp 631/udp
-ldaps 636/tcp # LDAP protocol over TLS/SSL (was sldap)
-ldaps 636/udp # LDAP protocol over TLS/SSL (was sldap)
-silc 706/tcp
-silc 706/udp
-iscsi 860/tcp
-iscsi 860/udp
-rsync 873/tcp
-rsync 873/udp
-ftps-data 989/tcp
-ftps-data 989/udp
-ftps 990/tcp
-ftps 990/udp
-imaps 993/tcp
-imaps 993/udp
-pop3s 995/tcp
-pop3s 995/udp
-socks 1080/tcp
-socks 1080/udp
-openvpn 1194/tcp
-openvpn 1194/udp
-icap 1344/tcp # Internet Content Adaptation Protocol
-wins 1512/tcp
-wins 1512/udp
-radius 1812/tcp
-radius 1812/udp
-radius-acct 1813/tcp
-radius-acct 1813/udp
-cvspserver 2401/tcp
-icpv2 3130/tcp
-icpv2 3130/udp
-iscsi-target 3260/tcp
-iscsi-target 3260/udp
-mysql 3306/tcp
-mysql 3306/udp
-nut 3493/tcp # Network UPS Tools
-svn 3690/tcp
-svn 3690/udp
-epmd 4369/tcp # Erlang Port Mapper Daemon
-epmd 4369/udp
-sip 5060/tcp
-sip 5060/udp
-sip-tls 5061/tcp
-sip-tls 5061/udp
-xmpp-client 5222/tcp
-xmpp-server 5269/tcp
-postgresql 5432/tcp postgres
-postgresql 5432/udp postgres
-http-alt 8080/tcp webcache # HTTP Alternate, webcache
-http-alt 8080/udp
-memcache 11211/tcp
-memcache 11211/udp
-#
-# Host specific functions
-#
-tftp 69/udp
-rje 77/tcp
-finger 79/tcp
-link 87/tcp ttylink
-supdup 95/tcp
-iso-tsap 102/tcp
-x400 103/tcp # ISO Mail
-x400-snd 104/tcp
-csnet-ns 105/tcp
-uucp-path 117/tcp
-nntp 119/tcp usenet # Network News Transfer
-ntp 123/tcp # Network Time Protocol
-ntp 123/udp # Network Time Protocol
-netbios-ns 137/tcp # NETBIOS Name Service
-netbios-ns 137/udp # NETBIOS Name Service
-netbios-dgm 138/tcp # NETBIOS Datagram Service
-netbios-dgm 138/udp # NETBIOS Datagram Service
-netbios-ssn 139/tcp # NETBIOS Session Service
-netbios-ssn 139/udp # NETBIOS Session Service
-NeWS 144/tcp news # Window System
-snmpd 161/udp snmp # Net-SNMP snmp daemon
-slp 427/tcp slp # Service Location Protocol, V2
-slp 427/udp slp # Service Location Protocol, V2
-mobile-ip 434/udp mobile-ip # Mobile-IP
-cvc_hostd 442/tcp # Network Console
-microsoft-ds 445/tcp # Microsoft Directory Services
-microsoft-ds 445/udp # Microsoft Directory Services
-ike 500/udp ike # Internet Key Exchange
uuidgen 697/tcp # UUID Generator
uuidgen 697/udp # UUID Generator
#
# UNIX specific services
#
-# these are NOT officially assigned
-#
rdc 121/tcp # SNDR server daemon
exec 512/tcp
-login 513/tcp
-shell 514/tcp cmd # no passwords used
-printer 515/tcp spooler # line printer spooler
-courier 530/tcp rpc # experimental
-uucp 540/tcp uucpd # uucp daemon
biff 512/udp comsat
+login 513/tcp
who 513/udp whod
+shell 514/tcp cmd # no passwords used
syslog 514/udp
+printer 515/tcp spooler # line printer spooler
talk 517/udp
-route 520/udp router routed
+ntalk 518/udp
+route 520/udp router routed # RIP
ripng 521/udp
-klogin 543/tcp # Kerberos authenticated rlogin
-kshell 544/tcp cmd # Kerberos authenticated remote shell
+timed 525/udp timeserver
+tempo 526/tcp newdate
+courier 530/tcp rpc
+conference 531/tcp chat
+netnews 532/tcp readnews
+netwall 533/udp # for emergency broadcasts
+gdomap 538/tcp # GNUstep distributed objects
+gdomap 538/udp
+uucp 540/tcp uucpd # uucp daemon
+klogin 543/tcp # Kerberized `rlogin' (v5)
+kshell 544/tcp krcmd # Kerberized `rsh' (v5)
+afpovertcp 548/tcp # AFP over TCP
+afpovertcp 548/udp
new-rwho 550/udp new-who # experimental
+remotefs 556/tcp rfs_server rfs # Brunhoff remote filesystem
rmonitor 560/udp rmonitord # experimental
monitor 561/udp # experimental
+nntps 563/tcp snntp # NNTP over SSL
+nntps 563/udp snntp
+submission 587/tcp # Submission [RFC4409]
+submission 587/udp
pcserver 600/tcp # ECD Integrated PC board srvr
+ldaps 636/tcp # LDAP over SSL
+ldaps 636/udp
+tinc 655/tcp # tinc control port
+tinc 655/udp
sun-dr 665/tcp # Remote Dynamic Reconfiguration
-kerberos-adm 749/tcp # Kerberos V5 Administration
+silc 706/tcp
+silc 706/udp
+kerberos-adm 749/tcp # Kerberos `kadmin' (v5)
kerberos-adm 749/udp # Kerberos V5 Administration
kerberos-iv 750/udp # Kerberos V4 key server
krb5_prop 754/tcp # Kerberos V5 KDC propogation
-swat 901/tcp # Samba Web Adm.Tool
+#
+webster 765/tcp # Network dictionary
+webster 765/udp
+iscsi 860/tcp
+iscsi 860/udp
+rsync 873/tcp
+rsync 873/udp
+ftps-data 989/tcp # FTP over SSL (data)
+ftps 990/tcp
+telnets 992/tcp # Telnet over SSL
+telnets 992/udp
+imaps 993/tcp # IMAP over SSL
+imaps 993/udp
+ircs 994/tcp # IRC over SSL
+ircs 994/udp
+pop3s 995/tcp # POP-3 over SSL
+pop3s 995/udp
ufsd 1008/tcp ufsd # UFS-aware server
ufsd 1008/udp ufsd
portolan 1296/tcp # Portolan
svp-underlay 1339/tcp # SDC VXLAN underlay invalidation
cvc 1495/tcp # Network Console
+#
+# From ``Assigned Numbers'':
+#
+#> The Registered Ports are not controlled by the IANA and on most systems
+#> can be used by ordinary user processes or programs executed by ordinary
+#> users.
+#
+#> Ports are used in the TCP [45,106] to name the ends of logical
+#> connections which carry long term conversations. For the purpose of
+#> providing services to unknown callers, a service contact port is
+#> defined. This list specifies the port used by the server process as its
+#> contact port. While the IANA can not control uses of these ports it
+#> does register or list uses of these ports as a convienence to the
+#> community.
+#
+socks 1080/tcp # socks proxy server
+socks 1080/udp
+proofd 1093/tcp
+proofd 1093/udp
+rootd 1094/tcp
+rootd 1094/udp
+openvpn 1194/tcp
+openvpn 1194/udp
+rmiregistry 1099/tcp # Java RMI Registry
+rmiregistry 1099/udp
+kazaa 1214/tcp
+kazaa 1214/udp
+nessus 1241/tcp # Nessus vulnerability
+nessus 1241/udp # assessment scanner
+icap 1344/tcp # Internet Content Adaptation Protocol
+lotusnote 1352/tcp lotusnotes # Lotus Note
+lotusnote 1352/udp lotusnotes
+ms-sql-s 1433/tcp # Microsoft SQL Server
+ms-sql-s 1433/udp
+ms-sql-m 1434/tcp # Microsoft SQL Monitor
+ms-sql-m 1434/udp
+wins 1512/tcp
+wins 1512/udp
ingreslock 1524/tcp
+ingreslock 1524/udp
+prospero-np 1525/tcp # Prospero non-privileged
+prospero-np 1525/udp
+datametrics 1645/tcp old-radius
+datametrics 1645/udp old-radius
+sa-msg-port 1646/tcp old-radacct
+sa-msg-port 1646/udp old-radacct
+kermit 1649/tcp
+kermit 1649/udp
+l2f 1701/tcp l2tp
+l2f 1701/udp l2tp
www-ldap-gw 1760/tcp # HTTP to LDAP gateway
www-ldap-gw 1760/udp # HTTP to LDAP gateway
-listen 2766/tcp # System V listener port
-nfsd 2049/udp nfs # NFS server daemon (clts)
-nfsd 2049/tcp nfs # NFS server daemon (cots)
+radius 1812/tcp
+radius 1812/udp
+radius-acct 1813/tcp radacct # Radius Accounting
+radius-acct 1813/udp radacct
+msnp 1863/tcp # MSN Messenger
+msnp 1863/udp
+unix-status 1957/tcp # remstats unix-status server
+log-server 1958/tcp # remstats log server
+remoteping 1959/tcp # remstats remoteping server
+cisco-sccp 2000/tcp sieve # Cisco SCCP
+cisco-sccp 2000/udp
+search 2010/tcp ndtp
+pipe_server 2010/tcp
+nfs 2049/tcp # Network File System
+nfs 2049/udp # Network File System
nfsd 2049/sctp nfs
-eklogin 2105/tcp # Kerberos encrypted rlogin
+gnunet 2086/tcp
+gnunet 2086/udp
+rtcm-sc104 2101/tcp # RTCM SC-104 IANA 1/29/99
+rtcm-sc104 2101/udp
+gsigatekeeper 2119/tcp
+gsigatekeeper 2119/udp
+gris 2135/tcp # Grid Resource Information Server
+gris 2135/udp # Grid Resource Information Server
+cvspserver 2401/tcp # CVS client/server operations
+cvspserver 2401/udp
+venus 2430/tcp # codacon port
+venus 2430/udp # Venus callback/wbc interface
+venus-se 2431/tcp # tcp side effects
+venus-se 2431/udp # udp sftp side effect
+codasrv 2432/tcp # not used
+codasrv 2432/udp # server port
+codasrv-se 2433/tcp # tcp side effects
+codasrv-se 2433/udp # udp sftp side effect
+mon 2583/tcp # MON traps
+mon 2583/udp
+dict 2628/tcp # Dictionary server
+dict 2628/udp
+listen 2766/tcp # System V listener port
+gsiftp 2811/tcp
+gsiftp 2811/udp
+gpsd 2947/tcp
+gpsd 2947/udp
+gds_db 3050/tcp # InterBase server
+gds_db 3050/udp
+icpv2 3130/tcp icp # Internet Cache Protocol
+icpv2 3130/udp icp
+iscsi-target 3260/tcp
+iscsi-target 3260/udp
+mysql 3306/tcp
+mysql 3306/udp
+nut 3493/tcp # Network UPS Tools
+nut 3493/udp
+distcc 3632/tcp # distributed compiler
+distcc 3632/udp
+daap 3689/tcp # Digital Audio Access Protocol
+daap 3689/udp
+svn 3690/tcp subversion # Subversion protocol
+svn 3690/udp subversion
+suucp 4031/tcp # UUCP over SSL
+suucp 4031/udp # UUCP over SSL
lockd 4045/udp # NFS lock daemon/manager
lockd 4045/tcp
+sysrqd 4094/tcp # sysrq daemon
+sysrqd 4094/udp # sysrq daemon
+remctl 4373/tcp # Remote Authenticated Command Service
+remctl 4373/udp # Remote Authenticated Command Service
+epmd 4369/tcp # Erlang Port Mapper Daemon
+epmd 4369/udp
ipsec-nat-t 4500/udp # IPsec NAT-Traversal
+iax 4569/tcp # Inter-Asterisk eXchange
+iax 4569/udp
+radmin-port 4899/tcp # RAdmin Port
+radmin-port 4899/udp
+rfe 5002/udp # Radio Free Ethernet
+rfe 5002/tcp
+mmcc 5050/tcp # multimedia conference control tool (Yahoo IM)
+mmcc 5050/udp
+sip 5060/tcp # Session Initiation Protocol
+sip 5060/udp
+sip-tls 5061/tcp
+sip-tls 5061/udp
+aol 5190/tcp # AIM
+aol 5190/udp
+xmpp-client 5222/tcp jabber-client # Jabber Client Connection
+xmpp-client 5222/udp jabber-client
+xmpp-server 5269/tcp jabber-server # Jabber Server Connection
+xmpp-server 5269/udp jabber-server
+cfengine 5308/tcp
+cfengine 5308/udp
+mdns 5353/tcp # Multicast DNS
mdns 5353/udp # Multicast DNS
-mdns 5353/tcp
+postgresql 5432/tcp postgres # PostgreSQL Database
+postgresql 5432/udp postgres
+freeciv 5556/tcp rptp # Freeciv gameplay
+freeciv 5556/udp
+amqp 5672/tcp
+amqp 5672/udp
+amqp 5672/sctp
+ggz 5688/tcp # GGZ Gaming Zone
+ggz 5688/udp # GGZ Gaming Zone
vnc-server 5900/tcp # VNC Server
+x11 6000/tcp x11-0 # X Window System
+x11 6000/udp x11-0
+x11-1 6001/tcp
+x11-1 6001/udp
+x11-2 6002/tcp
+x11-2 6002/udp
+x11-3 6003/tcp
+x11-3 6003/udp
+x11-4 6004/tcp
+x11-4 6004/udp
+x11-5 6005/tcp
+x11-5 6005/udp
+x11-6 6006/tcp
+x11-6 6006/udp
+x11-7 6007/tcp
+x11-7 6007/udp
dtspc 6112/tcp # CDE subprocess control
+gnutella-svc 6346/tcp # gnutella
+gnutella-svc 6346/udp
+gnutella-rtr 6347/tcp # gnutella
+gnutella-rtr 6347/udp
+sge_qmaster 6444/tcp # Grid Engine Qmaster Service
+sge_qmaster 6444/udp # Grid Engine Qmaster Service
+sge_execd 6445/tcp # Grid Engine Execution Service
+sge_execd 6445/udp # Grid Engine Execution Service
servicetag 6481/udp
servicetag 6481/tcp
-fs 7100/tcp # Font server
+afs3-fileserver 7000/tcp bbs # file server itself
+afs3-fileserver 7000/udp bbs
+afs3-callback 7001/tcp # callbacks to cache managers
+afs3-callback 7001/udp
+afs3-prserver 7002/tcp # users & groups database
+afs3-prserver 7002/udp
+afs3-vlserver 7003/tcp # volume location database
+afs3-vlserver 7003/udp
+afs3-kaserver 7004/tcp # AFS/Kerberos authentication
+afs3-kaserver 7004/udp
+afs3-volser 7005/tcp # volume managment server
+afs3-volser 7005/udp
+afs3-errors 7006/tcp # error interpretation service
+afs3-errors 7006/udp
+afs3-bos 7007/tcp # basic overseer process
+afs3-bos 7007/udp
+afs3-update 7008/tcp # server-to-server updater
+afs3-update 7008/udp
+afs3-rmtsys 7009/tcp # remote cache manager service
+afs3-rmtsys 7009/udp
+font-service 7100/tcp xfs # X Font Service
+font-service 7100/udp xfs
+http-alt 8080/tcp webcache # WWW caching service
+http-alt 8080/udp # WWW caching service
+bacula-dir 9101/tcp # Bacula Director
+bacula-dir 9101/udp
+bacula-fd 9102/tcp # Bacula File Daemon
+bacula-fd 9102/udp
+bacula-sd 9103/tcp # Bacula Storage Daemon
+bacula-sd 9103/udp
+xmms2 9667/tcp # Cross-platform Music Multiplexing System
+xmms2 9667/udp # Cross-platform Music Multiplexing System
+amanda 10080/tcp # amanda backup services
+amanda 10080/udp
+memcache 11211/tcp
+memcache 11211/udp
+hkp 11371/tcp # OpenPGP HTTP Keyserver
+hkp 11371/udp # OpenPGP HTTP Keyserver
+bprd 13720/tcp # VERITAS NetBackup
+bprd 13720/udp
+bpdbm 13721/tcp # VERITAS NetBackup
+bpdbm 13721/udp
+bpjava-msvc 13722/tcp # BP Java MSVC Protocol
+bpjava-msvc 13722/udp
+vnetd 13724/tcp # Veritas Network Utility
+vnetd 13724/udp
+bpcd 13782/tcp # VERITAS NetBackup
+bpcd 13782/udp
+vopied 13783/tcp # VERITAS NetBackup
+vopied 13783/udp
solaris-audit 16162/tcp # Secure remote audit logging
-wnn6 22273/tcp # Wnn6 jserver
-wnn6 22273/udp # Wnn6 jserver
+wnn6 22273/tcp # wnn6
+wnn6 22273/udp
+
+#
+# Datagram Delivery Protocol services
+#
+rtmp 1/ddp # Routing Table Maintenance Protocol
+nbp 2/ddp # Name Binding Protocol
+echo 4/ddp # AppleTalk Echo Protocol
+zip 6/ddp # Zone Information Protocol
+
+#=========================================================================
+# The remaining port numbers are not as allocated by IANA.
+#=========================================================================
+
+# Kerberos (Project Athena/MIT) services
+# Note that these are for Kerberos v4, and are unofficial. Sites running
+# v4 should uncomment these and comment out the v5 entries above.
+#
+kerberos4 750/udp kerberos-iv kdc # Kerberos (server)
+kerberos4 750/tcp kerberos-iv kdc
+kerberos_master 751/udp # Kerberos authentication
+kerberos_master 751/tcp
+passwd_server 752/udp # Kerberos passwd server
+krb_prop 754/tcp krb5_prop hprop # Kerberos slave propagation
+krbupdate 760/tcp kreg # Kerberos registration
+swat 901/tcp # swat
+kpop 1109/tcp # Pop with Kerberos
+knetd 2053/tcp # Kerberos de-multiplexor
+zephyr-srv 2102/udp # Zephyr server
+zephyr-clt 2103/udp # Zephyr serv-hm connection
+zephyr-hm 2104/udp # Zephyr hostmanager
+eklogin 2105/tcp # Kerberos encrypted rlogin
+# Hmmm. Are we using Kv4 or Kv5 now? Worrying.
+# The following is probably Kerberos v5 --- ajt@debian.org (11/02/2000)
+kx 2111/tcp # X over Kerberos
+iprop 2121/tcp # incremental propagation
+#
+# Unofficial but necessary (for NetBSD) services
+#
+supfilesrv 871/tcp # SUP server
+supfiledbg 1127/tcp # SUP debugging
+
+#
+# Services added for the Debian GNU/Linux distribution
+#
+linuxconf 98/tcp # LinuxConf
+poppassd 106/tcp # Eudora
+poppassd 106/udp
+ssmtp 465/tcp smtps # SMTP over SSL
+moira_db 775/tcp # Moira database
+moira_update 777/tcp # Moira update protocol
+moira_ureg 779/udp # Moira user registration
+spamd 783/tcp # spamassassin daemon
+omirr 808/tcp omirrd # online mirror
+omirr 808/udp omirrd
+customs 1001/tcp # pmake customs server
+customs 1001/udp
+skkserv 1178/tcp # skk jisho server port
+predict 1210/udp # predict -- satellite tracking
+rmtcfg 1236/tcp # Gracilis Packeten remote config server
+wipld 1300/tcp # Wipl network monitor
+xtel 1313/tcp # french minitel
+xtelw 1314/tcp # french minitel
+support 1529/tcp # GNATS
+cfinger 2003/tcp # GNU Finger
+frox 2121/tcp # frox: caching ftp proxy
+ninstall 2150/tcp # ninstall service
+ninstall 2150/udp
+zebrasrv 2600/tcp # zebra service
+zebra 2601/tcp # zebra vty
+ripd 2602/tcp # ripd vty (zebra)
+ripngd 2603/tcp # ripngd vty (zebra)
+ospfd 2604/tcp # ospfd vty (zebra)
+bgpd 2605/tcp # bgpd vty (zebra)
+ospf6d 2606/tcp # ospf6d vty (zebra)
+ospfapi 2607/tcp # OSPF-API
+isisd 2608/tcp # ISISd vty (zebra)
+afbackup 2988/tcp # Afbackup system
+afbackup 2988/udp
+afmbackup 2989/tcp # Afmbackup system
+afmbackup 2989/udp
+xtell 4224/tcp # xtell server
+fax 4557/tcp # FAX transmission service (old)
+hylafax 4559/tcp # HylaFAX client-server protocol (new)
+distmp3 4600/tcp # distmp3host daemon
+munin 4949/tcp lrrd # Munin
+enbd-cstatd 5051/tcp # ENBD client statd
+enbd-sstatd 5052/tcp # ENBD server statd
+pcrd 5151/tcp # PCR-1000 Daemon
+noclog 5354/tcp # noclogd with TCP (nocol)
+noclog 5354/udp # noclogd with UDP (nocol)
+hostmon 5355/tcp # hostmon uses TCP (nocol)
+hostmon 5355/udp # hostmon uses UDP (nocol)
+rplay 5555/udp # RPlay audio service
+nsca 5667/tcp # Nagios Agent - NSCA
+mrtd 5674/tcp # MRT Routing Daemon
+bgpsim 5675/tcp # MRT Routing Simulator
+canna 5680/tcp # cannaserver
+sane-port 6566/tcp sane saned # SANE network scanner daemon
+ircd 6667/tcp # Internet Relay Chat
+zope-ftp 8021/tcp # zope management by ftp
+tproxy 8081/tcp # Transparent Proxy
+omniorb 8088/tcp # OmniORB
+omniorb 8088/udp
+clc-build-daemon 8990/tcp # Common lisp build daemon
+xinetd 9098/tcp
+mandelspawn 9359/udp mandelbrot # network mandelbrot
+git 9418/tcp # Git Version Control System
+zope 9673/tcp # zope server
+webmin 10000/tcp
+kamanda 10081/tcp # amanda backup services (Kerberos)
+kamanda 10081/udp
+amandaidx 10082/tcp # amanda backup services
+amidxtape 10083/tcp # amanda backup services
+smsqp 11201/tcp # Alamin SMS gateway
+smsqp 11201/udp
+xpilot 15345/tcp # XPilot Contact Port
+xpilot 15345/udp
+sgi-cmsd 17001/udp # Cluster membership services daemon
+sgi-crsd 17002/udp
+sgi-gcd 17003/udp # SGI Group membership daemon
+sgi-cad 17004/tcp # Cluster Admin daemon
+isdnlog 20011/tcp # isdn logging system
+isdnlog 20011/udp
+vboxd 20012/tcp # voice box system
+vboxd 20012/udp
+binkp 24554/tcp # binkp fidonet protocol
+asp 27374/tcp # Address Search Protocol
+asp 27374/udp
+csync2 30865/tcp # cluster synchronization tool
+dircproxy 57000/tcp # Detachable IRC Proxy
+tfido 60177/tcp # fidonet EMSI over telnet
+fido 60179/tcp # fidonet EMSI over TCP
+
+# Local services
diff --git a/usr/src/cmd/coreadm/coreadm.xml b/usr/src/cmd/coreadm/coreadm.xml
index 28f1e27240..c6198f885a 100644
--- a/usr/src/cmd/coreadm/coreadm.xml
+++ b/usr/src/cmd/coreadm/coreadm.xml
@@ -48,6 +48,14 @@
<service_fmri value='svc:/system/filesystem/minimal' />
</dependency>
+ <dependency
+ name='coreadm_manifest-import'
+ type='service'
+ grouping='require_all'
+ restart_on='none'>
+ <service_fmri value='svc:/system/manifest-import:default' />
+ </dependency>
+
<instance name='default' enabled='false'>
<exec_method
type='method'
@@ -84,17 +92,17 @@
value='solaris.smf.value.coreadm' />
<propval name='global_pattern'
- type='astring' value='' />
+ type='astring' value='/%Z/cores/core.%f.%p' />
<propval name='global_content'
type='astring' value='default' />
<propval name='init_pattern'
- type='astring' value='core' />
+ type='astring' value='/%Z/cores/core.%f.%p' />
<propval name='init_content'
type='astring' value='default' />
<propval name='global_enabled'
- type='boolean' value='false' />
- <propval name='process_enabled'
type='boolean' value='true' />
+ <propval name='process_enabled'
+ type='boolean' value='false' />
<propval name='global_setid_enabled'
type='boolean' value='false' />
<propval name='process_setid_enabled'
diff --git a/usr/src/cmd/cron/Makefile b/usr/src/cmd/cron/Makefile
index d8df76960f..c45159969e 100644
--- a/usr/src/cmd/cron/Makefile
+++ b/usr/src/cmd/cron/Makefile
@@ -22,7 +22,7 @@
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# Copyright (c) 2018, Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
DEFAULTFILES = cron.dfl
@@ -48,6 +48,7 @@ ROOTVAR = $(ROOT)/var
ROOTSPCRON = $(ROOTVAR)/spool/cron
ROOTCROND = $(ROOTETC)/cron.d
+ROOTCRONDCRONTABS = $(ROOTCROND)/crontabs
ROOTCRONTABS = $(ROOTSPCRON)/crontabs
ROOTATJOBS = $(ROOTSPCRON)/atjobs
ROOTLIBCRON = $(ROOTLIB)/cron
@@ -66,9 +67,6 @@ POFILES1= at.po crontab.po funcs.po batch.po
POFILES= $(POFILES1) atrm.po
$(POFILES1) := XGETFLAGS= -a -x $(PROG1).xcl
-ROOTDIRS = $(ROOTSPCRON) $(ROOTCROND) \
- $(ROOTCRONTABS) $(ROOTATJOBS)
-
ROOTPROG = $(PROG1:%=$(ROOTUSRSBIN)/%) $(PROG2:%=$(ROOTBIN)/%) \
$(SCRIPT:%=$(ROOTBIN)/%) \
$(XPG6PROG:%=$(ROOTXPG6BIN)/%) \
@@ -144,13 +142,9 @@ crontab := LDLIBS += -lsecdb -lpam -lzoneinfo
crontab.xpg6 := LDLIBS += -lsecdb -lpam -lzoneinfo
crontab.xpg4 := LDLIBS += -lsecdb -lpam -lzoneinfo
-lint := LDLIBS += -lproject -lsecdb -lcontract -lpam
-
$(XPG4) := CFLAGS += -DXPG4
$(XPG6) := CFLAGS += -DXPG6
-LINTFLAGS += -u
-
$(ROOTSVCSYSTEM)/cron.xml := FILEMODE = 0444
$(ROOTLIBSVCMETHOD)/svc-cron := FILEMODE = 0555
@@ -160,7 +154,7 @@ $(ROOTLIBSVCMETHOD)/svc-cron := FILEMODE = 0555
all : $(PROG) $(XPG4) $(XPG6) $(SCRIPT) $(XPG4SCRIPT) $(FILES)
install : all $(ROOTPROG) $(ROOTETCDEFAULTFILES) $(ROOTSYMLINK) \
- $(ROOTMANIFEST) $(ROOTMETHOD)
+ $(ROOTMANIFEST) $(ROOTMETHOD) $(ROOTCRONDCRONTABS)/root
$(PROG) : $$(OBJS)
$(LINK.c) $(OBJS) -o $@ $(LDLIBS)
@@ -214,13 +208,14 @@ att2.c : att2.l att2.ed att1.c
ed - lex.yy.c < att2.ed
$(MV) lex.yy.c att2.c
-# Don't re-install directories installed by Targetdirs
-#$(ROOTDIRS):
-# $(INS.dir)
-
$(ROOTSYMLINK) :
$(RM) $@; $(SYMLINK) $(SYMLNKDEST) $@
+$(ROOTCRONDCRONTABS)/root: crontab.root
+ $(RM) $@; \
+ $(INS) -s -m $(FILEMODE) -f $(@D) crontab.root; \
+ $(MV) $(@D)/crontab.root $@
+
check: $(CHKMANIFEST)
$(POFILE): $(POFILES)
@@ -229,8 +224,6 @@ $(POFILE): $(POFILES)
clean :
$(RM) $(COBJS) att1.h att1.c att2.c
-lint : lint_SRCS
-
strip :
$(STRIP) $(PROG) $(XPG4) $(XPG6)
diff --git a/usr/src/cmd/cron/crontab.root b/usr/src/cmd/cron/crontab.root
new file mode 100644
index 0000000000..4153ad2d6a
--- /dev/null
+++ b/usr/src/cmd/cron/crontab.root
@@ -0,0 +1,18 @@
+## Rotate and trim the audit logs nightly.
+0 0 * * * /smartdc/bin/sdc-lastcomm -R 30
+## Run logadm hourly so that the minimum rotate interval is 1h
+0 * * * * /usr/sbin/logadm
+## Rotate vm.log files for any KVM VMs
+0 * * * * SDC_LOG_ROLL_BACKWARD=1 /usr/vm/sbin/rotate-kvm-logs.sh >> /var/log/rotate-kvm-logs.log 2>&1
+## Headnode should phone home nightly.
+0 1 * * * [ -x /opt/smartdc/bin/sdc-phonehome ] && /opt/smartdc/bin/sdc-phonehome
+## Delete saved core dumps over 7 days old
+15 0 * * * find /zones/*/cores -type f -mtime +7 -exec rm -f "{}" \;
+## Delete archived zone data over 7 days old
+30 0 * * * find /zones/archive/ -mount -maxdepth 1 -mindepth 1 -type d -mtime +7 -exec rm -rf "{}" \;
+## Delete logs to be uploaded over 7 days old if they aren't being consumed
+45 0 * * * [ -d /var/log/sdc/upload/ ] && find /var/log/sdc/upload/ -mount -maxdepth 1 -mindepth 1 -type f -mtime +7 -exec rm -f "{}" \;
+
+# NOTE: all entries above are in root's system-defined crontab; see the
+# crontab(1) man page.
+
diff --git a/usr/src/cmd/cron/svc-cron b/usr/src/cmd/cron/svc-cron
index 4def6071b8..55033608ee 100644
--- a/usr/src/cmd/cron/svc-cron
+++ b/usr/src/cmd/cron/svc-cron
@@ -22,8 +22,7 @@
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
-#
-# ident "%Z%%M% %I% %E% SMI"
+# Copyright 2012 Joyent, Inc. All rights reserved.
#
# Start method script for the cron service.
#
@@ -37,6 +36,45 @@ if [ -p /etc/cron.d/FIFO ]; then
fi
fi
+if smf_is_globalzone && [ -n "$(bootparams | grep '^headnode=true')" ]; then
+ #
+ # Randomize root's crontab so all HN's are not in sync.
+ #
+ utc_offset=`nawk -F= '{if ($1 == "utc_offset") print $2}' \
+ /usbkey/config.inc/generic`
+ [ -z "$utc_offset" ] && utc_offset=0
+
+ n=$(date +%S)
+ hr=$(($n % 5))
+ hr=$(($hr + $utc_offset))
+
+ n=$(date +%M)
+ mn=$(($n % 15))
+
+ nawk -v hr=$hr -v mn=$mn '{
+ if (substr($1, 1, 1) == "#") {
+ print $0
+ next
+ }
+ if (substr($2, 1, 1) == "*") {
+ print $0
+ next
+ }
+ if (length($0) == 0) {
+ print $0
+ next
+ }
+
+ printf("%d %d %s %s %s %s", mn, hr, $3, $4, $5, $6)
+ for (i = 7; i <= NF; i++)
+ printf(" %s", $i)
+ printf("\n")
+ mn += 10
+ }' /etc/cron.d/crontabs/root >/etc/cron.d/crontabs/root.$$
+ cp /etc/cron.d/crontabs/root.$$ /etc/cron.d/crontabs/root
+ rm -f /etc/cron.d/crontabs/root.$$
+fi
+
if [ -x /usr/sbin/cron ]; then
/usr/bin/rm -f /etc/cron.d/FIFO
/usr/sbin/cron &
diff --git a/usr/src/cmd/dispadmin/Makefile b/usr/src/cmd/dispadmin/Makefile
index 65f7e7301c..6df5bbca3f 100644
--- a/usr/src/cmd/dispadmin/Makefile
+++ b/usr/src/cmd/dispadmin/Makefile
@@ -22,12 +22,14 @@
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# cmd/dispadmin/Makefile
+# Copyright 2019 Joyent, Inc.
#
PROG= dispadmin
MANIFEST= scheduler.xml
SVCMETHOD= svc-scheduler
+ETCFILES= dispadmin.conf
+
SDC= SDC$(PROG)
RT= RT$(PROG)
TS= TS$(PROG)
@@ -36,6 +38,8 @@ FSS= FSS$(PROG)
FX= FX$(PROG)
PROGS= $(PROG) $(RT) $(TS) $(IA) $(FSS) $(FX) $(SDC)
+ROOTETCFILES= $(ETCFILES:%=$(ROOTETC)/%)
+
include ../Makefile.cmd
CFLAGS += $(CCVERBOSE)
@@ -59,6 +63,8 @@ ROOTSDC= $(SDC:%=$(ROOTDIR)/SDC/%)
ROOTTS= $(TS:%=$(ROOTDIR)/TS/%)
ROOTMANIFESTDIR= $(ROOTSVCSYSTEM)
+$(ROOTETCFILES) := FILEMODE = 644
+
# this would be simpler if we renamed rtdispadmin.c and tsdispadmin.c
OBJECTS= $(PROG).o rt$(PROG).o ts$(PROG).o ia$(PROG).o \
fss$(PROG).o fx$(PROG).o sdc$(PROG).o subr.o
@@ -83,20 +89,15 @@ $(ROOTDIR)/TS/% : %
$(INS.file)
.KEEP_STATE:
-
-all: $(PROGS)
+
+all: $(PROGS)
$(PROGS): $$(OBJ) subr.o
$(LINK.c) -o $@ $(OBJ) subr.o $(LDLIBS)
$(POST_PROCESS)
-llib-lsubr.ln: subr.c
- $(LINT.c) -y -o subr subr.c
-
-lint := LDLIBS += -L. -lsubr
-
install: all $(ROOTPROG) $(ROOTRT) $(ROOTTS) $(ROOTIA) $(ROOTFSS) $(ROOTFX) \
- $(ROOTSDC) $(ROOTMANIFEST) $(ROOTSVCMETHOD)
+ $(ROOTSDC) $(ROOTMANIFEST) $(ROOTSVCMETHOD) $(ROOTETCFILES)
# Don't re-install directories already installed by Targetdirs
#$(ROOTDIRS):
@@ -105,15 +106,6 @@ install: all $(ROOTPROG) $(ROOTRT) $(ROOTTS) $(ROOTIA) $(ROOTFSS) $(ROOTFX) \
check: $(CHKMANIFEST)
clean:
- $(RM) $(OBJECTS) $(PROGS) llib-lsubr.ln
-
-lint: llib-lsubr.ln
- $(LINT.c) dispadmin.c $(LDLIBS)
- $(LINT.c) fssdispadmin.c $(LDLIBS)
- $(LINT.c) fxdispadmin.c $(LDLIBS)
- $(LINT.c) iadispadmin.c $(LDLIBS)
- $(LINT.c) rtdispadmin.c $(LDLIBS)
- $(LINT.c) sdcdispadmin.c $(LDLIBS)
- $(LINT.c) tsdispadmin.c $(LDLIBS)
-
+ $(RM) $(OBJECTS) $(PROGS)
+
include ../Makefile.targ
diff --git a/usr/src/cmd/dispadmin/dispadmin.conf b/usr/src/cmd/dispadmin/dispadmin.conf
new file mode 100644
index 0000000000..7970647c62
--- /dev/null
+++ b/usr/src/cmd/dispadmin/dispadmin.conf
@@ -0,0 +1 @@
+DEFAULT_SCHEDULER=FSS
diff --git a/usr/src/cmd/dumpadm/Makefile b/usr/src/cmd/dumpadm/Makefile
index 7818439eb4..0734535b29 100644
--- a/usr/src/cmd/dumpadm/Makefile
+++ b/usr/src/cmd/dumpadm/Makefile
@@ -20,17 +20,18 @@
#
#
# Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2019 Joyent, Inc.
#
PROG = dumpadm
MANIFEST = dumpadm.xml
SVCMETHOD= svc-dumpadm
+ETCFILES= dumpadm.conf
OBJS = main.o dconf.o minfree.o utils.o swap.o
SRCS = $(OBJS:.o=.c)
-
-lint := LINTFLAGS = -mx
+ROOTETCFILES= $(ETCFILES:%=$(ROOTETC)/%)
include ../Makefile.cmd
@@ -50,13 +51,11 @@ $(PROG): $(OBJS)
$(LINK.c) -o $@ $(OBJS) $(LDLIBS)
$(POST_PROCESS)
-install: all $(ROOTUSRSBINPROG) $(ROOTMANIFEST) $(ROOTSVCMETHOD)
+install: all $(ROOTUSRSBINPROG) $(ROOTMANIFEST) $(ROOTSVCMETHOD) $(ROOTETCFILES)
check: $(CHKMANIFEST)
clean:
$(RM) $(OBJS)
-lint: lint_SRCS
-
include ../Makefile.targ
diff --git a/usr/src/cmd/dumpadm/dumpadm.conf b/usr/src/cmd/dumpadm/dumpadm.conf
new file mode 100644
index 0000000000..804e1da11a
--- /dev/null
+++ b/usr/src/cmd/dumpadm/dumpadm.conf
@@ -0,0 +1,11 @@
+#
+# dumpadm.conf
+#
+# Configuration parameters for system crash dump.
+# Do NOT edit this file by hand -- use dumpadm(1m) instead.
+#
+DUMPADM_DEVICE=/dev/zvol/dsk/zones/dump
+DUMPADM_SAVDIR=/var/crash/volatile
+DUMPADM_CONTENT=kernel
+DUMPADM_ENABLE=no
+DUMPADM_CSAVE=on
diff --git a/usr/src/cmd/init/init.dfl b/usr/src/cmd/init/init.dfl
index 371b48becc..150f720b1c 100644
--- a/usr/src/cmd/init/init.dfl
+++ b/usr/src/cmd/init/init.dfl
@@ -29,5 +29,6 @@
# TZ, LANG, CMASK, or any of the LC_* environment variables. value may
# be enclosed in double quotes (") or single quotes (').
#
-TZ=PST8PDT
+TZ=UTC
CMASK=022
+LANG=en_US.UTF-8
diff --git a/usr/src/cmd/ipf/etc/Makefile b/usr/src/cmd/ipf/etc/Makefile
index 3e06187ae9..a5eb399f56 100644
--- a/usr/src/cmd/ipf/etc/Makefile
+++ b/usr/src/cmd/ipf/etc/Makefile
@@ -22,42 +22,31 @@
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-#cmd/ipf/etc/Makefile
+# Copyright 2019 Joyent, Inc.
#
-IPFCONF= ipf.conf
-IPFPROG= $(IPFCONF)
+IPFFILES = ipf.conf smartos_version
include ../../Makefile.cmd
-
ETCIPF= $(ROOTETC)/ipf
-DIRS= $(ETCIPF)
-
-ETCIPFPROG= $(IPFPROG:%=$(ETCIPF)/%)
+ROOTETCIPFFILES = $(IPFFILES:%=$(ETCIPF)/%)
-$(ETCIPFPROG):= FILEMODE= 0644
+$(ETCIPF)/ipf.conf := FILEMODE= 0644
+$(ETCIPF)/smartos_version := FILEMODE= 0444
.KEEP_STATE:
-all: $(IPFPROG) $(DIRS) $(ETCIPFPROG)
-
-install: all $(DIRS)
+all:
-$(PFILAP):
- $(SH) $@.sh
+install: all $(ROOTETCIPFFILES)
-$(ETCIPF)/% : % $(ETCIPF)
+$(ETCIPF)/% : %
$(INS.file)
-$(DIRS):
- $(INS.dir)
-
clean:
clobber:
-lint:
-
.PARALLEL:
diff --git a/usr/src/cmd/ipf/etc/smartos_version b/usr/src/cmd/ipf/etc/smartos_version
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/usr/src/cmd/ipf/etc/smartos_version
@@ -0,0 +1 @@
+2
diff --git a/usr/src/cmd/ipf/svc/ipfilter b/usr/src/cmd/ipf/svc/ipfilter
index 48e3e2e915..bb25316b44 100644
--- a/usr/src/cmd/ipf/svc/ipfilter
+++ b/usr/src/cmd/ipf/svc/ipfilter
@@ -23,9 +23,12 @@
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
+# Copyright (c) 2013, Joyent, Inc. All rights reserved.
# Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
#
+set -o xtrace
+
. /lib/svc/share/smf_include.sh
. /lib/svc/share/ipf_include.sh
@@ -152,8 +155,25 @@ upgrade_config()
svcadm refresh $SMF_FMRI >/dev/null 2>&1
}
+symlink_persistent_file()
+{
+ persist_file=/var/fw/$1
+ etc_file=$ETC_IPF_DIR/$1
+
+ [ ! -e $persist_file ] && return 0
+ [ -L $etc_file ] && return 0
+
+ [ -e $etc_file ] && mv $etc_file{,.orig}
+
+ ln -s $persist_file $etc_file
+}
+
+
configure_firewall()
{
+ symlink_persistent_file ipnat.conf
+ symlink_persistent_file ipf.conf
+ symlink_persistent_file ipf6.conf
create_global_rules || exit $SMF_EXIT_ERR_CONFIG
create_global_ovr_rules || exit $SMF_EXIT_ERR_CONFIG
create_services_rules || exit $SMF_EXIT_ERR_CONFIG
diff --git a/usr/src/cmd/ipf/svc/ipfilter.xml b/usr/src/cmd/ipf/svc/ipfilter.xml
index 5f088f5344..8b6506795f 100644
--- a/usr/src/cmd/ipf/svc/ipfilter.xml
+++ b/usr/src/cmd/ipf/svc/ipfilter.xml
@@ -4,6 +4,7 @@
Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
+
CDDL HEADER START
The contents of this file are subject to the terms of the
@@ -97,13 +98,13 @@
type='method'
name='refresh'
exec='/lib/svc/method/ipfilter reload'
- timeout_seconds='120' >
+ timeout_seconds='1200' >
</exec_method>
- <instance name='default' enabled='false'>
+ <instance name='default' enabled='true'>
<property_group name='firewall_config_default'
type='com.sun,fw_configuration'>
- <propval name='policy' type='astring' value='none' />
+ <propval name='policy' type='astring' value='custom' />
<propval name='block_policy' type='astring'
value='none' />
<propval name='custom_policy_file' type='astring'
diff --git a/usr/src/cmd/localedef/Makefile b/usr/src/cmd/localedef/Makefile
index 358f63de01..8a8e5dc2e0 100644
--- a/usr/src/cmd/localedef/Makefile
+++ b/usr/src/cmd/localedef/Makefile
@@ -13,7 +13,7 @@
# Copyright 2017 Nexenta Systems, Inc.
# Copyright 2011 EveryCity Ltd. All rights reserved.
# Copyright 2013 DEY Storage Systems, Inc.
-# Copyright 2016 Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
# Copyright 2017 RackTop Systems.
#
@@ -23,6 +23,10 @@ include $(SRC)/cmd/localedef/Makefile.common
LDLIBS += -lavl -lgen
+I18NEXTFILE = $(ROOTI18NEXT)/UTF-8.x
+
+$(I18NEXTFILE) := FILEMODE = 0444
+
.KEEP_STATE:
all: $(PROG)
@@ -43,9 +47,7 @@ $(POFILE): $(PIFILES)
$(SED) -e '/domain/d' messages.po > $@
$(RM) $(PIFILES) messages.po
-install: all $(ROOTPROG)
-
-lint: lint_SRCS
+install: all $(ROOTPROG) $(I18NEXTFILE)
clean:
$(RM) $(CLEANFILES)
diff --git a/usr/src/cmd/localedef/UTF-8.x b/usr/src/cmd/localedef/UTF-8.x
new file mode 100644
index 0000000000..b7ab359bd4
--- /dev/null
+++ b/usr/src/cmd/localedef/UTF-8.x
@@ -0,0 +1,114 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1996-1997, 2000-2003 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# Method file for Solaris Unicode locales.
+#
+#
+#ident "@(#)UTF-8.x 1.4 03/08/19 SMI"
+#
+
+METHODS
+
+#
+# Encoding definitions to use UTF-8 (MB) and UTF-32 (WC):
+file_code utf8
+process_code ucs4
+
+#
+# We use the following methods from the libc:
+iswctype@native "__iswctype_std" "libc" "/usr/lib/" "libc.so.1"
+towctrans@native "__towctrans_std"
+towlower@native "__towlower_std"
+towupper@native "__towupper_std"
+trwctype "__trwctype_std"
+wctrans "__wctrans_std"
+wctype "__wctype_std"
+
+mbsinit "__mbsinit_gen"
+mbrlen "__mbrlen_gen"
+
+strcoll "__strcoll_std"
+strxfrm "__strxfrm_std"
+wcscoll "__wcscoll_bc"
+wcscoll@native "__wcscoll_std"
+wcsxfrm "__wcsxfrm_bc"
+wcsxfrm@native "__wcsxfrm_std"
+
+fnmatch "__fnmatch_std"
+regcomp "__regcomp_std"
+regexec "__regexec_std"
+regerror "__regerror_std"
+regfree "__regfree_std"
+
+strfmon "__strfmon_std"
+
+strftime "__strftime_std"
+strptime "__strptime_std"
+wcsftime "__wcsftime_std"
+
+getdate "__getdate_std"
+
+#
+# The methods designated at below are all Unicode locale-specific methods
+# coming from the methods_unicode.so.3 shared object:
+eucpctowc "__u32_to_dense_u32_utf8" "localelib" "/usr/lib/locale/common" "methods_unicode.so.3"
+wctoeucpc "__dense_u32_to_u32_utf8"
+
+iswctype "__iswctype_bc_utf8"
+towctrans "__towctrans_bc_utf8"
+towlower "__towlower_bc_utf8"
+towupper "__towupper_bc_utf8"
+
+mbftowc "__mbftowc_dense_utf8"
+mbftowc@native "__mbftowc_dense_native_utf8"
+fgetwc "__fgetwc_dense_utf8"
+fgetwc@native "__fgetwc_dense_native_utf8"
+mblen "__mblen_dense_utf8"
+mbstowcs "__mbstowcs_dense_utf8"
+mbstowcs@native "__mbstowcs_dense_native_utf8"
+mbtowc "__mbtowc_dense_utf8"
+mbtowc@native "__mbtowc_dense_native_utf8"
+wcstombs "__wcstombs_dense_utf8"
+wcstombs@native "__wcstombs_dense_native_utf8"
+wcswidth "__wcswidth_dense_utf8"
+wcswidth@native "__wcswidth_dense_utf8"
+wctomb "__wctomb_dense_utf8"
+wctomb@native "__wctomb_dense_native_utf8"
+wcwidth "__wcwidth_dense_utf8"
+wcwidth@native "__wcwidth_dense_utf8"
+
+btowc "__btowc_dense_utf8"
+btowc@native "__btowc_dense_utf8"
+wctob "__wctob_dense_utf8"
+wctob@native "__wctob_dense_utf8"
+mbrtowc "__mbrtowc_dense_utf8"
+mbrtowc@native "__mbrtowc_dense_native_utf8"
+wcrtomb "__wcrtomb_dense_utf8"
+wcrtomb@native "__wcrtomb_dense_native_utf8"
+mbsrtowcs "__mbsrtowcs_dense_utf8"
+mbsrtowcs@native "__mbsrtowcs_dense_native_utf8"
+wcsrtombs "__wcsrtombs_dense_utf8"
+wcsrtombs@native "__wcsrtombs_dense_native_utf8"
+
+END METHODS
diff --git a/usr/src/cmd/logadm/logadm.conf b/usr/src/cmd/logadm/logadm.conf
index 7b19473a19..39eea57578 100644
--- a/usr/src/cmd/logadm/logadm.conf
+++ b/usr/src/cmd/logadm/logadm.conf
@@ -19,6 +19,7 @@
# CDDL HEADER END
#
# Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2018, Joyent, Inc.
#
# logadm.conf
#
@@ -35,12 +36,18 @@
# logadm typically runs early every morning via an entry in
# root's crontab (see crontab(1)).
#
-/var/log/syslog -C 8 -a 'kill -HUP `cat /var/run/syslog.pid`'
-/var/adm/messages -C 4 -a 'kill -HUP `cat /var/run/syslog.pid`'
+/var/log/syslog -C 8 -a 'kill -HUP `cat /var/run/*syslog*.pid`'
+/var/adm/messages -C 4 -a 'kill -HUP `cat /var/run/*syslog*.pid`'
/var/cron/log -c -s 512k -t /var/cron/olog
/var/lp/logs/lpsched -C 2 -N -t '$file.$N'
/var/fm/fmd/errlog -N -s 2m -M '/usr/sbin/fmadm -q rotate errlog && mv /var/fm/fmd/errlog.0- $nfile'
/var/fm/fmd/fltlog -N -A 6m -s 10m -M '/usr/sbin/fmadm -q rotate fltlog && mv /var/fm/fmd/fltlog.0- $nfile'
+vm_logs /var/log/vm/vmadm.log -b '/usr/vm/sbin/rotate-logs.sh -m /var/log/vm/logs/ /var/log/vm/vmadm.log' -t '/var/log/vm/vmadm_$nodename_%FT%H:%M:%S.log' -C 168 -S 1g -p 1h
+fw_logs /var/log/fw/fwadm.log -b '/usr/vm/sbin/rotate-logs.sh -i /var/log/fw/logs/ /var/log/fw/fwadm.log' -t '/var/log/fw/fwadm_$nodename_%FT%H:%M:%S.log' -C 168 -S 1g -p 1h
+vmadmd_logs /var/svc/log/*vmadmd*.log -C 168 -S 1g -c -p 1h -t '/var/log/vm/vmadmd_$nodename_%FT%H:%M:%S.log'
+vminfod_logs /var/svc/log/*vminfod*.log -C 168 -S 1g -c -p 1h -t '/var/log/vm/vminfod_$nodename_%FT%H:%M:%S.log'
+/var/log/*.log -C 2 -s 5m -c
+/var/log/*.debug -C 2 -s 5m -c
smf_logs /var/svc/log/*.log -C 8 -s 1m -c
#
# The entry below is used by turnacct(1M)
diff --git a/usr/src/cmd/login/login.dfl b/usr/src/cmd/login/login.dfl
index 13ecd51113..4515dfcc6a 100644
--- a/usr/src/cmd/login/login.dfl
+++ b/usr/src/cmd/login/login.dfl
@@ -36,7 +36,7 @@
# any of the currently enabled /dev/vt/# virtual terminal devices.
# Comment this line out to allow remote login by root.
#
-CONSOLE=/dev/console
+#CONSOLE=/dev/console
# PASSREQ determines if login requires a password.
#
@@ -47,19 +47,16 @@ PASSREQ=YES
ALTSHELL=YES
# PATH sets the initial shell PATH variable
-# sample with GNU tools in front of the path
-# PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin
-# sample with XPG4 tools in front of the path
-# PATH=/usr/xpg4/bin:/usr/bin:/usr/sbin:/sbin
-PATH=/usr/bin:/usr/sbin:/sbin:/usr/gnu/bin
+#
+#PATH=/usr/bin:
# SUPATH sets the initial shell PATH variable for root
#
-SUPATH=/usr/sbin:/sbin:/usr/bin
+#SUPATH=/usr/sbin:/usr/bin
# TIMEOUT sets the number of seconds (between 0 and 900) to wait before
# abandoning a login session.
-#
+#
#TIMEOUT=300
# UMASK sets the initial shell file creation mode mask. See umask(1).
@@ -80,9 +77,9 @@ SYSLOG=YES
#SLEEPTIME=4
# DISABLETIME If present, and greater than zero, the number of seconds
-# login will wait after RETRIES failed attempts or the PAM framework returns
+# login will wait after RETRIES failed attempts or the PAM framework returns
# PAM_ABORT. Default is 20. Minimum is 0. No maximum is imposed.
-#
+#
#DISABLETIME=20
# RETRIES determines the number of failed logins that will be
diff --git a/usr/src/cmd/netfiles/Makefile b/usr/src/cmd/netfiles/Makefile
index 0ae84c2276..aa6886311d 100644
--- a/usr/src/cmd/netfiles/Makefile
+++ b/usr/src/cmd/netfiles/Makefile
@@ -21,6 +21,8 @@
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
+# Copyright 2019 Joyent, Inc.
+#
TXTS= nsswitch.conf netconfig hosts services
DEFAULTFILES= nss.dfl
@@ -29,7 +31,7 @@ include ../Makefile.cmd
FILES= hosts services
ETCFILES= netconfig nsswitch.conf nsswitch.files nsswitch.nis \
- nsswitch.dns nsswitch.ldap nsswitch.ad
+ nsswitch.dns nsswitch.ldap nsswitch.ad resolv.conf
ROOTNET= $(ROOTETC)/net
TICLTS= $(ROOTNET)/ticlts
diff --git a/usr/src/cmd/netfiles/nsswitch.conf b/usr/src/cmd/netfiles/nsswitch.conf
index 58ec600c9a..166e5e0ca3 100644
--- a/usr/src/cmd/netfiles/nsswitch.conf
+++ b/usr/src/cmd/netfiles/nsswitch.conf
@@ -29,8 +29,8 @@
passwd: files
group: files
-hosts: files
-ipnodes: files
+hosts: files dns mdns
+ipnodes: files dns mdns
networks: files
protocols: files
rpc: files
diff --git a/usr/src/cmd/netfiles/resolv.conf b/usr/src/cmd/netfiles/resolv.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/usr/src/cmd/netfiles/resolv.conf
diff --git a/usr/src/cmd/nsadmin/Makefile b/usr/src/cmd/nsadmin/Makefile
index c87810e767..819a69340c 100644
--- a/usr/src/cmd/nsadmin/Makefile
+++ b/usr/src/cmd/nsadmin/Makefile
@@ -22,54 +22,72 @@
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
+# Copyright 2019 Joyent, Inc.
+#
-PROG= profile .login ksh.kshrc system
-PROGSKEL= .profile .kshrc
-PROGROOT= .profile .bashrc
+ETCFILES = profile .login ksh.kshrc system zshrc
+ETCSKELFILES = .profile .kshrc .bashrc
+ETCBASHFILES = bash_completion
+ETCBASHCOMPLETIONDFILES = dladm zones
+ROOTFILES = .profile .bashrc .bash_profile
include ../Makefile.cmd
-ROOTROOT= $(ROOT)/root
+ROOTETCFILES = $(ETCFILES:%=$(ROOTETC)/%)
ROOTETCSKEL= $(ROOTETC)/skel
-ROOTETCSKELPROG= $(PROGSKEL:%=$(ROOTETCSKEL)/%)
-ROOTROOTPROG= $(PROGROOT:%=$(ROOTROOT)/%)
+ROOTETCSKELFILES = $(ETCSKELFILES:%=$(ROOTETCSKEL)/%)
+ETCBASHDIR = $(ROOTETC)/bash
+ROOTETCBASHFILES = $(ETCBASHFILES:%=$(ETCBASHDIR)/%)
+ETCBASHCOMPLETIONDDIR = $(ETCBASHDIR)/bash_completion.d
+ROOTETCBASHCOMPLETIONDFILES = \
+ $(ETCBASHCOMPLETIONDFILES:%=$(ETCBASHCOMPLETIONDDIR)/%)
+ROOTROOT= $(ROOT)/root
+ROOTROOTFILES = $(ROOTFILES:%=$(ROOTROOT)/%)
+
+FILES = $(ROOTETCFILES) $(ROOTETCSKELFILES) \
+ $(ROOTETCBASHFILES) $(ROOTETCBASHCOMPLETIONDFILES) \
+ $(ROOTROOTFILES)
+
FILEMODE= 0644
-CLOBBERFILES = profile .bashrc .profile .login .kshrc
+.KEEP_STATE:
-.login: login.csh
- $(RM) .login
- $(CP) login.csh .login
+all:
-profile: etc-profile.sh
- $(RM) profile
- $(CP) etc-profile.sh $@
+# Use $^ instead of $< - it's broken without %
+INS.file = $(RM) $@; $(INS) -s -m $(FILEMODE) -f $(@D) $^
+INS.rename = $(INS.file); $(MV) $(@D)/$(^F) $@
-.profile: dot-profile.sh
- $(RM) .profile
- $(CP) dot-profile.sh $@
+$(ROOTETC)/profile: etc-profile.sh
+ $(INS.rename)
-.kshrc: dot-kshrc.sh
- $(RM) .kshrc
- $(CP) dot-kshrc.sh $@
+$(ROOTETC)/.login: login.csh
+ $(INS.rename)
-.bashrc: bashrc.sh
- $(RM) .bashrc
- $(CP) bashrc.sh $@
+# skel file and root's default
+$(ROOTROOT)/.kshrc $(ROOTETCSKEL)/.kshrc: dot-kshrc.sh
+ $(INS.rename)
-.KEEP_STATE:
+# skel file and root's default
+$(ROOTROOT)/.profile $(ROOTETCSKEL)/.profile: dot-profile.sh
+ $(INS.rename)
+
+$(ROOTETCSKEL)/.bashrc: etc-skel-bashrc.sh
+ $(INS.rename)
-all: $(PROG) $(PROGSKEL)
+$(ROOTROOT)/.bash_profile: dot-bash_profile.sh
+ $(INS.rename)
-$(ROOTROOT)/% \
-$(ROOTETCSKEL)/%: %
+$(ROOTROOT)/.bashrc: dot-bashrc.sh
+ $(INS.rename)
+
+$(ROOTETCBASHDIR)/%: %
$(INS.file)
-$(ROOTROOT) \
-$(ROOTETCSKEL):
- $(INS.dir)
+$(ROOTETCBASHCOMPLETIONDDIR)/%: %
+ $(INS.file)
-install: all $(ROOTETCSKEL) $(ROOTETCPROG) $(ROOTETCSKELPROG) $(ROOTROOTPROG)
+install: all $(FILES)
clean:
diff --git a/usr/src/cmd/nsadmin/bash/bash_completion b/usr/src/cmd/nsadmin/bash/bash_completion
new file mode 100755
index 0000000000..71f3e9e63f
--- /dev/null
+++ b/usr/src/cmd/nsadmin/bash/bash_completion
@@ -0,0 +1,9417 @@
+#
+# This file contains an example set of shell completions that can be used with
+# bash(1). These completions allow a user to complete filenames, commands
+# name, command line options, and command line arguments using the [tab] key.
+# The completions defined here are specific to the GNU command set, as a result
+# they will provide the choice of GNU command line options in response to the
+# [tab] key. For the completed options to match the command implementation,
+# you may have to have /usr/gnu/bin at the head of your PATH.
+#
+# These completions are not included in the default bash(1) environment. To
+# include them in the default environment, it is recommended that this file be
+# copied to /etc/bash/bash_completion and be sourced from either a system wide
+# bashrc in /etc/bash/bashrc or individual bashrcs in ~/.bashrc via
+# [ -f /etc/bash/bash_completion ] && . /etc/bash/bash_completion
+#
+
+# bash_completion - programmable completion functions for bash 3.x
+# (backwards compatible with bash 2.05b)
+#
+# $Id: bash_completion,v 1.872 2006/03/01 16:20:18 ianmacd Exp $
+#
+# Copyright (C) Ian Macdonald <ian@caliban.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# The latest version of this software can be obtained here:
+#
+# http://www.caliban.org/bash/index.shtml#completion
+#
+# RELEASE: 20060301
+
+if [[ $- == *v* ]]; then
+ BASH_COMPLETION_ORIGINAL_V_VALUE="-v"
+else
+ BASH_COMPLETION_ORIGINAL_V_VALUE="+v"
+fi
+
+if [[ -n $BASH_COMPLETION_DEBUG ]]; then
+ set -v
+else
+ set +v
+fi
+
+# Alter the following to reflect the location of this file.
+#
+[ -n "$BASH_COMPLETION" ] || BASH_COMPLETION=/etc/bash/bash_completion
+[ -n "$BASH_COMPLETION_DIR" ] || BASH_COMPLETION_DIR=/etc/bash/bash_completion.d
+readonly BASH_COMPLETION BASH_COMPLETION_DIR
+
+# Set a couple of useful vars
+#
+UNAME=$( uname -s )
+# strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
+UNAME=${UNAME/CYGWIN_*/Cygwin}
+RELEASE=$( uname -r )
+
+# features supported by bash 2.05 and higher
+if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} > 04 ]] ||
+ [ ${BASH_VERSINFO[0]} -gt 2 ]; then
+ declare -r bash205=$BASH_VERSION 2>/dev/null || :
+ default="-o default"
+ dirnames="-o dirnames"
+ filenames="-o filenames"
+fi
+# features supported by bash 2.05b and higher
+if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} = "05b" ]] ||
+ [ ${BASH_VERSINFO[0]} -gt 2 ]; then
+ declare -r bash205b=$BASH_VERSION 2>/dev/null || :
+ nospace="-o nospace"
+fi
+# features supported by bash 3.0 and higher
+if [ ${BASH_VERSINFO[0]} -gt 2 ]; then
+ declare -r bash3=$BASH_VERSION 2>/dev/null || :
+ bashdefault="-o bashdefault"
+ plusdirs="-o plusdirs"
+fi
+
+# Turn on extended globbing and programmable completion
+shopt -s extglob progcomp
+
+# A lot of the following one-liners were taken directly from the
+# completion examples provided with the bash 2.04 source distribution
+
+# Make directory commands see only directories
+complete -d pushd
+
+# The following section lists completions that are redefined later
+# Do NOT break these over multiple lines.
+#
+# START exclude -- do NOT remove this line
+complete -f -X '!*.?(t)bz?(2)' bunzip2 bzcat bzcmp bzdiff bzegrep bzfgrep bzgrep
+complete -f -X '!*.@(zip|ZIP|jar|JAR|exe|EXE|pk3|war|wsz|ear|zargo|xpi|sxw|ott)' unzip zipinfo
+complete -f -X '*.Z' compress znew
+complete -f -X '!*.@(Z|gz|tgz|Gz|dz)' gunzip zcmp zdiff zcat zegrep zfgrep zgrep zless zmore
+complete -f -X '!*.Z' uncompress
+complete -f -X '!*.@(gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' ee display
+complete -f -X '!*.@(gif|jp?(e)g|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|GIF|JPG|JP?(E)G|TIF?(F)|PNG|P[BGP]M|BMP|X[BP]M|RLE|RGB|PCX|FITS|PM)' xv qiv
+complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))' gv ggv kghostview
+complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' xdvi
+complete -f -X '!*.@(dvi|DVI)?(.@(gz|bz2))' kdvi
+complete -f -X '!*.@(dvi|DVI)' dvips dviselect dvitype dvipdf advi dvipdfm dvipdfmx
+complete -f -X '!*.@(pdf|PDF)' acroread gpdf xpdf
+complete -f -X '!*.@(?(e)ps|?(E)PS|pdf|PDF)' kpdf
+complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ)|cb(r|z)|CB(R|Z)|djv?(u)|DJV?(U)||dvi|DVI|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' evince
+complete -f -X '!*.@(?(e)ps|?(E)PS)' ps2pdf
+complete -f -X '!*.texi*' makeinfo texi2html
+complete -f -X '!*.@(?(la)tex|?(LA)TEX|texi|TEXI|dtx|DTX|ins|INS)' tex latex slitex jadetex pdfjadetex pdftex pdflatex texi2dvi
+complete -f -X '!*.@(mp3|MP3)' mpg123 mpg321 madplay
+complete -f -X '!*.@(mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp3|MP3|m4v|M4V|ogg|OGG|ogm|OGM|mp4|MP4|wav|WAV|asx|ASX|mng|MNG|srt)' xine aaxine fbxine kaffeine
+complete -f -X '!*.@(avi|asf|wmv)' aviplay
+complete -f -X '!*.@(rm?(j)|ra?(m)|smi?(l))' realplay
+complete -f -X '!*.@(mpg|mpeg|avi|mov|qt)' xanim
+complete -f -X '!*.@(ogg|OGG|m3u|flac|spx)' ogg123
+complete -f -X '!*.@(mp3|MP3|ogg|OGG|pls|m3u)' gqmpeg freeamp
+complete -f -X '!*.fig' xfig
+complete -f -X '!*.@(mid?(i)|MID?(I))' playmidi
+complete -f -X '!*.@(mid?(i)|MID?(I)|rmi|RMI|rcp|RCP|[gr]36|[GR]36|g18|G18|mod|MOD|xm|XM|it|IT|x3m|X3M)' timidity
+complete -f -X '*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' vi vim gvim rvim view rview rgvim rgview gview
+complete -f -X '*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' emacs
+complete -f -X '!*.@(exe|EXE|com|COM|scr|SCR|exe.so)' wine
+complete -f -X '!*.@(zip|ZIP|z|Z|gz|GZ|tgz|TGZ)' bzme
+complete -f -X '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))' netscape mozilla lynx opera galeon curl dillo elinks amaya
+complete -f -X '!*.@(sxw|stw|sxg|sgl|doc|dot|rtf|txt|htm|html|odt|ott|odm)' oowriter
+complete -f -X '!*.@(sxi|sti|pps|ppt|pot|odp|otp)' ooimpress
+complete -f -X '!*.@(sxc|stc|xls|xlw|xlt|csv|ods|ots)' oocalc
+complete -f -X '!*.@(sxd|std|sda|sdd|odg|otg)' oodraw
+complete -f -X '!*.@(sxm|smf|mml|odf)' oomath
+complete -f -X '!*.odb' oobase
+complete -f -X '!*.rpm' rpm2cpio
+# FINISH exclude -- do not remove this line
+
+# start of section containing compspecs that can be handled within bash
+
+# user commands see only users
+complete -u su usermod userdel passwd chage write chfn groups slay w sux
+
+# group commands see only groups
+[ -n "$bash205" ] && complete -g groupmod groupdel newgrp 2>/dev/null
+
+# bg completes with stopped jobs
+complete -A stopped -P '%' bg
+
+# other job commands
+complete -j -P '%' fg jobs disown
+
+# readonly and unset complete with shell variables
+complete -v readonly unset
+
+# set completes with set options
+complete -A setopt set
+
+# shopt completes with shopt options
+complete -A shopt shopt
+
+# helptopics
+complete -A helptopic help
+
+# unalias completes with aliases
+complete -a unalias
+
+# bind completes with readline bindings (make this more intelligent)
+complete -A binding bind
+
+# type and which complete on commands
+complete -c command type which
+
+# builtin completes on builtins
+complete -b builtin
+
+# start of section containing completion functions called by other functions
+
+# This function checks whether we have a given program on the system.
+# No need for bulky functions in memory if we don't.
+#
+have()
+{
+ unset -v have
+ PATH=/usr/gnu/bin:$PATH:/sbin:/usr/sbin type $1 &>/dev/null &&
+ have="yes"
+}
+
+# use GNU sed if we have it, since its extensions are still used in our code
+#
+[ $UNAME != Linux ] && have gsed && alias sed=gsed
+
+# This function checks whether a given readline variable
+# is `on'.
+#
+_rl_enabled()
+{
+ [[ "$( bind -v )" = *$1+([[:space:]])on* ]]
+}
+
+# This function shell-quotes the argument
+quote()
+{
+ echo \'${1//\'/\'\\\'\'}\' #'# Help vim syntax highlighting
+}
+
+# This function quotes the argument in a way so that readline dequoting
+# results in the original argument
+quote_readline()
+{
+ local t="${1//\\/\\\\}"
+ echo \'${t//\'/\'\\\'\'}\' #'# Help vim syntax highlighting
+}
+
+# This function shell-dequotes the argument
+dequote()
+{
+ eval echo "$1"
+}
+
+
+# Get the word to complete
+# This is nicer than ${COMP_WORDS[$COMP_CWORD]}, since it handles cases
+# where the user is completing in the middle of a word.
+# (For example, if the line is "ls foobar",
+# and the cursor is here --------> ^
+# it will complete just "foo", not "foobar", which is what the user wants.)
+_get_cword()
+{
+ if [[ "${#COMP_WORDS[COMP_CWORD]}" -eq 0 ]] || [[ "$COMP_POINT" == "${#COMP_LINE}" ]]; then
+ echo "${COMP_WORDS[COMP_CWORD]}"
+ else
+ local i
+ local cur="$COMP_LINE"
+ local index="$COMP_POINT"
+ for (( i = 0; i <= COMP_CWORD; ++i )); do
+ while [[ "${#cur}" -ge ${#COMP_WORDS[i]} ]] && [[ "${cur:0:${#COMP_WORDS[i]}}" != "${COMP_WORDS[i]}" ]]; do
+ cur="${cur:1}"
+ index="$(( index - 1 ))"
+ done
+ if [[ "$i" -lt "$COMP_CWORD" ]]; then
+ local old_size="${#cur}"
+ cur="${cur#${COMP_WORDS[i]}}"
+ local new_size="${#cur}"
+ index="$(( index - old_size + new_size ))"
+ fi
+ done
+
+ if [[ "${COMP_WORDS[COMP_CWORD]:0:${#cur}}" != "$cur" ]]; then
+ # We messed up! At least return the whole word so things keep working
+ echo "${COMP_WORDS[COMP_CWORD]}"
+ else
+ echo "${cur:0:$index}"
+ fi
+ fi
+}
+
+
+# This function performs file and directory completion. It's better than
+# simply using 'compgen -f', because it honours spaces in filenames.
+# If passed -d, it completes only on directories. If passed anything else,
+# it's assumed to be a file glob to complete on.
+#
+_filedir()
+{
+ local IFS=$'\t\n' xspec
+
+ _expand || return 0
+
+ local toks=( ) tmp
+ while read -r tmp; do
+ [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp
+ done < <( compgen -d -- "$(quote_readline "$cur")" )
+
+ if [[ "$1" != -d ]]; then
+ xspec=${1:+"!*.$1"}
+ while read -r tmp; do
+ [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp
+ done < <( compgen -f -X "$xspec" -- "$(quote_readline "$cur")" )
+ fi
+
+ COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" )
+}
+
+# This function completes on signal names
+#
+_signals()
+{
+ local i
+
+ # standard signal completion is rather braindead, so we need
+ # to hack around to get what we want here, which is to
+ # complete on a dash, followed by the signal name minus
+ # the SIG prefix
+ COMPREPLY=( $( compgen -A signal SIG${cur#-} ))
+ for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
+ COMPREPLY[i]=-${COMPREPLY[i]#SIG}
+ done
+}
+
+# This function completes on configured network interfaces
+#
+_configured_interfaces()
+{
+ if [ -f /etc/debian_version ]; then
+ # Debian system
+ COMPREPLY=( $( sed -ne 's|^iface \([^ ]\+\).*$|\1|p' \
+ /etc/network/interfaces ) )
+ elif [ -f /etc/SuSE-release ]; then
+ # SuSE system
+ COMPREPLY=( $( command ls \
+ /etc/sysconfig/network/ifcfg-* | \
+ sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
+ elif [ -f /etc/pld-release ]; then
+ # PLD Linux
+ COMPREPLY=( $( command ls -B \
+ /etc/sysconfig/interfaces | \
+ sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
+ else
+ # Assume Red Hat
+ COMPREPLY=( $( command ls \
+ /etc/sysconfig/network-scripts/ifcfg-* | \
+ sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
+ fi
+}
+
+# This function completes on all available network interfaces
+# -a: restrict to active interfaces only
+# -w: restrict to wireless interfaces only
+#
+_available_interfaces()
+{
+ local cmd
+
+ if [ "${1:-}" = -w ]; then
+ cmd="iwconfig"
+ elif [ "${1:-}" = -a ]; then
+ cmd="ifconfig"
+ else
+ cmd="ifconfig -a"
+ fi
+
+ COMPREPLY=( $( eval $cmd 2>/dev/null | \
+ sed -ne 's|^\('$cur'[^[:space:][:punct:]]\{1,\}\).*$|\1|p') )
+}
+
+# This function expands tildes in pathnames
+#
+_expand()
+{
+ # FIXME: Why was this here?
+ # [ "$cur" != "${cur%\\}" ] && cur="$cur\\"
+
+ # expand ~username type directory specifications
+ if [[ "$cur" == \~*/* ]]; then
+ eval cur=$cur
+ elif [[ "$cur" == \~* ]]; then
+ cur=${cur#\~}
+ COMPREPLY=( $( compgen -P '~' -u $cur ) )
+ return ${#COMPREPLY[@]}
+ fi
+}
+
+# This function completes on process IDs.
+# AIX and Solaris ps prefers X/Open syntax.
+[ $UNAME = SunOS -o $UNAME = AIX ] &&
+_pids()
+{
+ COMPREPLY=( $( compgen -W '$( command ps -efo pid | sed 1d )' -- $cur ))
+} ||
+_pids()
+{
+ COMPREPLY=( $( compgen -W '$( command ps axo pid | sed 1d )' -- $cur ) )
+}
+
+# This function completes on process group IDs.
+# AIX and SunOS prefer X/Open, all else should be BSD.
+[ $UNAME = SunOS -o $UNAME = AIX ] &&
+_pgids()
+{
+ COMPREPLY=( $( compgen -W '$( command ps -efo pgid | sed 1d )' -- $cur ))
+} ||
+_pgids()
+{
+ COMPREPLY=( $( compgen -W '$( command ps axo pgid | sed 1d )' -- $cur ))
+}
+
+# This function completes on user IDs
+#
+_uids()
+{
+ if type getent &>/dev/null; then
+ COMPREPLY=( $( getent passwd | \
+ awk -F: '{if ($3 ~ /^'$cur'/) print $3}' ) )
+ elif type perl &>/dev/null; then
+ COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"' )' -- $cur ) )
+ else
+ # make do with /etc/passwd
+ COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\
+ /etc/passwd ) )
+ fi
+}
+
+# This function completes on group IDs
+#
+_gids()
+{
+ if type getent &>/dev/null; then
+ COMPREPLY=( $( getent group | \
+ awk -F: '{if ($3 ~ /^'$cur'/) print $3}' ) )
+ elif type perl &>/dev/null; then
+ COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"' )' -- $cur ) )
+ else
+ # make do with /etc/group
+ COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\
+ /etc/group ) )
+ fi
+}
+
+# This function completes on services
+#
+_services()
+{
+ local sysvdir famdir
+ [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
+ famdir=/etc/xinetd.d
+ COMPREPLY=( $( builtin echo $sysvdir/!(*.rpmsave|*.rpmorig|*~|functions)) )
+
+ if [ -d $famdir ]; then
+ COMPREPLY=( "${COMPREPLY[@]}" $( builtin echo $famdir/!(*.rpmsave|*.rpmorig|*~)) )
+ fi
+
+ COMPREPLY=( $( compgen -W '${COMPREPLY[@]#@($sysvdir|$famdir)/}' -- $cur ) )
+}
+
+# This function complete on modules
+#
+_modules()
+{
+ local modpath
+ modpath=/lib/modules/$1
+ COMPREPLY=( $( command ls -R $modpath | \
+ sed -ne 's/^\('$cur'.*\)\.k\?o\(\|.gz\)$/\1/p') )
+}
+
+# this function complete on user:group format
+#
+_usergroup()
+{
+ local IFS=$'\n'
+ cur=${cur//\\\\ / }
+ if [[ $cur = *@(\\:|.)* ]] && [ -n "$bash205" ]; then
+ user=${cur%%*([^:.])}
+ COMPREPLY=( $(compgen -P ${user/\\\\} -g -- ${cur##*[.:]}) )
+ elif [[ $cur = *:* ]] && [ -n "$bash205" ]; then
+ COMPREPLY=( $( compgen -g -- ${cur##*[.:]} ) )
+ else
+ COMPREPLY=( $( compgen -S : -u -- $cur ) )
+ fi
+}
+
+# this function count the number of mandatory args
+#
+_count_args()
+{
+ args=1
+ for (( i=1; i < COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" != -* ]]; then
+ args=$(($args+1))
+ fi
+ done
+}
+
+# start of section containing completion functions for bash built-ins
+
+# bash alias completion
+#
+_alias()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=${COMP_WORDS[$COMP_CWORD]}
+
+ case "$COMP_LINE" in
+ *[^=])
+ COMPREPLY=( $( compgen -A alias -S '=' -- $cur ) )
+ ;;
+ *=)
+ COMPREPLY=( "$( alias ${cur%=} 2>/dev/null | \
+ sed -e 's|^alias '$cur'\(.*\)$|\1|' )" )
+ ;;
+ esac
+}
+complete -F _alias $nospace alias
+
+# bash export completion
+#
+_export()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=${COMP_WORDS[$COMP_CWORD]}
+
+ case "$COMP_LINE" in
+ *=\$*)
+ COMPREPLY=( $( compgen -v -P '$' -- ${cur#*=\$} ) )
+ ;;
+ *[^=])
+ COMPREPLY=( $( compgen -v -S '=' -- $cur ) )
+ ;;
+ *=)
+ COMPREPLY=( "$( eval echo -n \"$`echo ${cur%=}`\" |
+ ( echo -n \'
+ sed -e 's/'\''/'\''\\\'\'''\''/g'
+ echo -n \' ) )" )
+ ;;
+ esac
+}
+complete -F _export $default $nospace export
+
+# bash shell function completion
+#
+_function()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [[ $1 == @(declare|typeset) ]]; then
+ if [ "$prev" = -f ]; then
+ COMPREPLY=( $( compgen -A function -- $cur ) )
+ elif [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-a -f -F -i -r -x -p' -- \
+ $cur ) )
+ fi
+ elif [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $( compgen -A function -- $cur ) )
+ else
+ COMPREPLY=( "() $( type -- ${COMP_WORDS[1]} | sed -e 1,2d )" )
+ fi
+}
+complete -F _function function declare typeset
+
+# bash complete completion
+#
+_complete()
+{
+ local cur prev options
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case $prev in
+ -o)
+ options="default dirnames filenames"
+ [ -n "$bash205b" ] && options="$options nospace"
+ [ -n "$bash3" ] && options="$options bashdefault plusdirs"
+ COMPREPLY=( $( compgen -W "$options" -- $cur ) )
+ return 0
+ ;;
+
+ -A)
+ COMPREPLY=( $( compgen -W 'alias arrayvar binding \
+ builtin command directory disabled enabled \
+ export file function group helptopic hostname \
+ job keyword running service setopt shopt \
+ signal stopped user variable' -- $cur ) )
+ return 0
+ ;;
+
+ -C)
+ COMPREPLY=( $( compgen -A command -- $cur ) )
+ return 0
+ ;;
+ -F)
+ COMPREPLY=( $( compgen -A function -- $cur ) )
+ return 0
+ ;;
+ -@(p|r))
+ COMPREPLY=( $( complete -p | sed -e 's|.* ||' | \
+ grep "^$cur" ) )
+ return 0
+ ;;
+
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ # relevant options completion
+ options="-a -b -c -d -e -f -g -j -k -s -v -u -A -G -W -P -S -X -F -C"
+ [ -n "$bash205" ] && options="$options -o"
+ COMPREPLY=( $( compgen -W "$options" -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -A command -- $cur ) )
+ fi
+}
+complete -F _complete complete
+
+# start of section containing completion functions for external programs
+
+# a little help for FreeBSD ports users
+[ $UNAME = FreeBSD ] && complete -W 'index search fetch fetch-list \
+ extract patch configure build install reinstall \
+ deinstall clean clean-depends kernel buildworld' make
+
+# This completes on a list of all available service scripts for the
+# 'service' command and/or the SysV init.d directory, followed by
+# that script's available commands
+#
+{ have service || [ -d /etc/init.d/ ]; } &&
+_service()
+{
+ local cur sysvdir
+
+ COMPREPLY=()
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ cur=`_get_cword`
+
+ # don't complete for things like killall, ssh and mysql if it's
+ # the standalone command, rather than the init script
+ [[ ${COMP_WORDS[0]} != @(*init.d/!(functions|~)|service) ]] && return 0
+
+ # don't complete past 2nd token
+ [ $COMP_CWORD -gt 2 ] && return 0
+
+ [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
+ || sysvdir=/etc/init.d
+
+ if [[ $COMP_CWORD -eq 1 ]] && [[ $prev == "service" ]]; then
+ _services
+ else
+ COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \
+ s/^.*Usage.*{\(.*\)}.*$/\1/p" \
+ $sysvdir/${prev##*/} 2>/dev/null`' -- $cur ) )
+ fi
+
+ return 0
+} &&
+complete -F _service service
+[ -d /etc/init.d/ ] && complete -F _service $default \
+ $(for i in /etc/init.d/*; do echo ${i##*/}; done)
+
+# chown(1) completion
+#
+_chown()
+{
+ local cur
+ cur=`_get_cword`
+
+ # options completion
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \
+ --dereference --no-dereference --from= --silent --quiet \
+ --reference= --recursive --verbose --help --version' -- $cur ) )
+ else
+ _count_args
+
+ case $args in
+ 1)
+ _usergroup
+ ;;
+ *)
+ _filedir
+ ;;
+ esac
+ fi
+}
+complete -F _chown $filenames chown
+
+# chgrp(1) completion
+#
+_chgrp()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ cur=${cur//\\\\/}
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # options completion
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \
+ --dereference --no-dereference --silent --quiet \
+ --reference= --recursive --verbose --help --version' -- $cur ) )
+ return 0
+ fi
+
+ # first parameter on line or first since an option?
+ if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]] || \
+ [[ "$prev" == -* ]] && [ -n "$bash205" ]; then
+ local IFS=$'\n'
+ COMPREPLY=( $( compgen -g $cur 2>/dev/null ) )
+ else
+ _filedir || return 0
+ fi
+
+ return 0
+}
+complete -F _chgrp $filenames chgrp
+
+# umount(8) completion. This relies on the mount point being the third
+# space-delimited field in the output of mount(8)
+#
+_umount()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ OLDIFS="$IFS"
+ IFS="\n"
+ COMPREPLY=( $( compgen -W '$( mount | cut -d" " -f 3 )' -- $cur ) )
+ IFS="$OLDIFS"
+
+ return 0
+}
+complete -F _umount $dirnames umount
+
+# mount(8) completion. This will pull a list of possible mounts out of
+# /etc/{,v}fstab, unless the word being completed contains a ':', which
+# would indicate the specification of an NFS server. In that case, we
+# query the server for a list of all available exports and complete on
+# that instead.
+#
+_mount()
+{ local cur i sm host
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ [[ "$cur" == \\ ]] && cur="/"
+
+ for i in {,/usr}/{,s}bin/showmount; do [ -x $i ] && sm=$i && break; done
+
+ if [ -n "$sm" ] && [[ "$cur" == *:* ]]; then
+ COMPREPLY=( $( $sm -e ${cur%%:*} | sed 1d | \
+ grep ^${cur#*:} | awk '{print $1}' ) )
+ elif [[ "$cur" == //* ]]; then
+ host=${cur#//}
+ host=${host%%/*}
+ if [ -n "$host" ]; then
+ COMPREPLY=( $( compgen -W "$( echo $( smbclient -d 0 -NL $host 2>/dev/null|
+ sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' |
+ sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|//'$host'/\1|p' ) )" -- "$cur" ) )
+ fi
+ elif [ -r /etc/vfstab ]; then
+ # Solaris
+ COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \
+ /etc/vfstab | grep "^$cur" ) )
+ elif [ ! -e /etc/fstab ]; then
+ # probably Cygwin
+ COMPREPLY=( $( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \
+ | grep "^$cur" ) )
+ else
+ # probably Linux
+ COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' \
+ /etc/fstab | grep "^$cur" ) )
+ fi
+
+ return 0
+}
+complete -F _mount $default $filenames mount
+
+# Linux rmmod(8) completion. This completes on a list of all currently
+# installed kernel modules.
+#
+have rmmod && {
+_rmmod()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ COMPREPLY=( $( /sbin/lsmod | \
+ awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' 2>/dev/null ))
+ return 0
+}
+complete -F _rmmod rmmod
+
+# Linux insmod(8), modprobe(8) and modinfo(8) completion. This completes on a
+# list of all available modules for the version of the kernel currently
+# running.
+#
+_insmod()
+{
+ local cur prev modpath
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # behave like lsmod for modprobe -r
+ if [ $1 = "modprobe" ] &&
+ [ "${COMP_WORDS[1]}" = "-r" ]; then
+ COMPREPLY=( $( /sbin/lsmod | \
+ awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' ) )
+ return 0
+ fi
+
+ # do filename completion if we're giving a path to a module
+ if [[ "$cur" == */* ]]; then
+ _filedir '@(?(k)o?(.gz))'
+ return 0
+ fi
+
+ if [ $COMP_CWORD -gt 1 ] &&
+ [[ "${COMP_WORDS[COMP_CWORD-1]}" != -* ]]; then
+ # do module parameter completion
+ COMPREPLY=( $( /sbin/modinfo -p ${COMP_WORDS[1]} 2>/dev/null | \
+ awk '{if ($1 ~ /^parm:/ && $2 ~ /^'$cur'/) { print $2 } \
+ else if ($1 !~ /:/ && $1 ~ /^'$cur'/) { print $1 }}' ) )
+ else
+ _modules $(uname -r)
+ fi
+
+ return 0
+}
+complete -F _insmod $filenames insmod modprobe modinfo
+}
+
+# man(1) completion
+#
+[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \
+ -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \
+ -o $UNAME = OpenBSD ] &&
+_man()
+{
+ local cur prev sect manpath UNAME
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ _expand || return 0
+
+ # default completion if parameter contains /
+ if [[ "$cur" == */* ]]; then
+ _filedir
+ return 0
+ fi
+
+ UNAME=$( uname -s )
+ # strip OS type and version under Cygwin
+ UNAME=${UNAME/CYGWIN_*/Cygwin}
+ if [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = FreeBSD \
+ -o $UNAME = Cygwin ]; then
+ manpath=$( manpath 2>/dev/null || command man --path )
+ else
+ manpath=$MANPATH
+ fi
+
+ if [ -z "$manpath" ]; then
+ COMPREPLY=( $( compgen -c -- $cur ) )
+ return 0
+ fi
+
+ # determine manual section to search
+ [[ "$prev" == [0-9ln] ]] && sect=$prev || sect='*'
+
+ manpath=$manpath:
+ if [ -n "$cur" ]; then
+ manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }"
+ else
+ manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }"
+ fi
+
+ # redirect stderr for when path doesn't exist
+ COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) )
+ # weed out directory path names and paths to man pages
+ COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
+ # strip suffix from man pages
+ COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
+ COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
+
+ [[ "$prev" != [0-9ln] ]] && _filedir '[0-9ln]'
+
+ return 0
+}
+[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \
+ -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \
+ -o $UNAME = OpenBSD ] && \
+complete -F _man $filenames man apropos whatis
+
+# renice(8) completion
+#
+_renice()
+{
+ local command cur curopt i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ command=$1
+
+ i=0
+ # walk back through command line and find last option
+ while [ $i -le $COMP_CWORD -a ${#COMPREPLY[@]} -eq 0 ]; do
+ curopt=${COMP_WORDS[COMP_CWORD-$i]}
+ case "$curopt" in
+ -u)
+ COMPREPLY=( $( compgen -u -- $cur ) )
+ ;;
+ -g)
+ _pgids
+ ;;
+ -p|$command)
+ _pids
+ ;;
+ esac
+ i=$(( ++i ))
+ done
+}
+complete -F _renice renice
+
+# kill(1) completion
+#
+_kill()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
+ # return list of available signals
+ _signals
+ else
+ # return list of available PIDs
+ _pids
+ fi
+}
+complete -F _kill kill
+
+# Linux and FreeBSD killall(1) completion.
+#
+[ $UNAME = Linux -o $UNAME = FreeBSD ] &&
+_killall()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
+ _signals
+ else
+ COMPREPLY=( $( compgen -W '$( command ps axo command | \
+ sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \
+ sed -e "s/.*\///" )' -- $cur ) )
+ fi
+
+ return 0
+}
+[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _killall killall pkill
+
+# Linux and FreeBSD pgrep(1) completion.
+#
+[ $UNAME = Linux -o $UNAME = FreeBSD ] &&
+_pgrep()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ COMPREPLY=( $( compgen -W '$( command ps axo command | \
+ sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \
+ sed -e "s/.*\///" )' -- $cur ) )
+
+ return 0
+}
+[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _pgrep pgrep
+# Linux pidof(8) completion.
+[ $UNAME = Linux ] && complete -F _pgrep pidof
+
+# GNU find(1) completion. This makes heavy use of ksh style extended
+# globs and contains Linux specific code for completing the parameter
+# to the -fstype option.
+#
+_find()
+{
+ local cur prev i exprfound onlyonce
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(max|min)depth)
+ COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' -- $cur ) )
+ return 0
+ ;;
+ -?(a|c)newer|-fls|-fprint?(0|f)|-?(i)?(l)name|-?(i)wholename)
+ _filedir
+ return 0
+ ;;
+ -fstype)
+ # this is highly non-portable
+ [ -e /proc/filesystems ] &&
+ COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | \
+ grep "^$cur" ) )
+ return 0
+ ;;
+ -gid)
+ _gids
+ return 0
+ ;;
+ -group)
+ if [ -n "$bash205" ]; then
+ COMPREPLY=( $( compgen -g -- $cur 2>/dev/null) )
+ fi
+ return 0
+ ;;
+ -?(x)type)
+ COMPREPLY=( $( compgen -W 'b c d p f l s' -- $cur ) )
+ return 0
+ ;;
+ -uid)
+ _uids
+ return 0
+ ;;
+ -user)
+ COMPREPLY=( $( compgen -u -- $cur ) )
+ return 0
+ ;;
+ -exec|-ok)
+ COMP_WORDS=(COMP_WORDS[0] $cur)
+ COMP_CWORD=1
+ _command
+ return 0
+ ;;
+ -[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \
+ -links|-perm|-size|-used|-printf)
+ # do nothing, just wait for a parameter to be given
+ return 0
+ ;;
+ esac
+
+ _expand || return 0
+
+ # set exprfound to 1 if there is already an expression present
+ for i in ${COMP_WORDS[@]}; do
+ [[ "$i" = [-\(\),\!]* ]] && exprfound=1 && break
+ done
+
+ # handle case where first parameter is not a dash option
+ if [ "$exprfound" != 1 ] && [[ "$cur" != [-\(\),\!]* ]]; then
+ _filedir -d
+ return 0
+ fi
+
+ # complete using basic options
+ COMPREPLY=( $( compgen -W '-daystart -depth -follow -help -maxdepth \
+ -mindepth -mount -noleaf -version -xdev -amin -anewer \
+ -atime -cmin -cnewer -ctime -empty -false -fstype \
+ -gid -group -ilname -iname -inum -ipath -iregex \
+ -wholename \
+ -links -lname -mmin -mtime -name -newer -nouser \
+ -nogroup -perm -regex -size -true -type -uid -used \
+ -user -xtype -exec -fls -fprint -fprint0 -fprintf -ok \
+ -print -print0 -printf -prune -ls' -- $cur ) )
+
+ # this removes any options from the list of completions that have
+ # already been specified somewhere on the command line, as long as
+ # these options can only be used once (in a word, "options", in
+ # opposition to "tests" and "actions", as in the find(1) manpage).
+ onlyonce=' -daystart -depth -follow -help -maxdepth -mindepth -mount \
+ -noleaf -version -xdev '
+ COMPREPLY=( $( echo "${COMP_WORDS[@]}" | \
+ (while read -d ' ' i; do
+ [ "$i" == "" ] ||
+ [ "${onlyonce/ ${i%% *} / }" == "$onlyonce" ] &&
+ continue
+ # flatten array with spaces on either side,
+ # otherwise we cannot grep on word boundaries of
+ # first and last word
+ COMPREPLY=" ${COMPREPLY[@]} "
+ # remove word from list of completions
+ COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
+ done
+ echo "${COMPREPLY[@]}")
+ ) )
+
+ _filedir
+
+ return 0
+}
+complete -F _find $filenames find
+
+# Linux iwconfig(8) completion
+#
+[ $UNAME = Linux ] && have iwconfig &&
+_iwconfig()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case $prev in
+ mode)
+ COMPREPLY=( $( compgen -W 'managed ad-hoc master \
+ repeater secondary monitor' -- $cur ) )
+ return 0
+ ;;
+ essid)
+ COMPREPLY=( $( compgen -W 'on off any' -- $cur ) )
+ if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
+ COMPREPLY=( "${COMPREPLY[@]}" \
+ $( iwlist ${COMP_WORDS[1]} scan | \
+ awk -F '"' '/ESSID/ {print $2}' | \
+ grep "^$cur" ))
+ fi
+ return 0
+ ;;
+ nwid)
+ COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
+ return 0
+ ;;
+ channel)
+ COMPREPLY=( $( iwlist ${COMP_WORDS[1]} channel | \
+ awk '/^[[:space:]]*Channel/ {print $2}' | \
+ grep "^$cur" ) )
+ return 0
+ ;;
+
+ freq)
+ COMPREPLY=( $( iwlist ${COMP_WORDS[1]} channel | \
+ awk '/^[[:space:]]*Channel/ {print $4"G"}' | \
+ grep "^$cur" ) )
+ return 0
+ ;;
+ ap)
+ COMPREPLY=( $( compgen -W 'on off any' -- $cur ) )
+ if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
+ COMPREPLY=( "${COMPREPLY[@]}" \
+ $( iwlist ${COMP_WORDS[1]} scan | \
+ awk -F ': ' '/Address/ {print $2}' | \
+ grep "^$cur" ) )
+ fi
+ return 0
+ ;;
+ rate)
+ COMPREPLY=( $( compgen -W 'auto fixed' -- $cur ) )
+ COMPREPLY=( "${COMPREPLY[@]}" \
+ $( iwlist ${COMP_WORDS[1]} rate | \
+ awk '/^[[:space:]]*[0-9]/ {print $1"M"}' | \
+ grep "^$cur" ) )
+ return 0
+ ;;
+ rts)
+ COMPREPLY=( $( compgen -W 'auto fixed off' -- $cur ) )
+ return 0
+ ;;
+ frag)
+ COMPREPLY=( $( compgen -W 'auto fixed off' -- $cur ) )
+ return 0
+ ;;
+ key)
+ COMPREPLY=( $( compgen -W 'off on open restricted' -- $cur ) )
+ return 0
+ ;;
+ enc)
+ COMPREPLY=( $( compgen -W 'off on open restricted' -- $cur ) )
+ return 0
+ ;;
+ power)
+ COMPREPLY=( $( compgen -W 'period timeout off on' -- $cur ) )
+ return 0
+ ;;
+ txpower)
+ COMPREPLY=( $( compgen -W 'off on auto' -- $cur ) )
+ return 0
+ ;;
+ retry)
+ COMPREPLY=( $( compgen -W 'limit lifetime' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--help --version' -- $cur ) )
+ else
+ _available_interfaces -w
+ fi
+ else
+ COMPREPLY=( $( compgen -W 'essid nwid mode freq channel sens mode \
+ ap nick rate rts frag enc key power txpower commit' -- $cur ) )
+ fi
+
+} &&
+complete -F _iwconfig iwconfig
+
+# Linux iwlist(8) completion
+#
+[ $UNAME = Linux ] && have iwlist &&
+_iwlist()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--help --version' -- $cur ) )
+ else
+ _available_interfaces -w
+ fi
+ else
+ COMPREPLY=( $( compgen -W 'scan scanning freq frequency \
+ channel rate bit bitrate key enc encryption power \
+ txpower retry ap accesspoint peers event' -- $cur ) )
+ fi
+} &&
+complete -F _iwlist iwlist
+
+# Linux iwspy(8) completion
+#
+[ $UNAME = Linux ] && have iwspy &&
+_iwspy()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--help --version' -- $cur ) )
+ else
+ _available_interfaces -w
+ fi
+ else
+ COMPREPLY=( $( compgen -W 'setthr getthr off' -- $cur ) )
+ fi
+} &&
+complete -F _iwspy iwspy
+
+# Linux iwpriv(8) completion
+#
+[ $UNAME = Linux ] && have iwpriv &&
+_iwpriv()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ roam)
+ COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
+ return 0
+ ;;
+ port)
+ COMPREPLY=( $( compgen -W 'ad-hoc managed' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--help --version' -- $cur ) )
+ else
+ _available_interfaces -w
+ fi
+ else
+ COMPREPLY=( $( compgen -W '--all roam port' -- $cur ) )
+ fi
+} &&
+complete -F _iwpriv iwpriv
+
+# RedHat & Debian GNU/Linux if{up,down} completion
+#
+[ $UNAME = Linux ] && { have ifup || have ifdown; } &&
+_ifupdown()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ _configured_interfaces
+ COMPREPLY=( $(compgen -W '${COMPREPLY[@]}' -- "$cur") )
+ fi
+
+ return 0
+} &&
+complete -F _ifupdown ifup ifdown
+[ $UNAME = Linux ] && have ifstatus && complete -F _ifupdown ifstatus
+
+# Linux ipsec(8) completion (for FreeS/WAN)
+#
+[ $UNAME = Linux ] && have ipsec &&
+_ipsec()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $( compgen -W 'auto barf eroute klipsdebug look \
+ manual pluto ranbits rsasigkey \
+ setup showdefaults showhostkey spi \
+ spigrp tncfg whack' -- $cur ) )
+ return 0
+ fi
+
+ case ${COMP_WORDS[1]} in
+ auto)
+ COMPREPLY=( $( compgen -W '--asynchronous --up --add --delete \
+ --replace --down --route --unroute \
+ --ready --status --rereadsecrets' \
+ -- $cur ) )
+ ;;
+ manual)
+ COMPREPLY=( $( compgen -W '--up --down --route --unroute \
+ --union' -- $cur ) )
+ ;;
+ ranbits)
+ COMPREPLY=( $( compgen -W '--quick --continuous --bytes' \
+ -- $cur ) )
+ ;;
+ setup)
+ COMPREPLY=( $( compgen -W '--start --stop --restart' -- $cur ) )
+ ;;
+
+ *)
+ ;;
+ esac
+
+ return 0
+} &&
+complete -F _ipsec ipsec
+
+# Postfix completion.
+#
+have postfix && {
+# postfix(1)
+#
+_postfix()
+{
+ local cur prev
+
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [[ $cur == '-' ]]; then
+ COMPREPLY=(-c -D -v)
+ return 0
+ fi
+ if [[ $prev == '-c' ]]; then
+ _filedir -d
+ return 0
+ fi
+ if [[ $prev == '-D' ]]; then
+ COMPREPLY=( $( compgen -W 'start' -- "`get_cword`" ) )
+ return 0
+ fi
+ COMPREPLY=( $( compgen -W 'start stop reload abort flush check' -- \
+ "`get_cword`" ) )
+}
+complete -F _postfix postfix
+
+# postalias(1) and postmap(1)
+#
+_postmap()
+{
+ local cur prev len idx
+
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [[ $cur == '-' ]]; then
+ COMPREPLY=(-N -f -i -n -o -p -r -v -w -c -d -q)
+ return 0
+ fi
+ if [[ $prev == '-c' ]]; then
+ _filedir -d
+ return 0
+ fi
+ if [[ $prev == -[dq] ]]; then
+ return 0
+ fi
+
+ if [[ "$cur" == *:* ]]; then
+ COMPREPLY=( $( compgen -f -- ${cur#*:} ) )
+ else
+ len=${#cur}
+ idx=0
+ for pval in $( /usr/sbin/postconf -m ); do
+ if [[ "$cur" == "${pval:0:$len}" ]]; then
+ COMPREPLY[$idx]="$pval:"
+ idx=$(($idx+1))
+ fi
+ done
+ if [[ $idx -eq 0 ]]; then
+ COMPREPLY=( $( compgen -f -- "$cur" ) )
+ fi
+ fi
+ return 0
+}
+complete -F _postmap postmap postalias
+
+# postcat(1)
+#
+_postcat()
+{
+ local cur prev pval len idx qfile
+
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [[ $cur == '-' ]]; then
+ COMPREPLY=(-c -q -v)
+ return 0
+ fi
+ if [[ $prev == '-c' ]]; then
+ _filedir -d
+ return 0
+ fi
+
+ qfile=0
+ for idx in "${COMP_WORDS[@]}"; do
+ [[ "$idx" = -q ]] && qfile=1 && break
+ done
+ if [[ $qfile == 1 ]]; then
+ len=${#cur}
+ idx=0
+ for pval in $( mailq | \
+ sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do
+ if [[ "$cur" == "${pval:0:$len}" ]]; then
+ COMPREPLY[$idx]=$pval
+ idx=$(($idx+1))
+ fi
+ done
+ return 0
+ else
+ _filedir
+ return 0
+ fi
+}
+complete -F _postcat postcat
+
+# postconf(1)
+#
+_postconf()
+{
+ local cur prev pval len idx eqext
+
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ if [[ $cur == '-' ]]; then
+ COMPREPLY=(-c -d -e -h -m -l -n -v)
+ return 0
+ fi
+ if [[ $prev == '-c' ]]; then
+ _filedir -d
+ return 0
+ fi
+ if [[ $prev == '-e' ]]; then
+ cur=${cur#[\"\']}
+ eqext='='
+ fi
+ len=${#cur}
+ idx=0
+ for pval in $( /usr/sbin/postconf | cut -d ' ' -f 1 ); do
+ if [[ "$cur" == "${pval:0:$len}" ]]; then
+ COMPREPLY[$idx]="$pval$eqext"
+ idx=$(($idx+1))
+ fi
+ done
+ return 0
+}
+complete -F _postconf postconf
+
+# postsuper(1)
+#
+_postsuper()
+{
+ local cur prev pval len idx
+
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [[ $cur == '-' ]]; then
+ COMPREPLY=(-c -d -h -H -p -r -s -v)
+ return 0
+ fi
+ case $prev in
+ -[dr])
+ len=${#cur}
+ idx=0
+ for pval in $( echo ALL; mailq | \
+ sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do
+ if [[ "$cur" == "${pval:0:$len}" ]]; then
+ COMPREPLY[$idx]=$pval
+ idx=$(($idx+1))
+ fi
+ done
+ return 0
+ ;;
+ -h)
+ len=${#cur}
+ idx=0
+ for pval in $( echo ALL; mailq | \
+ sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* ].*$//; /!$/d' ); do
+ if [[ "$cur" == "${pval:0:$len}" ]]; then
+ COMPREPLY[$idx]=$pval
+ idx=$(($idx+1))
+ fi
+ done
+ return 0
+ ;;
+ -H)
+ len=${#cur}
+ idx=0
+ for pval in $( echo ALL; mailq | \
+ sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//' ); do
+ if [[ "$cur" == "${pval:0:$len}" ]]; then
+ COMPREPLY[$idx]=$pval
+ idx=$(($idx+1))
+ fi
+ done
+ return 0
+ ;;
+ esac
+ COMPREPLY=( $( compgen -W 'hold incoming active deferred' -- $cur ) )
+ return 0
+}
+complete -F _postsuper postsuper
+}
+
+# cvs(1) completion
+#
+have cvs && {
+set_prefix()
+{
+ [ -z ${prefix:-} ] || prefix=${cur%/*}/
+ [ -r ${prefix:-}CVS/Entries ] || prefix=""
+}
+
+get_entries()
+{
+ local IFS=$'\n'
+ [ -r ${prefix:-}CVS/Entries ] && \
+ entries=$(cut -d/ -f2 -s ${prefix:-}CVS/Entries)
+}
+
+get_modules()
+{
+ if [ -n "$prefix" ]; then
+ COMPREPLY=( $( command ls -d ${cvsroot}/${prefix}/!(CVSROOT) ) )
+ else
+ COMPREPLY=( $( command ls -d ${cvsroot}/!(CVSROOT) ) )
+ fi
+}
+
+_cvs()
+{
+ local cur count mode i cvsroot cvsroots pwd
+ local -a flags miss files entries changed newremoved
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ count=0
+ for i in "${COMP_WORDS[@]}"; do
+ [ $count -eq $COMP_CWORD ] && break
+ # Last parameter was the CVSROOT, now go back to mode selection
+ if [ "${COMP_WORDS[((count))]}" == "$cvsroot" -a "$mode" == "cvsroot" ]; then
+ mode=""
+ fi
+ if [ -z "$mode" ]; then
+ case $i in
+ -d)
+ mode=cvsroot
+ cvsroot=${COMP_WORDS[((count+1))]}
+ ;;
+ @(ad?(d)|new))
+ mode=add
+ ;;
+ @(adm?(in)|rcs))
+ mode=admin
+ ;;
+ ann?(notate))
+ mode=annotate
+ ;;
+ @(checkout|co|get))
+ mode=checkout
+ ;;
+ @(com?(mit)|ci))
+ mode=commit
+ ;;
+ di?(f?(f)))
+ mode=diff
+ ;;
+ ex?(p?(ort)))
+ mode=export
+ ;;
+ ?(un)edit)
+ mode=$i
+ ;;
+ hi?(s?(tory)))
+ mode=history
+ ;;
+ im?(p?(ort)))
+ mode=import
+ ;;
+ re?(l?(ease)))
+ mode=release
+ ;;
+ ?(r)log)
+ mode=log
+ ;;
+ @(rdiff|patch))
+ mode=rdiff
+ ;;
+ @(remove|rm|delete))
+ mode=remove
+ ;;
+ @(rtag|rfreeze))
+ mode=rtag
+ ;;
+ st?(at?(us)))
+ mode=status
+ ;;
+ @(tag|freeze))
+ mode=tag
+ ;;
+ up?(d?(ate)))
+ mode=update
+ ;;
+ *)
+ ;;
+ esac
+ elif [[ "$i" = -* ]]; then
+ flags=( "${flags[@]}" $i )
+ fi
+ count=$((++count))
+ done
+
+ case "$mode" in
+ add)
+ if [[ "$cur" != -* ]]; then
+ set_prefix
+ if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then
+ get_entries
+ [ -z "$cur" ] && \
+ files=$( command ls -Ad !(CVS) ) || \
+ files=$( command ls -d ${cur}* 2>/dev/null )
+ for i in "${entries[@]}"; do
+ files=( ${files[@]/#$i//} )
+ done
+ COMPREPLY=( $( compgen -W '${files[@]}' -- \
+ $cur ) )
+ fi
+ else
+ COMPREPLY=( $( compgen -W '-k -m' -- $cur ) )
+ fi
+ ;;
+ admin)
+ if [[ "$cur" = -* ]]; then
+ COMPREPLY=( $( compgen -W '-i -a -A -e -b -c -k -l -u \
+ -L -U -m -M -n -N -o -q -I \
+ -s -t -t- -T -V -x -z' -- \
+ $cur ) )
+ fi
+ ;;
+ annotate)
+ if [[ "$cur" = -* ]]; then
+ COMPREPLY=( $( compgen -W '-D -F -f -l -R -r' -- $cur ) )
+ else
+ get_entries
+ COMPREPLY=( $( compgen -W '${entries[@]}' -- $cur ) )
+ fi
+ ;;
+ checkout)
+ if [[ "$cur" != -* ]]; then
+ [ -z "$cvsroot" ] && cvsroot=$CVSROOT
+ COMPREPLY=( $( cvs -d "$cvsroot" co -c 2> /dev/null | \
+ awk '{print $1}' ) )
+ COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -W '-A -N -P -R -c -f -l -n -p \
+ -s -r -D -d -k -j' -- $cur ) )
+ fi
+ ;;
+ commit)
+ set_prefix
+
+ if [[ "$cur" != -* ]] && [ -r ${prefix:-}CVS/Entries ]; then
+ # if $COMP_CVS_REMOTE is not null, 'cvs commit' will
+ # complete on remotely checked-out files (requires
+ # passwordless access to the remote repository
+ if [ -n "${COMP_CVS_REMOTE:-}" ]; then
+ # this is the least computationally intensive
+ # way found so far, but other changes
+ # (something other than changed/removed/new)
+ # may be missing
+ changed=( $( cvs -q diff --brief 2>&1 | \
+ sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) )
+ newremoved=( $( cvs -q diff --brief 2>&1 | \
+ sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) )
+ COMPREPLY=( $( compgen -W '${changed[@]:-} \
+ ${newremoved[@]:-}' -- $cur ) )
+ else
+ _filedir
+ fi
+ else
+ COMPREPLY=( $( compgen -W '-n -R -l -f -F -m -r' -- \
+ $cur ) )
+ fi
+ ;;
+ cvsroot)
+ if [ -r ~/.cvspass ]; then
+ # Ugly escaping because of bash treating ':' specially
+ cvsroots=$( sed 's/^[^ ]* //; s/:/\\:/g' ~/.cvspass )
+ COMPREPLY=( $( compgen -W '$cvsroots' -- $cur ) )
+ fi
+ ;;
+ export)
+ if [[ "$cur" != -* ]]; then
+ [ -z "$cvsroot" ] && cvsroot=$CVSROOT
+ COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) )
+ COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -W '-N -f -l -R -n \
+ -r -D -d -k' -- $cur ) )
+ fi
+ ;;
+ diff)
+ if [[ "$cur" == -* ]]; then
+ _longopt diff
+ else
+ get_entries
+ COMPREPLY=( $( compgen -W '${entries[@]:-}' -- $cur ) )
+ fi
+ ;;
+ remove)
+ if [[ "$cur" != -* ]]; then
+ set_prefix
+ if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then
+ get_entries
+ # find out what files are missing
+ for i in "${entries[@]}"; do
+ [ ! -r "$i" ] && miss=( "${miss[@]}" $i )
+ done
+ COMPREPLY=( $(compgen -W '${miss[@]:-}' -- $cur) )
+ fi
+ else
+ COMPREPLY=( $( compgen -W '-f -l -R' -- $cur ) )
+ fi
+ ;;
+ import)
+ if [[ "$cur" != -* ]]; then
+ # starts with same algorithm as checkout
+ [ -z "$cvsroot" ] && cvsroot=$CVSROOT
+ prefix=${cur%/*}
+ if [ -r ${cvsroot}/${prefix} ]; then
+ get_modules
+ COMPREPLY=( ${COMPREPLY[@]#$cvsroot} )
+ COMPREPLY=( ${COMPREPLY[@]#\/} )
+ fi
+ pwd=$( pwd )
+ pwd=${pwd##*/}
+ COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- \
+ $cur ) )
+ else
+ COMPREPLY=( $( compgen -W '-d -k -I -b -m -W' -- $cur ))
+ fi
+ ;;
+ update)
+ if [[ "$cur" = -* ]]; then
+ COMPREPLY=( $( compgen -W '-A -P -C -d -f -l -R -p \
+ -k -r -D -j -I -W' -- \
+ $cur ) )
+ fi
+ ;;
+ "")
+ COMPREPLY=( $( compgen -W 'add admin annotate checkout ci co \
+ commit diff delete edit export \
+ freeze get history import log new \
+ patch rcs rdiff release remove \
+ rfreeze rlog rm rtag stat status \
+ tag unedit up update -H -Q -q -b \
+ -d -e -f -l -n -t -r -v -w -x -z \
+ --help --version' -- $cur ) )
+ ;;
+ *)
+ ;;
+ esac
+
+ return 0
+}
+complete -F _cvs $default cvs
+}
+
+have rpm && {
+# helper functions for rpm completion
+#
+_rpm_installed_packages()
+{
+ local ver nodig nosig
+
+ if [ -r /var/log/rpmpkgs -a \
+ /var/log/rpmpkgs -nt /var/lib/rpm/Packages ]; then
+ # using RHL 7.2 or later - this is quicker than querying the DB
+ COMPREPLY=( $( sed -ne \
+ 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+.*\.rpm$|\1|p' \
+ /var/log/rpmpkgs ) )
+ else
+ nodig=""
+ nosig=""
+ ver=$(rpm --version)
+ ver=${ver##* }
+
+ if [[ "$ver" > "4.0.4" ]]; then
+ nodig="--nodigest"
+ fi
+ if [[ "$ver" > "4.0.99" ]]; then
+ nosig="--nosignature"
+ fi
+
+ COMPREPLY=( $( rpm -qa $nodig $nosig | sed -ne \
+ 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+$|\1|p' ) )
+ fi
+}
+
+_rpm_groups()
+{
+ local IFS=$'\t'
+ # remove trailing backslash, or grep will complain
+ cur=${cur%"\\"}
+ COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat '%{group}\n' | \
+ grep "^$cur" ) )
+ # backslash escape spaces and translate newlines to tabs
+ COMPREPLY=( $( echo "${COMPREPLY[@]}" | sed 's/ /\\ /g' | tr '\n' '\t' ) )
+}
+
+# rpm(8) completion
+#
+_rpm()
+{
+ local cur prev ver nodig nosig
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ nodig=""
+ nosig=""
+ ver=$(rpm --version); ver=${ver##* }
+
+ if [[ "$ver" > "4.0.4" ]]; then
+ nodig="--nodigest"
+ fi
+ if [[ "$ver" > "4.0.99" ]]; then
+ nosig="--nosignature"
+ fi
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ # first parameter on line
+ case "$cur" in
+ -b*)
+ COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs'\
+ -- $cur ) )
+ ;;
+ -t*)
+ COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts'\
+ -- $cur ) )
+ ;;
+ --*)
+ COMPREPLY=( $( compgen -W '--help --version --initdb \
+ --checksig --recompile --rebuild --resign --addsign \
+ --rebuilddb --showrc --setperms --setugids --tarbuild \
+ --eval --install --upgrade --query --freshen --erase \
+ --verify --querytags --rmsource --rmspec --clean \
+ --import' -- $cur ) )
+ ;;
+ *)
+ COMPREPLY=( $( compgen -W '-b -e -F -i -q -t -U -V' \
+ -- $cur ) )
+ ;;
+ esac
+
+ return 0
+ fi
+
+ case "$prev" in
+ --@(@(db|exclude)path|prefix|relocate|root))
+ _filedir -d
+ return 0
+ ;;
+ --eval)
+ # get a list of macros
+ COMPREPLY=( $( sed -ne 's|^\(%'${cur#\%}'[^ '$'\t'']*\).*$|\1|p' \
+ /usr/lib/rpm/macros ) )
+ return 0
+ ;;
+ --pipe)
+ COMPREPLY=( $( compgen -c -- $cur ) )
+ return 0
+ ;;
+ --rcfile)
+ _filedir
+ return 0
+ ;;
+ --specfile)
+ # complete on .spec files
+ _filedir spec
+ return 0
+ ;;
+ --whatprovides)
+ if [[ "$cur" == */* ]]; then
+ _filedir
+ else
+ # complete on capabilities
+ COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \
+ '%{providename}\n' | grep "^$cur" ) )
+ fi
+ return 0
+ ;;
+ --whatrequires)
+ # complete on capabilities
+ COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \
+ '%{requirename}\n' | grep "^$cur" ) )
+ return 0
+ ;;
+ esac
+
+ case "${COMP_WORDS[1]}" in
+ -@([iFU]*|-install|-freshen|-upgrade))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--percent --force --test \
+ --replacepkgs --replacefiles --root --excludedocs \
+ --includedocs --noscripts --rcfile --ignorearch \
+ --dbpath --prefix --ignoreos --nodeps --allfiles \
+ --ftpproxy --ftpport --justdb --httpproxy --httpport \
+ --noorder --relocate --badreloc --notriggers \
+ --excludepath --ignoresize --oldpackage --define \
+ --eval --pipe --queryformat --repackage --nosuggests \
+ --nodigest --nosignature' -- $cur ) )
+ else
+ _filedir 'rpm'
+ fi
+ ;;
+ -@(e|-erase))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--allmatches --noscripts \
+ --notriggers --nodeps --test --repackage' -- $cur ) )
+ else
+ _rpm_installed_packages
+ fi
+ ;;
+ -@(q*|-query))
+ # check whether we're doing file completion
+ if [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--scripts --root \
+ --rcfile --requires --ftpport --ftpproxy \
+ --httpproxy --httpport --provides --triggers \
+ --dump --changelog --dbpath \
+ --last --filesbypkg \
+ --info --list --state \
+ --docfiles --configfiles --queryformat \
+ --conflicts --obsoletes \
+ --nodigest --nosignature \
+ --triggerscripts' -- $cur ) )
+ else
+ _filedir
+ fi
+ elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then
+ _rpm_groups
+ elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then
+ # uninstalled package completion
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--scripts --root \
+ --rcfile --whatprovides --whatrequires \
+ --requires --triggeredby --ftpport --ftpproxy \
+ --httpproxy --httpport --provides --triggers \
+ --dump --changelog --dbpath --filesbypkg \
+ --define --eval --pipe --showrc --info --list \
+ --state --docfiles --configfiles --queryformat\
+ --conflicts --obsoletes --nodigest \
+ --nosignature' -- $cur ) )
+ else
+ _filedir 'rpm'
+ fi
+ else
+ # installed package completion
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--scripts --root \
+ --rcfile --whatprovides --whatrequires \
+ --requires --triggeredby --ftpport --ftpproxy \
+ --httpproxy --httpport --provides --triggers \
+ --dump --changelog --dbpath --specfile \
+ --querybynumber --last --filesbypkg --define \
+ --eval --pipe --showrc --info --list --state \
+ --docfiles --configfiles --queryformat \
+ --conflicts --obsoletes --pkgid --hdrid \
+ --fileid --tid --nodigest --nosignature \
+ --triggerscripts' -- $cur ) )
+ elif [ "${COMP_LINE#* -*([^ -])a}" == "$COMP_LINE" ]; then
+ _rpm_installed_packages
+ fi
+ fi
+ ;;
+ -@(K*|-checksig))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--nopgp --nogpg --nomd5 \
+ --nodigest --nosignature' -- $cur ) )
+ else
+ _filedir 'rpm'
+ fi
+ ;;
+ -@([Vy]*|-verify))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--root --rcfile --dbpath \
+ --nodeps --nogroup --nolinkto --nomode --nomtime \
+ --nordev --nouser --nofiles --noscripts --nomd5 \
+ --querytags --specfile --whatrequires --whatprovides \
+ --nodigest --nosignature' -- $cur ) )
+ # check whether we're doing file completion
+ elif [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then
+ _filedir
+ elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then
+ _rpm_groups
+ elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then
+ _filedir 'rpm'
+ else
+ _rpm_installed_packages
+ fi
+ ;;
+ -[bt]*)
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--short-circuit --timecheck \
+ --clean --rmsource --rmspec --test --sign --buildroot \
+ --target -- buildarch --buildos --nobuild --nodeps \
+ --nodirtokens' -- $cur ) )
+ elif [[ ${COMP_WORDS[1]} == -b* ]]; then
+ _filedir 'spec'
+ else
+ _filedir '@(tgz|tar.@(gz|bz2))'
+ fi
+ ;;
+ --re@(build|compile))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--nodeps --rmsource \
+ --rmspec --sign --nodirtokens --target' -- $cur ) )
+ else
+ _filedir '?(no)src.rpm'
+ fi
+ ;;
+ --tarbuild)
+ _filedir '@(tgz|tar.@(gz|bz2))'
+ ;;
+ --@(re|add)sign)
+ _filedir 'rpm'
+ ;;
+ --set@(perms|gids))
+ _rpm_installed_packages
+ ;;
+ --@(clean|rms@(ource|pec)))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--clean --rmsource \
+ --rmspec' -- $cur ) )
+ else
+ _filedir 'spec'
+ fi
+ ;;
+ --@(import|dbpath|root))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--import --dbpath --root' \
+ -- $cur ) )
+ else
+ _filedir
+ fi
+ ;;
+ esac
+
+ return 0
+}
+complete -F _rpm $filenames rpm rpmbuild
+}
+
+# Debian apt-get(8) completion.
+#
+have apt-get &&
+_apt_get()
+{
+ local cur prev special i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
+ if [[ ${COMP_WORDS[i]} == @(install|remove|purge|source|build-dep) ]]; then
+ special=${COMP_WORDS[i]}
+ fi
+ done
+
+ if [ -n "$special" ]; then
+ case $special in
+ remove|purge)
+ if [ -f /etc/debian_version ]; then
+ # Debian system
+ COMPREPLY=( $( _comp_dpkg_installed_packages \
+ $cur ) )
+ else
+ # assume RPM based
+ _rpm_installed_packages
+ fi
+ return 0
+ ;;
+ *)
+ COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
+ return 0
+ ;;
+
+ esac
+ fi
+
+ case "$prev" in
+ -@(c|-config-file))
+ _filedir
+ return 0
+ ;;
+
+ -@(t|-target-release|-default-release))
+ COMPREPLY=( $( apt-cache policy | \
+ grep "release.o=Debian,a=$cur" | \
+ sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null) )
+ return 0
+ ;;
+
+ esac
+
+ if [[ "$cur" == -* ]]; then
+
+ COMPREPLY=( $( compgen -W '-d -f -h -v -m -q -s -y \
+ -u -t -b -c -o --download-only --fix-broken \
+ --help --version --ignore-missing \
+ --fix-missing --no-download --quiet --simulate \
+ --just-print --dry-run --recon --no-act --yes \
+ --assume-yes --show-upgraded --only-source \
+ --compile --build --ignore-hold \
+ --target-release --no-upgrade --force-yes \
+ --print-uris --purge --reinstall \
+ --list-cleanup --default-release \
+ --trivial-only --no-remove --diff-only \
+ --tar-only --config-file --option --auto-remove' -- $cur ) )
+ else
+
+ COMPREPLY=( $( compgen -W 'update upgrade dselect-upgrade \
+ dist-upgrade install remove purge source \
+ build-dep check clean autoclean autoremove' \
+ -- $cur ) )
+
+ fi
+
+
+ return 0
+} &&
+complete -F _apt_get $filenames apt-get
+
+# Debian apt-cache(8) completion.
+#
+have apt-cache &&
+_apt_cache()
+{
+ local cur prev special i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+
+ if [ "$cur" != show ]; then
+ for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
+ if [[ ${COMP_WORDS[i]} == @(add|depends|dotty|policy|rdepends|madison|show?(pkg|src|)) ]]; then
+ special=${COMP_WORDS[i]}
+ fi
+ done
+ fi
+
+
+ if [ -n "$special" ]; then
+ case $special in
+ add)
+ _filedir
+ return 0
+ ;;
+
+ *)
+ COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
+ return 0
+ ;;
+
+ esac
+ fi
+
+
+ case "$prev" in
+ -@(c|p|s|-config-file|-@(pkg|src)-cache))
+ _filedir
+ return 0
+ ;;
+ search)
+ if [[ "$cur" != -* ]]; then
+ return 0
+ fi
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+
+ COMPREPLY=( $( compgen -W '-h -v -p -s -q -i -f -a -g -c \
+ -o --help --version --pkg-cache --src-cache \
+ --quiet --important --full --all-versions \
+ --no-all-versions --generate --no-generate \
+ --names-only --all-names --recurse \
+ --config-file --option' -- $cur ) )
+ else
+
+ COMPREPLY=( $( compgen -W 'add gencaches show showpkg showsrc \
+ stats dump dumpavail unmet search search \
+ depends rdepends pkgnames dotty xvcg \
+ policy madison' -- $cur ) )
+
+ fi
+
+
+ return 0
+} &&
+complete -F _apt_cache $filenames apt-cache
+
+
+# Debian aptitude(1) completion
+#
+have aptitude && {
+have grep-status && {
+_comp_dpkg_hold_packages()
+{
+ grep-status -P -e "^$1" -a -FStatus 'hold' -n -s Package
+}
+} || {
+_comp_dpkg_hold_packages()
+{
+ grep -B 2 'hold' /var/lib/dpkg/status | grep "Package: $1" \
+ | cut -d\ -f2
+}
+}
+
+_aptitude()
+{
+ local cur dashoptions prev special i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+
+ dashoptions='-S -u -i -h --help --version -s --simulate -d \
+ --download-only -P --prompt -y --assume-yes -F \
+ --display-format -O --sort -w --width -f -r -g \
+ --with-recommends --with-suggests -R -G \
+ --without-recommends --without-suggests -t \
+ --target-release -V --show-versions -D --show-deps\
+ -Z -v --verbose --purge-unused'
+
+ for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
+ if [[ ${COMP_WORDS[i]} == @(install|reinstall|hold|unhold|markauto|unmarkauto|dist-upgrade|full-upgrade|download|show|forbid-version|purge|remove|changelog|why|why-not|keep|keep-all) ]]; then
+ special=${COMP_WORDS[i]}
+ fi
+ #exclude some mutually exclusive options
+ [[ ${COMP_WORDS[i]} == '-u' ]] && dashoptions=${dashoptions/-i}
+ [[ ${COMP_WORDS[i]} == '-i' ]] && dashoptions=${dashoptions/-u}
+ done
+
+ if [[ -n "$special" ]]; then
+ case $special in
+ @(install|hold|markauto|unmarkauto|dist-upgrade|full-upgrade|download|show|changelog|why|why-not))
+ COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
+ return 0
+ ;;
+ @(purge|remove|reinstall|forbid-version))
+ COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
+ return 0
+ ;;
+ unhold)
+ COMPREPLY=( $( _comp_dpkg_hold_packages $cur ) )
+ return 0
+ ;;
+
+ esac
+ fi
+
+ case $prev in
+ # don't complete anything if these options are found
+ @(autoclean|clean|forget-new|search|upgrade|safe-upgrade|update|keep-all))
+ return 0
+ ;;
+
+ -S)
+ _filedir
+ return 0
+ ;;
+
+ -@(t|-target-release|-default-release))
+ COMPREPLY=( $( apt-cache policy | \
+ grep "release.o=Debian,a=$cur" | \
+ sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null ) )
+ return 0
+ ;;
+
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -W 'update upgrade safe-upgrade forget-new clean \
+ autoclean install reinstall remove \
+ hold unhold purge markauto unmarkauto why why-not \
+ dist-upgrade full-upgrade download search show \
+ forbid-version changelog keep-all' -- $cur ) )
+ fi
+
+
+ return 0
+}
+complete -F _aptitude $default aptitude
+}
+
+# Debian apt-build(1) completion.
+#
+have apt-build &&
+_apt_build()
+{
+ local cur prev special i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
+ if [[ ${COMP_WORDS[i]} == @(install|remove|source|info|clean) ]]; then
+ special=${COMP_WORDS[i]}
+ fi
+ done
+
+ if [ -n "$special" ]; then
+ case $special in
+ @(install|source|info))
+ COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
+ return 0
+ ;;
+ remove)
+ COMPREPLY=( $( _comp_dpkg_installed_packages \
+ $cur ) )
+ return 0
+ ;;
+ *)
+ return 0
+ ;;
+ esac
+ fi
+
+ case "$prev" in
+
+ --@(patch|build-dir|repository-dir))
+ _filedir
+ return 0
+ ;;
+
+ -@(h|-help))
+ return 0
+ ;;
+
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--help --show-upgraded -u --build-dir \
+ --repository-dir --build-only \
+ --build-command --reinstall --rebuild \
+ --remove-builddep --no-wrapper --purge \
+ --patch --patch-strip -p --yes -y \
+ --version -v --no-source' -- $cur ) )
+
+ else
+ COMPREPLY=( $( compgen -W 'update upgrade install remove \
+ source dist-upgrade world clean info \
+ clean-build update-repository ' -- $cur ) )
+ fi
+
+
+ return 0
+} &&
+complete -F _apt_build $filenames apt-build
+
+# chsh(1) completion
+#
+_chsh()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [ "$prev" = "-s" ]; then
+ if [ -f /etc/debian_version ]; then
+ COMPREPLY=( $( </etc/shells ) )
+ else
+ COMPREPLY=( $( chsh -l | grep "^$cur" ) )
+ fi
+ else
+ COMPREPLY=( $( compgen -u -- $cur ) )
+ fi
+
+ return 0
+}
+complete -F _chsh chsh
+
+# chkconfig(8) completion
+#
+have chkconfig &&
+_chkconfig()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ @([1-6]|--@(list|add|del)))
+ _services
+ return 0
+ ;;
+ --level)
+ COMPREPLY=( $( compgen -W '1 2 3 4 5 6' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--list --add --del --level' -- $cur ) )
+ else
+ if [ $COMP_CWORD -eq 2 -o $COMP_CWORD -eq 4 ]; then
+ COMPREPLY=( $( compgen -W 'on off reset' -- $cur ) )
+ else
+ _services
+ fi
+ fi
+} &&
+complete -F _chkconfig chkconfig
+
+# This function provides simple user@host completion
+#
+_user_at_host() {
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ $cur == *@* ]]; then
+ _known_hosts
+ else
+ COMPREPLY=( $( compgen -u -- "$cur" ) )
+ fi
+
+ return 0
+}
+shopt -u hostcomplete && complete -F _user_at_host $nospace talk ytalk finger
+
+# This function performs host completion based on ssh's known_hosts files,
+# defaulting to standard host completion if they don't exist.
+#
+_known_hosts()
+{
+ local cur curd ocur user suffix aliases global_kh user_kh hosts i host
+ local -a kh khd config
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ ocur=$cur
+
+ [ "$1" = -a ] || [ "$2" = -a ] && aliases='yes'
+ [ "$1" = -c ] || [ "$2" = -c ] && suffix=':'
+ [[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@}
+ kh=()
+
+ # ssh config files
+ [ -r /etc/ssh/ssh_config ] &&
+ config=( "${config[@]}" "/etc/ssh/ssh_config" )
+ [ -r "${HOME}/.ssh/config" ] &&
+ config=( "${config[@]}" "${HOME}/.ssh/config" )
+ [ -r "${HOME}/.ssh2/config" ] &&
+ config=( "${config[@]}" "${HOME}/.ssh2/config" )
+
+ if [ ${#config[@]} -gt 0 ]; then
+ # expand path (if present) to global known hosts file
+ global_kh=$( eval echo $( sed -ne 's/^[ \t]*[Gg][Ll][Oo][Bb][Aa][Ll][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\1/p' "${config[@]}" ) )
+ # expand path (if present) to user known hosts file
+ user_kh=$( eval echo $( sed -ne 's/^[ \t]*[Uu][Ss][Ee][Rr][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\1/p' "${config[@]}" ) )
+ fi
+
+ # Global known_hosts files
+ [ -r "$global_kh" ] &&
+ kh=( "${kh[@]}" "$global_kh" )
+ [ -r /etc/ssh/ssh_known_hosts ] &&
+ kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts )
+ [ -r /etc/ssh/ssh_known_hosts2 ] &&
+ kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts2 )
+ [ -r /etc/known_hosts ] &&
+ kh=( "${kh[@]}" /etc/known_hosts )
+ [ -r /etc/known_hosts2 ] &&
+ kh=( "${kh[@]}" /etc/known_hosts2 )
+ [ -d /etc/ssh2/knownhosts ] &&
+ khd=( "${khd[@]}" /etc/ssh2/knownhosts/*pub )
+
+ # User known_hosts files
+ [ -r "$user_kh" ] &&
+ kh=( "${kh[@]}" "$user_kh" )
+ [ -r ~/.ssh/known_hosts ] &&
+ kh=( "${kh[@]}" ~/.ssh/known_hosts )
+ [ -r ~/.ssh/known_hosts2 ] &&
+ kh=( "${kh[@]}" ~/.ssh/known_hosts2 )
+ [ -d ~/.ssh2/hostkeys ] &&
+ khd=( "${khd[@]}" ~/.ssh2/hostkeys/*pub )
+
+ # If we have known_hosts files to use
+ if [ ${#kh[@]} -gt 0 -o ${#khd[@]} -gt 0 ]; then
+ # Escape slashes and dots in paths for awk
+ cur=${cur//\//\\\/}
+ cur=${cur//\./\\\.}
+ curd=$cur
+
+ if [[ "$cur" == [0-9]*.* ]]; then
+ # Digits followed by a dot - just search for that
+ cur="^$cur.*"
+ elif [[ "$cur" == [0-9]* ]]; then
+ # Digits followed by no dot - search for digits followed
+ # by a dot
+ cur="^$cur.*\."
+ elif [ -z "$cur" ]; then
+ # A blank - search for a dot or an alpha character
+ cur="[a-z.]"
+ else
+ cur="^$cur"
+ fi
+
+ if [ ${#kh[@]} -gt 0 ]; then
+
+ # FS needs to look for a comma separated list
+ COMPREPLY=( $( awk 'BEGIN {FS=","}
+ /^[^|]/ {for (i=1; i<=2; ++i) { \
+ gsub(" .*$", "", $i); \
+ if ($i ~ /'$cur'/) {print $i} \
+ }}' "${kh[@]}" 2>/dev/null ) )
+ fi
+ if [ ${#khd[@]} -gt 0 ]; then
+ # Needs to look for files called
+ # .../.ssh2/key_22_<hostname>.pub
+ # dont fork any processes, because in a cluster environment,
+ # there can be hundreds of hostkeys
+ for i in "${khd[@]}" ; do
+ if [[ "$i" == *key_22_$curd*.pub ]] && [ -r "$i" ] ; then
+ host=${i/#*key_22_/}
+ host=${host/%.pub/}
+ COMPREPLY=( "${COMPREPLY[@]}" $host )
+ fi
+ done
+ fi
+
+ # append any available aliases from config files
+ if [ ${#config[@]} -gt 0 ] && [ -n "$aliases" ]; then
+ local host_aliases=$( sed -ne 's/^[Hh][Oo][Ss][Tt]\([Nn][Aa][Mm][Ee]\)\?['"$'\t '"']\+\([^*?]*\)$/\2/p' "${config[@]}" )
+ hosts=$( compgen -W "$host_aliases" -- $ocur )
+ COMPREPLY=( "${COMPREPLY[@]}" $hosts )
+ fi
+
+ # Now add results of normal hostname completion
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -A hostname -- $ocur ) )
+
+ # apply suffix
+ for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
+ COMPREPLY[i]=$user${COMPREPLY[i]}$suffix
+ done
+ else
+ # Just do normal hostname completion
+ COMPREPLY=( $( compgen -A hostname -S "$suffix" -- $cur ) )
+ fi
+
+ return 0
+}
+complete -F _known_hosts traceroute traceroute6 tracepath tracepath6 \
+ ping ping6 fping fping6 telnet host nslookup rsh rlogin ftp dig ssh-installkeys mtr
+
+# ssh(1) completion
+#
+have ssh && {
+_ssh()
+{
+ local cur prev
+ local -a config
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -*c)
+ COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \
+ arcfour cast128-cbc' -- $cur ) )
+ ;;
+ -*i)
+ _filedir
+ ;;
+ -*l)
+ COMPREPLY=( $( compgen -u -- $cur ) )
+ ;;
+ *)
+ _known_hosts -a
+
+ [ $COMP_CWORD -eq 1 ] || \
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- $cur ) )
+ esac
+
+ return 0
+}
+shopt -u hostcomplete && complete -F _ssh ssh slogin sftp xhost autossh
+
+# scp(1) completion
+#
+_scp()
+{
+ local cur userhost path
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _expand || return 0
+
+ if [[ "$cur" == *:* ]]; then
+ local IFS=$'\t\n'
+ # remove backslash escape from :
+ cur=${cur/\\:/:}
+ userhost=${cur%%?(\\):*}
+ path=${cur#*:}
+ # unescape spaces
+ path=${path//\\\\\\\\ / }
+ if [ -z "$path" ]; then
+ # default to home dir of specified user on remote host
+ path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null)
+ fi
+ # escape spaces; remove executables, aliases, pipes and sockets;
+ # add space at end of file names
+ COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
+ command ls -aF1d "$path*" 2>/dev/null | \
+ sed -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\\\\\\\\\&/g" \
+ -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
+ return 0
+ fi
+
+ [[ "$cur" == */* ]] || _known_hosts -c -a
+ local IFS=$'\t\n'
+ COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* \
+ 2>/dev/null | sed \
+ -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\&/g" \
+ -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
+ return 0
+}
+complete -F _scp $nospace scp
+}
+
+# rsync(1) completion
+#
+have rsync &&
+_rsync()
+{
+ local cur prev shell i userhost path
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ _expand || return 0
+
+ case "$prev" in
+ --@(config|password-file|include-from|exclude-from))
+ _filedir
+ return 0
+ ;;
+ -@(T|-temp-dir|-compare-dest))
+ _filedir -d
+ return 0
+ ;;
+ -@(e|-rsh))
+ COMPREPLY=( $( compgen -W 'rsh ssh' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ case "$cur" in
+ -*)
+ COMPREPLY=( $( compgen -W '-v -q -c -a -r -R -b -u -l -L -H \
+ -p -o -g -D -t -S -n -W -x -B -e -C -I -T -P \
+ -z -h -4 -6 --verbose --quiet --checksum \
+ --archive --recursive --relative --backup \
+ --backup-dir --suffix= --update --links \
+ --copy-links --copy-unsafe-links --safe-links \
+ --hard-links --perms --owner --group --devices\
+ --times --sparse --dry-run --whole-file \
+ --no-whole-file --one-file-system \
+ --block-size= --rsh= --rsync-path= \
+ --cvs-exclude --existing --ignore-existing \
+ --delete --delete-excluded --delete-after \
+ --ignore-errors --max-delete= --partial \
+ --force --numeric-ids --timeout= \
+ --ignore-times --size-only --modify-window= \
+ --temp-dir= --compare-dest= --compress \
+ --exclude= --exclude-from= --include= \
+ --include-from= --version --daemon --no-detach\
+ --address= --config= --port= --blocking-io \
+ --no-blocking-io --stats --progress \
+ --log-format= --password-file= --bwlimit= \
+ --write-batch= --read-batch= --help' -- $cur ))
+ ;;
+ *:*)
+ # find which remote shell is used
+ shell=rsh
+ for (( i=1; i < COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" == -@(e|-rsh) ]]; then
+ shell=${COMP_WORDS[i+1]}
+ break
+ fi
+ done
+ if [[ "$shell" == ssh ]]; then
+ # remove backslash escape from :
+ cur=${cur/\\:/:}
+ userhost=${cur%%?(\\):*}
+ path=${cur#*:}
+ # unescape spaces
+ path=${path//\\\\\\\\ / }
+ if [ -z "$path" ]; then
+ # default to home dir of specified
+ # user on remote host
+ path=$(ssh -o 'Batchmode yes' \
+ $userhost pwd 2>/dev/null)
+ fi
+ # escape spaces; remove executables, aliases, pipes
+ # and sockets; add space at end of file names
+ COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
+ command ls -aF1d "$path*" 2>/dev/null | \
+ sed -e 's/ /\\\\\\\ /g' -e 's/[*@|=]$//g' \
+ -e 's/[^\/]$/& /g' ) )
+ fi
+ ;;
+ *)
+ _known_hosts -c -a
+ _filedir
+ ;;
+ esac
+
+ return 0
+} &&
+complete -F _rsync $nospace $filenames rsync
+
+# Linux route(8) completion
+#
+[ $UNAME = Linux ] &&
+_route()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [ "$prev" = dev ]; then
+ COMPREPLY=( $( ifconfig -a | sed -ne 's|^\('$cur'[^ ]*\).*$|\1|p' ))
+ return 0
+ fi
+
+ COMPREPLY=( $( compgen -W 'add del -host -net netmask metric mss \
+ window irtt reject mod dyn reinstate dev \
+ default gw' -- $cur ) )
+
+ COMPREPLY=( $( echo " ${COMP_WORDS[@]}" | \
+ (while read -d ' ' i; do
+ [ "$i" == "" ] && continue
+ # flatten array with spaces on either side,
+ # otherwise we cannot grep on word
+ # boundaries of first and last word
+ COMPREPLY=" ${COMPREPLY[@]} "
+ # remove word from list of completions
+ COMPREPLY=( ${COMPREPLY/ $i / } )
+ done
+ echo "${COMPREPLY[@]}")
+ ) )
+ return 0
+}
+[ $UNAME = Linux ] && complete -F _route route
+
+# GNU make(1) completion
+#
+have make || have gmake || have gnumake || have pmake &&
+_make()
+{
+ local file makef makef_dir="." makef_inc cur prev i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # --name value style option
+ case $prev in
+ -@(f|o|W))
+ _filedir
+ return 0
+ ;;
+ -@(I|C))
+ _filedir -d
+ return 0
+ ;;
+ esac
+
+ # --name=value style option
+ if [[ "$cur" == *=* ]]; then
+ prev=${cur/=*/}
+ cur=${cur/*=/}
+ case "$prev" in
+ --@(file|makefile))
+ _filedir
+ return 0
+ ;;
+ --@(directory|include-dir))
+ _filedir -d
+ return 0
+ ;;
+ esac
+ fi
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-b -m -B -C -d -e -f -h -i -I\
+ -j -l -k -n -o -p -q -r -R - s -S -t -v -w -W \
+ --always-make --directory= --debug \
+ --environment-overrides --file= --makefile= --help \
+ --ignore-errors --include-dir= --jobs --load-average \
+ --max-load --keep-going --just-print --dry-run \
+ --recon --old-file= --assume-old= --print-data-base \
+ --question --no-builtin-rules --no-builtin-variables \
+ --silent --quiet --no-keep-goind --stop --touch \
+ --version --print-directory --no-print-directory \
+ --what-if= --new-file= --assume-new= \
+ --warn-undefined-variables' -- $cur ) )
+ else
+ # before we check for makefiles, see if a path was specified
+ # with -C
+ for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
+ if [[ ${COMP_WORDS[i]} == -C ]]; then
+ # eval for tilde expansion
+ eval makef_dir=${COMP_WORDS[i+1]}
+ break
+ fi
+ done
+
+ # make reads `GNUmakefile', then `makefile', then `Makefile'
+ if [ -f ${makef_dir}/GNUmakefile ]; then
+ makef=${makef_dir}/GNUmakefile
+ elif [ -f ${makef_dir}/makefile ]; then
+ makef=${makef_dir}/makefile
+ elif [ -f ${makef_dir}/Makefile ]; then
+ makef=${makef_dir}/Makefile
+ else
+ makef=${makef_dir}/*.mk # local convention
+ fi
+
+ # before we scan for targets, see if a Makefile name was
+ # specified with -f
+ for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
+ if [[ ${COMP_WORDS[i]} == -f ]]; then
+ # eval for tilde expansion
+ eval makef=${COMP_WORDS[i+1]}
+ break
+ fi
+ done
+
+ [ ! -f $makef ] && return 0
+
+ # deal with included Makefiles
+ makef_inc=$( grep -E '^-?include' $makef | sed -e "s,^.* ,"$makef_dir"/," )
+
+ for file in $makef_inc; do
+ [ -f $file ] && makef="$makef $file"
+ done
+
+ COMPREPLY=( $( awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \
+ {split($1,A,/ /);for(i in A)print A[i]}' \
+ $makef 2>/dev/null | command grep "^$cur" ))
+ fi
+} &&
+complete -f -F _make $filenames make gmake gnumake pmake
+
+# GNU tar(1) completion
+#
+_tar()
+{
+ local cur ext regex tar untar
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $( compgen -W 'c t x u r d A' -- $cur ) )
+ return 0
+ fi
+
+ case "${COMP_WORDS[1]}" in
+ ?(-)[cr]*f)
+ _filedir
+ return 0
+ ;;
+ +([^IZzjy])f)
+ ext='t@(ar?(.@(Z|gz|bz?(2)))|gz|bz?(2))'
+ regex='t\(ar\(\.\(Z\|gz\|bz2\?\)\)\?\|gz\|bz2\?\)'
+ ;;
+ *[Zz]*f)
+ ext='t?(ar.)@(gz|Z)'
+ regex='t\(ar\.\)\?\(gz\|Z\)'
+ ;;
+ *[Ijy]*f)
+ ext='t?(ar.)bz?(2)'
+ regex='t\(ar\.\)\?bz2\?'
+ ;;
+ *)
+ _filedir
+ return 0
+ ;;
+
+ esac
+
+ if [[ "$COMP_LINE" == *$ext' ' ]]; then
+ # complete on files in tar file
+ #
+ # get name of tar file from command line
+ tar=$( echo "$COMP_LINE" | \
+ sed -e 's/^.* \([^ ]*'$regex'\) .*$/\1/' )
+ # devise how to untar and list it
+ untar=t${COMP_WORDS[1]//[^Izjyf]/}
+
+ COMPREPLY=( $( compgen -W "$( echo $( tar $untar $tar \
+ 2>/dev/null ) )" -- "$cur" ) )
+ return 0
+ fi
+
+ # file completion on relevant files
+ _filedir "$ext"
+
+ return 0
+}
+[ -n "${COMP_TAR_INTERNAL_PATHS:-}" ] && complete -F _tar $dirnames tar ||
+ complete -F _tar $filenames tar
+
+# jar(1) completion
+#
+have jar &&
+_jar()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD = 1 ]; then
+ COMPREPLY=( $( compgen -W 'c t x u' -- $cur ) )
+ return 0
+ fi
+
+ case "${COMP_WORDS[1]}" in
+ *c*f)
+ _filedir
+ ;;
+ *f)
+ _filedir '?(e|j|w)ar'
+ ;;
+ *)
+ _filedir
+ ;;
+ esac
+} &&
+complete -F _jar $filenames jar
+
+# Linux iptables(8) completion
+#
+have iptables &&
+_iptables()
+{
+ local cur prev table chain
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ chain='s/^Chain \([^ ]\+\).*$/\1/p'
+
+ if [[ $COMP_LINE == *-t\ *filter* ]]; then
+ table="-t filter"
+ elif [[ $COMP_LINE == *-t\ *nat* ]]; then
+ table="-t nat"
+ elif [[ $COMP_LINE == *-t\ *mangle* ]]; then
+ table="-t mangle"
+ fi
+
+ case "$prev" in
+ -*[AIDRPFXLZ])
+ COMPREPLY=( $( compgen -W '`iptables $table -nL | \
+ sed -ne "s/^Chain \([^ ]\+\).*$/\1/p"`' -- $cur ) )
+ ;;
+ -*t)
+ COMPREPLY=( $( compgen -W 'nat filter mangle' -- $cur ) )
+ ;;
+ -j)
+ if [ "$table" = "-t filter" -o "$table" = "" ]; then
+ COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
+ `iptables $table -nL | sed -ne "$chain" \
+ -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \
+ $cur ) )
+ elif [ "$table" = "-t nat" ]; then
+ COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
+ MIRROR SNAT DNAT MASQUERADE `iptables $table -nL | \
+ sed -ne "$chain" -e "s/OUTPUT|PREROUTING|POSTROUTING//"`' \
+ -- $cur ) )
+ elif [ "$table" = "-t mangle" ]; then
+ COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
+ MARK TOS `iptables $table -nL | sed -ne "$chain" \
+ -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \
+ $cur ) )
+ fi
+ ;;
+ *)
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-i -o -s -d -p -f -m --append \
+ --delete --insert --replace --list --flush --zero --new \
+ --delete-chain --policy --rename-chain --proto --source \
+ --destination --in-interface --jump --match --numeric \
+ --out-interface --table --verbose --line-numbers --exact \
+ --fragment --modprobe= --set-counters --version' -- "$cur") )
+ fi
+ ;;
+ esac
+
+} &&
+complete -F _iptables iptables
+
+# tcpdump(8) completion
+#
+have tcpdump &&
+_tcpdump()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(r|w|F))
+ _filedir
+ return 0
+ ;;
+ -i)
+ _available_interfaces -a
+ return 0
+ ;;
+ esac
+
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-a -d -e -f -l -n -N -O -p \
+ -q -R -S -t -u -v -x -C -F -i -m -r -s -T -w \
+ -E' -- $cur ) )
+ fi
+
+} &&
+complete -F _tcpdump tcpdump
+
+# autorpm(8) completion
+#
+have autorpm &&
+_autorpm()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ COMPREPLY=( $( compgen -W '--notty --debug --help --version \
+ auto add fullinfo info help install list \
+ remove set' -- $cur ) )
+
+} &&
+complete -F _autorpm autorpm
+
+# This meta-cd function observes the CDPATH variable, so that cd additionally
+# completes on directories under those specified in CDPATH.
+#
+_cd()
+{
+ local IFS=$'\t\n' cur=`_get_cword` i j k
+
+ # try to allow variable completion
+ if [[ "$cur" == ?(\\)\$* ]]; then
+ COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) )
+ return 0
+ fi
+
+ # Use standard dir completion if no CDPATH or parameter starts with /,
+ # ./ or ../
+ if [ -z "${CDPATH:-}" ] || [[ "$cur" == ?(.)?(.)/* ]]; then
+ _filedir -d
+ return 0
+ fi
+
+ local -r mark_dirs=$(_rl_enabled mark-directories && echo y)
+ local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y)
+
+ # we have a CDPATH, so loop on its contents
+ for i in ${CDPATH//:/$'\t'}; do
+ # create an array of matched subdirs
+ k="${#COMPREPLY[@]}"
+ for j in $( compgen -d $i/$cur ); do
+ if [[ ( $mark_symdirs && -h $j || $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then
+ j="${j}/"
+ fi
+ COMPREPLY[k++]=${j#$i/}
+ done
+ done
+
+ _filedir -d
+
+ if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
+ i=${COMPREPLY[0]}
+ if [ "$i" == "$cur" ] && [[ $i != "*/" ]]; then
+ COMPREPLY[0]="${i}/"
+ fi
+ fi
+
+ return 0
+}
+if shopt -q cdable_vars; then
+ complete -v -F _cd $nospace $filenames cd
+else
+ complete -F _cd $nospace $filenames cd
+fi
+
+_remove_comp_word()
+{
+ if [[ COMP_CWORD -eq 0 ]]; then
+ return
+ elif [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
+ local old_cw0="${COMP_WORDS[0]}"
+ local new_cw0="${COMP_WORDS[1]}"
+ local old_length="${#COMP_LINE}"
+ COMP_LINE=${COMP_LINE#${old_cw0}}
+ local head=${COMP_LINE:0:${#new_cw0}}
+ local i=1
+ while [[ $head != $new_cw0 ]]; do
+ COMP_LINE=${COMP_LINE:1}
+ head=${COMP_LINE:0:${#new_cw0}}
+ if (( ++i > 10 )); then
+ break
+ fi
+ done
+ local new_length="${#COMP_LINE}"
+ COMP_POINT=$(( COMP_POINT + new_length - old_length))
+
+ COMP_CWORD=$(( COMP_CWORD - 1 ))
+ for (( i=0; i < ${#COMP_WORDS[@]} - 1; ++i )); do
+ COMP_WORDS[i]="${COMP_WORDS[i+1]}"
+ done
+ unset COMP_WORDS[${#COMP_WORDS[@]}-1]
+ else
+ return
+ fi
+}
+
+# A meta-command completion function for commands like sudo(8), which need to
+# first complete on a command, then complete according to that command's own
+# completion definition - currently not quite foolproof (e.g. mount and umount
+# don't work properly), but still quite useful.
+#
+_command()
+{
+ local cur func cline cspec noglob cmd done i \
+ _COMMAND_FUNC _COMMAND_FUNC_ARGS
+
+ _remove_comp_word
+ COMPREPLY=()
+ cur=`_get_cword`
+ # If the the first arguments following our meta-command-invoker are
+ # switches, get rid of them. Most definitely not foolproof.
+ done=
+ while [ -z $done ] ; do
+ cmd=${COMP_WORDS[0]}
+ if [[ "$cmd" == -* ]] && [ $COMP_CWORD -ge 1 ]; then
+ _remove_comp_word
+ elif [[ "$cmd" == -* ]] && [[ $COMP_CWORD -eq 0 ]]; then
+ return
+ else
+ done=1
+ fi
+ done
+
+ if [ $COMP_CWORD -eq 0 ]; then
+ COMPREPLY=( $( compgen -c -- $cur ) )
+ elif complete -p $cmd &>/dev/null; then
+ cspec=$( complete -p $cmd )
+ if [ "${cspec#* -F }" != "$cspec" ]; then
+ # COMP_CWORD and COMP_WORDS() are not read-only,
+ # so we can set them before handing off to regular
+ # completion routine
+
+ # get function name
+ func=${cspec#*-F }
+ func=${func%% *}
+
+ if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
+ $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" "${COMP_WORDS[${#COMP_WORDS[@]}-2]}"
+ else
+ $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}"
+ fi
+
+ # remove any \: generated by a command that doesn't
+ # default to filenames or dirnames (e.g. sudo chown)
+ # FIXME: I'm pretty sure this does not work!
+ if [ "${cspec#*-o }" != "$cspec" ]; then
+ cspec=${cspec#*-o }
+ cspec=${cspec%% *}
+ if [[ "$cspec" != @(dir|file)names ]]; then
+ COMPREPLY=("${COMPREPLY[@]//\\\\:/:}")
+ fi
+ fi
+ elif [ -n "$cspec" ]; then
+ cspec=${cspec#complete};
+ cspec=${cspec%%$cmd};
+ COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) );
+ fi
+ fi
+
+ [ ${#COMPREPLY[@]} -eq 0 ] && _filedir
+}
+complete -F _command $filenames nohup exec nice eval strace time ltrace then \
+ else do vsound command xargs
+
+_root_command()
+{
+ PATH=/usr/gnu/bin:$PATH:/sbin:/usr/sbin _command $1 $2 $3
+}
+complete -F _root_command $filenames sudo fakeroot really
+
+# ant(1) completion
+#
+have ant && {
+_ant()
+{
+ local cur prev buildfile i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -buildfile|-f)
+ _filedir 'xml'
+ return 0
+ ;;
+ -logfile)
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ # relevant options completion
+ COMPREPLY=( $( compgen -W '-help -projecthelp -version -quiet \
+ -verbose -debug -emacs -logfile -logger \
+ -listener -buildfile -f -D -find' -- $cur ) )
+ else
+ # available targets completion
+ # find which buildfile to use
+ buildfile=build.xml
+ for (( i=1; i < COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" == -buildfile ]]; then
+ buildfile=${COMP_WORDS[i+1]}
+ break
+ fi
+ done
+ [ ! -f $buildfile ] && return 0
+
+ # parse buildfile for targets
+ COMPREPLY=( $( awk -F'"' '/<target name="/ {print $2}' \
+ $buildfile | grep "^$cur" )
+ $( awk -F"'" "/<target name='/ "'{print $2}' \
+ $buildfile | grep "^$cur" )
+ $( awk -F'"' '/<target [^n]/ {if ($1 ~ /name=/) { print $2 } else if ($3 ~ /name=/) {print $4} else if ($5 ~ /name=/) {print $6}}' \
+ $buildfile | grep "^$cur" ) )
+ fi
+}
+have complete-ant-cmd.pl && \
+ complete -C complete-ant-cmd.pl -F _ant $filenames ant || \
+ complete -F _ant $filenames ant
+}
+
+have nslookup &&
+_nslookup()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=${COMP_WORDS[COMP_CWORD]#-}
+
+ COMPREPLY=( $( compgen -P '-' -W 'all class= debug d2 domain= \
+ srchlist= defname search port= querytype= \
+ type= recurse retry root timeout vc \
+ ignoretc' -- $cur ) )
+} &&
+complete -F _nslookup nslookup
+
+# mysqladmin(1) completion
+#
+have mysqladmin &&
+_mysqladmin()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -u)
+ COMPREPLY=( $( compgen -u -- $cur ) )
+ return 0
+ ;;
+ *)
+ ;;
+ esac
+
+ COMPREPLY=( $( compgen -W '-# -f -? -C -h -p -P -i -r -E -s -S -t -u \
+ -v -V -w' -- $cur ) )
+
+ COMPREPLY=( "${COMPREPLY[@]}" \
+ $( compgen -W 'create drop extended-status flush-hosts \
+ flush-logs flush-status flush-tables \
+ flush-threads flush-privileges kill \
+ password ping processlist reload refresh \
+ shutdown status variables version' \
+ -- $cur ) )
+} &&
+complete -F _mysqladmin mysqladmin
+
+# gzip(1) completion
+#
+have gzip &&
+_gzip()
+{
+ local cur prev xspec IFS=$'\t\n'
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-c -d -f \
+ -h -l -L -n -N -q -r -S -t -v -V \
+ -1 -2 -3 -4 -5 -6 -7 -8 -9 \
+ --stdout --decompress --force --help --list \
+ --license --no-name --name --quiet --recursive \
+ --suffix --test --verbose --version --fast \
+ --best' -- $cur ) )
+ return 0
+ fi
+
+ xspec="*.?(t)gz"
+ if [[ "$prev" == --* ]]; then
+ [[ "$prev" == --decompress || \
+ "$prev" == --list || \
+ "$prev" == --test ]] && xspec="!"$xspec
+ [[ "$prev" == --force ]] && xspec=
+ elif [[ "$prev" == -* ]]; then
+ [[ "$prev" == -*[dlt]* ]] && xspec="!"$xspec
+ [[ "$prev" == -*f* ]] && xspec=
+ elif [ "$prev" = '>' ]; then
+ xspec=
+ elif [ "$prev" = '<' ]; then
+ xspec=
+ fi
+
+ _expand || return 0
+
+ COMPREPLY=( $( compgen -f -X "$xspec" -- $cur ) \
+ $( compgen -d -- $cur ) )
+} &&
+complete -F _gzip $filenames gzip
+
+# bzip2(1) completion
+#
+have bzip2 &&
+_bzip2()
+{
+ local cur prev xspec IFS=$'\t\n'
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-c -d -f -h -k -L -q -s \
+ -t -v -V -z -1 -2 -3 -4 -5 -6 -7 -8 -9 \
+ --help --decompress --compress --keep --force \
+ --test --stdout --quiet --verbose --license \
+ --version --small --fast --best' -- $cur ) )
+ return 0
+ fi
+
+ xspec="*.bz2"
+ if [[ "$prev" == --* ]]; then
+ [[ "$prev" == --decompress || \
+ "$prev" == --list || \
+ "$prev" == --test ]] && xspec="!"$xspec
+ [[ "$prev" == --compress ]] && xspec=
+ elif [[ "$prev" == -* ]]; then
+ [[ "$prev" == -*[dt]* ]] && xspec="!"$xspec
+ [[ "$prev" == -*z* ]] && xspec=
+ fi
+
+ _expand || return 0
+
+ COMPREPLY=( $( compgen -f -X "$xspec" -- $cur ) \
+ $( compgen -d -- $cur ) )
+} &&
+complete -F _bzip2 $filenames bzip2
+
+# openssl(1) completion
+#
+have openssl && {
+_openssl_sections()
+{
+ local config
+
+ config=/etc/ssl/openssl.cnf
+ [ ! -f $config ] && config=/usr/share/ssl/openssl.cnf
+ for (( i=2; i < COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" == -config ]]; then
+ config=${COMP_WORDS[i+1]}
+ break
+ fi
+ done
+ [ ! -f $config ] && return 0
+
+ COMPREPLY=( $( awk '/\[.*\]/ {print $2} ' $config | grep "^$cur" ) )
+}
+
+_openssl()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $( compgen -W 'asn1parse ca ciphers crl crl2pkcs7 \
+ dgst dh dhparam dsa dsaparam enc errstr gendh gendsa \
+ genrsa nseq passwd pkcs12 pkcs7 pkcs8 rand req rsa \
+ rsautl s_client s_server s_time sess_id smime speed \
+ spkac verify version x509 md2 md4 md5 mdc2 rmd160 sha \
+ sha1 base64 bf bf-cbc bf-cfb bf-ecb bf-ofb cast \
+ cast-cbc cast5-cbc cast5-cfb cast5-ecb cast5-ofb des \
+ des-cbc des-cfb des-ecb des-ede des-ede-cbc \
+ des-ede-cfb des-ede-ofb des-ede3 des-ede3-cbc \
+ des-ede3-cfb des-ede3-ofb des-ofb des3 desx rc2 \
+ rc2-40-cbc rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb \
+ rc4 rc4-40' -- $cur ) )
+ else
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ case ${COMP_WORDS[1]} in
+ asn1parse)
+ case $prev in
+ -inform)
+ COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
+ return 0
+ ;;
+ -@(in|out|oid))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -in -out -noout -offset \
+ -length -i -oid -strparse' -- $cur ) )
+ fi
+ ;;
+ ca)
+ case $prev in
+ -@(config|revoke|cert|in|out|spkac|ss_cert))
+ _filedir
+ return 0
+ ;;
+ -outdir)
+ _filedir -d
+ return 0
+ ;;
+ -@(name|crlexts|extensions))
+ _openssl_sections
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-verbose -config -name \
+ -gencrl -revoke -crldays -crlhours -crlexts \
+ -startdate -enddate -days -md -policy -keyfile \
+ -key -passin -cert -in -out -notext -outdir \
+ -infiles -spkac -ss_cert -preserveDN -batch \
+ -msie_hack -extensions' -- $cur ) )
+ fi
+ ;;
+ ciphers)
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-v -ssl2 -ssl3 -tls1' -- $cur ) )
+ fi
+ ;;
+ crl)
+ case $prev in
+ -@(in|out)form)
+ COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
+ return 0
+ ;;
+ -@(in|out|CAfile))
+ _filedir
+ return 0
+ ;;
+ -CAPath)
+ _filedir -d
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -outform -text -in -out -noout \
+ -hash -issuer -lastupdate -nextupdate -CAfile -CApath' -- $cur ) )
+ fi
+ ;;
+ crl2pkcs7)
+ case $prev in
+ -@(in|out)form)
+ COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
+ return 0
+ ;;
+ -@(in|out))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -outform -in -out -print_certs' -- $cur ) )
+ fi
+ ;;
+ dgst)
+ case $prev in
+ -@(out|sign|verify|prvrify|signature))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-md5 -md4 -md2 -sha1 -sha -mdc2 -ripemd160 -dss1 \
+ -c -d -hex -binary -out -sign -verify -prverify -signature' -- $cur ) )
+ else
+ _filedir
+ fi
+ ;;
+ dsa)
+ case $prev in
+ -@(in|out)form)
+ COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
+ return 0
+ ;;
+ -@(in|out))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -outform -in -passin -out -passout -des -des3 -idea -text -noout \
+ -modulus -pubin -pubout' -- $cur ) )
+ fi
+ ;;
+ dsaparam)
+ case $prev in
+ -@(in|out)form)
+ COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
+ return 0
+ ;;
+ -@(in|out|rand))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -outform -in -out -noout \
+ -text -C -rand -genkey' -- $cur ) )
+ fi
+ ;;
+ enc)
+ case $prev in
+ -@(in|out|kfile))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-ciphername -in -out -pass \
+ -e -d -a -A -k -kfile -S -K -iv -p -P -bufsize -debug' -- $cur ) )
+ fi
+ ;;
+ dhparam)
+ case $prev in
+ -@(in|out)form)
+ COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
+ return 0
+ ;;
+ -@(in|out|rand))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -outform -in -out -dsaparam -noout \
+ -text -C -2 -5 -rand' -- $cur ) )
+ fi
+ ;;
+ gendsa)
+ case $prev in
+ -@(out|rand))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-out -des -des3 -idea -rand' -- $cur ) )
+ else
+ _filedir
+ fi
+ ;;
+ genrsa)
+ case $prev in
+ -@(out|rand))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-out -passout -des -des3 -idea -f4 -3 -rand' -- $cur ) )
+ fi
+ ;;
+ pkcs7)
+ case $prev in
+ -@(in|out)form)
+ COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
+ return 0
+ ;;
+ -@(in|out))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -outform -in -out -print_certs -text -noout' -- $cur ) )
+ fi
+ ;;
+ rand)
+ case $prev in
+ -@(out|rand))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-out -rand -base64' -- $cur ) )
+ fi
+ ;;
+ req)
+ case "$prev" in
+ -@(in|out|key)form)
+ COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
+ return 0
+ ;;
+
+ -@(in|out|rand|key|keyout|config))
+ _filedir
+ return 0
+ ;;
+ -extensions)
+ _openssl_sections
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -outform -in \
+ -passin -out -passout -text -noout -verify \
+ -modulus -new -rand -newkey -newkey -nodes \
+ -key -keyform -keyout -md5 -sha1 -md2 -mdc2 \
+ -config -x509 -days -asn1-kludge -newhdr \
+ -extensions -reqexts section' -- $cur ) )
+ fi
+ ;;
+ rsa)
+ case $prev in
+ -@(in|out)form)
+ COMPREPLY=( $( compgen -W 'DER NET PEM' -- $cur ) )
+ return 0
+ ;;
+ -@(in|out))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -outform -in -passin -out -passout \
+ -sgckey -des -des3 -idea -text -noout -modulus -check -pubin \
+ -pubout -engine' -- $cur ) )
+ fi
+ ;;
+ rsautl)
+ case $prev in
+ -@(in|out|inkey))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-in -out -inkey -pubin -certin -sign -verify \
+ -encrypt -decrypt -pkcs -ssl -raw -hexdump -asn1parse' -- $cur ) )
+ fi
+ ;;
+ s_client)
+ case $prev in
+ -connect)
+ _known_hosts
+ return 0
+ ;;
+ -@(cert|key|CAfile|rand))
+ _filedir
+ return 0
+ ;;
+ -CApath)
+ _filedir -d
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-connect -verify -cert -key -CApath -CAfile \
+ -reconnect -pause -showcerts -debug -msg -nbio_test -state -nbio \
+ -crlf -ign_eof -quiet -ssl2 -ssl3 -tls1 -no_ssl2 -no_ssl3 -no_tls1 \
+ -bugs -cipher -starttls -engine -rand' -- $cur ) )
+ fi
+ ;;
+ s_server)
+ case $prev in
+ -@(cert|key|dcert|dkey|dhparam|CAfile|rand))
+ _filedir
+ return 0
+ ;;
+ -CApath)
+ _filedir -d
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-accept -context -verify -Verify -cert -key \
+ -dcert -dkey -dhparam -nbio -nbio_test -crlf -debug -msg -state -CApath \
+ -CAfile -nocert -cipher -quiet -no_tmp_rsa -ssl2 -ssl3 -tls1 -no_ssl2 \
+ -no_ssl3 -no_tls1 -no_dhe -bugs -hack -www -WWW -HTTP -engine -id_prefix \
+ -rand' -- $cur ) )
+ fi
+ ;;
+ s_time)
+ case $prev in
+ -connect)
+ _known_hosts
+ return 0
+ ;;
+ -@(cert|key|CAfile))
+ _filedir
+ return 0
+ ;;
+ -CApath)
+ _filedir -d
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-connect -www -cert -key -CApath -CAfile -reuse \
+ -new -verify -nbio -time -ssl2 -ssl3 -bugs -cipher' -- $cur ) )
+ fi
+ ;;
+
+ sess_id)
+ case $prev in
+ -@(in|out)form)
+ COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
+ return 0
+ ;;
+ -@(in|out))
+ _filedir
+ return 0
+ ;;
+ esac
+
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -outform -in -out -text -noout \
+ -context ID' -- $cur ) )
+ fi
+ ;;
+ smime)
+ case $prev in
+ -@(in|out)form)
+ COMPREPLY=( $( compgen -W 'SMIME DER PEM' -- $cur ) )
+ return 0
+ ;;
+ -@(in|out|certfile|signer|recip|inkey|content|rand))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-encrypt -decrypt -sign -verify -pk7out -des -des3 \
+ -rc2-40 -rc2-64 -rc2-128 -aes128 -aes192 -aes256 -in -certfile -signer \
+ -recip -inform -passin -inkey -out -outform -content -to -from -subject \
+ -text -rand' -- $cur ) )
+ else
+ _filedir
+ fi
+ ;;
+ speed)
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-engine' -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -W 'md2 mdc2 md5 hmac sha1 rmd160 idea-cbc \
+ rc2-cbc rc5-cbc bf-cbc des-cbc des-ede3 rc4 rsa512 rsa1024 rsa2048 \
+ rsa4096 dsa512 dsa1024 dsa2048 idea rc2 des rsa blowfish' -- $cur ) )
+ fi
+ ;;
+ verify)
+ case $prev in
+ -@(CAfile|untrusted))
+ _filedir
+ return 0
+ ;;
+ -CApath)
+ _filedir -d
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-CApath -CAfile -purpose -untrusted -help -issuer_checks \
+ -verbose -certificates' -- $cur ) )
+ else
+ _filedir
+ fi
+ ;;
+ x509)
+ case "$prev" in
+ -@(in|out|CA|CAkey|CAserial|extfile))
+ _filedir
+ return 0
+ ;;
+ -@(in|out)form)
+ COMPREPLY=( $( compgen -W 'DER PEM NET' -- $cur ) )
+ return 0
+ ;;
+ -@(key|CA|CAkey)form)
+ COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
+ return 0
+ ;;
+ -extensions)
+ _openssl_sections
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-inform -outform \
+ -keyform -CAform -CAkeyform -in -out \
+ -serial -hash -subject -issuer -nameopt \
+ -email -startdate -enddate -purpose \
+ -dates -modulus -fingerprint -alias \
+ -noout -trustout -clrtrust -clrreject \
+ -addtrust -addreject -setalias -days \
+ -set_serial -signkey -x509toreq -req \
+ -CA -CAkey -CAcreateserial -CAserial \
+ -text -C -md2 -md5 -sha1 -mdc2 -clrext \
+ -extfile -extensions -engine' -- $cur ) )
+ fi
+ ;;
+ @(md5|md4|md2|sha1|sha|mdc2|ripemd160))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-c -d' -- $cur ) )
+ else
+ _filedir
+ fi
+ ;;
+ esac
+ fi
+
+ return 0
+}
+complete -F _openssl $default openssl
+}
+
+# screen(1) completion
+#
+have screen &&
+_screen()
+{
+ local cur prev preprev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ [ "$COMP_CWORD" -ge 2 ] && preprev=${COMP_WORDS[COMP_CWORD-2]}
+
+ if [ "$preprev" = "-d" -o "$preprev" = "-D" -a "$prev" = "-r" -o \
+ "$prev" = "-R" ]; then
+ # list all
+ COMPREPLY=( $( command screen -ls | \
+ sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*$|\1|p' ) )
+ else
+ case "$prev" in
+ -[rR])
+ # list detached
+ COMPREPLY=( $( command screen -ls | \
+ sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Detached.*$|\1|p' ) )
+ ;;
+ -[dDx])
+ # list attached
+ COMPREPLY=( $( command screen -ls | \
+ sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Attached.*$|\1|p' ) )
+ ;;
+ -s)
+ # shells
+ COMPREPLY=( $( grep ^${cur:-[^#]} /etc/shells ) )
+ ;;
+ *)
+ ;;
+ esac
+ fi
+
+ return 0
+} &&
+complete -F _screen $default screen
+
+# lftp(1) bookmark completion
+#
+have lftp &&
+_lftp()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ] && [ -f ~/.lftp/bookmarks ]; then
+ COMPREPLY=( $( compgen -W '$( sed -ne "s/^\(.*\)'$'\t''.*$/\1/p" \
+ ~/.lftp/bookmarks )' -- $cur ) )
+ fi
+
+ return 0
+} &&
+complete -F _lftp $default lftp
+
+# ncftp(1) bookmark completion
+#
+have ncftp &&
+_ncftp()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ] && [ -f ~/.ncftp/bookmarks ]; then
+ COMPREPLY=( $( compgen -W '$( sed -ne "s/^\([^,]\{1,\}\),.*$/\1/p" \
+ ~/.ncftp/bookmarks )' -- $cur ) )
+ fi
+
+ return 0
+} &&
+complete -F _ncftp $default ncftp
+
+# gdb(1) completion
+#
+have gdb &&
+_gdb()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $( compgen -c -- $cur ) )
+ elif [ $COMP_CWORD -eq 2 ]; then
+ prev=${prev##*/}
+ COMPREPLY=( $( compgen -fW "$( command ps axo comm,pid | \
+ awk '{if ($1 ~ /^'"$prev"'/) print $2}' ) )" \
+ -- "$cur" ) )
+ fi
+} &&
+complete -F _gdb $filenames gdb
+
+# Postgresql completion
+#
+have psql && {
+_pg_databases()
+{
+ return
+ COMPREPLY=( $( psql -l 2>/dev/null | \
+ sed -e '1,/^-/d' -e '/^(/,$d' | \
+ awk '{print $1}' | grep "^$cur" ) )
+}
+
+_pg_users()
+{
+ #COMPREPLY=( $( psql -qtc 'select usename from pg_user' template1 2>/dev/null | \
+ # grep "^ $cur" ) )
+ #[ ${#COMPREPLY[@]} -eq 0 ] &&
+ COMPREPLY=( $( compgen -u -- $cur ) )
+}
+
+# createdb(1) completion
+#
+_createdb()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(h|-host=))
+ _known_hosts
+ return 0
+ ;;
+ -@(U|-username=))
+ _pg_users
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-D -T -E -h -p -U -W -e -q \
+ --location= --template= --encoding= --host= --port= \
+ --username= --password --echo --quiet --help' -- $cur ))
+ else
+ _pg_databases
+ fi
+}
+complete -F _createdb $default createdb
+
+# dropdb(1) completion
+#
+_dropdb()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(h|-host=))
+ _known_hosts
+ return 0
+ ;;
+ -@(U|-username=))
+ _pg_users
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-h -p -U -W -e -q \
+ --host= --port= --username= --password \
+ --interactive --echo --quiet --help' -- $cur ) )
+ else
+ _pg_databases
+ fi
+}
+complete -F _dropdb $default dropdb
+
+# psql(1) completion
+#
+_psql()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -h|--host)
+ _known_hosts
+ return 0
+ ;;
+ -U|--username)
+ _pg_users
+ return 0
+ ;;
+ -d|--dbname)
+ _pg_databases
+ return 0
+ ;;
+ -@(o|f)|--output|--file)
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ # return list of available options
+ COMPREPLY=( $( compgen -W '-a --echo-all -A --no-align \
+ -c --command -d --dbname -e --echo-queries \
+ -E --echo-hidden -f --file -F --filed-separator \
+ -h --host -H --html -l --list -n -o --output \
+ -p --port -P --pset -q -R --record-separator \
+ -s --single-step -S --single-line -t --tuples-only \
+ -T --table-attr -U --username -v --variable \
+ -V --version -W --password -x --expanded -X --nopsqlrc \
+ -? --help ' -- $cur ) )
+ else
+ # return list of available databases
+ _pg_databases
+ fi
+}
+complete -F _psql $default psql
+}
+
+_longopt()
+{
+ local cur opt
+
+ cur=`_get_cword`
+
+ if [[ "$cur" == --*=* ]]; then
+ opt=${cur%%=*}
+ # cut backslash that gets inserted before '=' sign
+ opt=${opt%\\*}
+ cur=${cur#*=}
+ _filedir
+ COMPREPLY=( $( compgen -P "$opt=" -W '${COMPREPLY[@]}' -- $cur))
+ return 0
+ fi
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( $1 --help 2>&1 | sed -e '/--/!d' \
+ -e 's/.*\(--[-A-Za-z0-9]\+=\?\).*/\1/' | \
+ command grep "^$cur" | sort -u ) )
+ elif [[ "$1" == @(mk|rm)dir ]]; then
+ _filedir -d
+ else
+ _filedir
+ fi
+}
+# makeinfo and texi2dvi are defined elsewhere.
+for i in a2ps autoconf automake bc gprof ld nm objcopy objdump readelf strip \
+ bison cpio diff patch enscript cp df dir du ln ls mkfifo mknod mv rm \
+ touch vdir awk gperf grep grub indent less m4 sed shar date \
+ tee who texindex cat csplit cut expand fmt fold head \
+ md5sum nl od paste pr ptx sha1sum sort split tac tail tr unexpand \
+ uniq wc ldd bash id irb mkdir rmdir; do
+ have $i && complete -F _longopt $filenames $i
+done
+
+# These commands use filenames, so '-o filenames' is not needed.
+for i in env netstat seq uname units wget; do
+ have $i && complete -F _longopt $default $i
+done
+unset i
+
+# gcc(1) completion
+#
+# The only unusual feature is that we don't parse "gcc --help -v" output
+# directly, because that would include the options of all the other backend
+# tools (linker, assembler, preprocessor, etc) without any indication that
+# you cannot feed such options to the gcc driver directly. (For example, the
+# linker takes a -z option, but you must type -Wl,-z for gcc.) Instead, we
+# ask the driver ("g++") for the name of the compiler ("cc1"), and parse the
+# --help output of the compiler.
+#
+have gcc &&
+_gcc()
+{
+ local cur cc backend
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _expand || return 0
+
+ case "$1" in
+ gcj)
+ backend=jc1
+ ;;
+ gpc)
+ backend=gpc1
+ ;;
+ *77)
+ backend=f771
+ ;;
+ *)
+ backend=cc1 # (near-)universal backend
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ cc=$( $1 -print-prog-name=$backend )
+ # sink stderr:
+ # for C/C++/ObjectiveC it's useless
+ # for FORTRAN/Java it's an error
+ COMPREPLY=( $( $cc --help 2>/dev/null | tr '\t' ' ' | \
+ sed -e '/^ *-/!d' -e 's/ *-\([^ ]*\).*/-\1/' | \
+ command grep "^$cur" | sort -u ) )
+ else
+ _filedir
+ fi
+} &&
+complete $filenames -F _gcc gcc g++ c++ g77 gcj gpc
+[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Cygwin ] && \
+[ -n "${have:-}" ] && complete $filenames -F _gcc cc
+
+# Linux cardctl(8) completion
+#
+have cardctl &&
+_cardctl()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $( compgen -W 'status config ident suspend \
+ resume reset eject insert scheme' \
+ -- $cur ) )
+ fi
+} &&
+complete -F _cardctl cardctl
+
+# This function is required by _dpkg() and _dpkg-reconfigure()
+#
+have dpkg && {
+_comp_dpkg_installed_packages()
+{
+ grep -A 1 "Package: $1" /var/lib/dpkg/status | \
+ grep -B 1 -E "ok installed|half-installed|unpacked| \
+ half-configured|config-files" | \
+ grep "Package: $1" | cut -d\ -f2
+}
+
+# Debian dpkg(8) completion
+#
+_dpkg()
+{
+ local cur prev i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ i=$COMP_CWORD
+
+ _expand || return 0
+
+ # find the last option flag
+ if [[ $cur != -* ]]; then
+ while [[ $prev != -* && $i != 1 ]]; do
+ i=$((i-1))
+ prev=${COMP_WORDS[i-1]}
+ done
+ fi
+
+ case "$prev" in
+ -@(c|i|A|I|f|e|x|X|-@(install|unpack|record-avail|contents|info|fsys-tarfile|field|control|extract)))
+ _filedir '?(u)deb'
+ return 0
+ ;;
+ -@(b|-build))
+ _filedir -d
+ return 0
+ ;;
+ -@(s|p|l|-@(status|print-avail|list)))
+ COMPREPLY=( $( apt-cache pkgnames $cur 2>/dev/null ) )
+ return 0
+ ;;
+ -@(S|-search))
+ _filedir
+ return 0
+ ;;
+ -@(r|L|P|-@(remove|purge|listfiles)))
+ COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
+ return 0
+ ;;
+ *)
+
+ COMPREPLY=( $( compgen -W '-i --install --unpack -A --record-avail \
+ --configure -r --remove -P --purge --get-selections \
+ --set-selections --update-avail --merge-avail \
+ --clear-avail --command-fd --forget-old-unavail -s \
+ --status -p --print-avail -L --listfiles -l --list \
+ -S --search -C --audit --print-architecture \
+ --print-gnu-build-architecture \
+ --print-installation-architecture \
+ --compare-versions --help --version --force-help \
+ --force-all --force-auto-select --force-downgrade \
+ --force-configure-any --force-hold --force-bad-path \
+ --force-not-root --force-overwrite \
+ --force-overwrite-diverted --force-bad-verify \
+ --force-depends-version --force-depends \
+ --force-confnew --force-confold --force-confdef \
+ --force-confmiss --force-conflicts --force-architecture\
+ --force-overwrite-dir --force-remove-reinstreq \
+ --force-remove-essential -Dh \
+ --debug=help --licence --admindir= --root= --instdir= \
+ -O --selected-only -E --skip-same-version \
+ -G --refuse-downgrade -B --auto-deconfigure \
+ --no-debsig --no-act -D --debug= --status-fd \
+ -b --build -I --info -f --field -c --contents \
+ -x --extract -X --vextract --fsys-tarfile -e --control \
+ --ignore-depends= --abort-after' -- $cur ) )
+ ;;
+ esac
+
+
+}
+complete -F _dpkg $filenames dpkg dpkg-deb
+}
+
+# Debian GNU dpkg-reconfigure(8) completion
+#
+have dpkg-reconfigure &&
+_dpkg_reconfigure()
+{
+ local cur prev opt
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+
+ case "$prev" in
+ -@(f|-frontend))
+ opt=( $( echo /usr/share/perl5/Debconf/FrontEnd/* ) )
+ opt=( ${opt[@]##*/} )
+ opt=( ${opt[@]%.pm} )
+ COMPREPLY=( $( compgen -W '${opt[@]}' -- $cur ) )
+ return 0
+ ;;
+ -@(p|-priority))
+ COMPREPLY=( $( compgen -W 'low medium high critical' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-f --frontend -p --priority -a --all \
+ -u --unseen-only -h --help -s --showold \
+ --force --terse' -- $cur ) )
+ else
+ COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
+ fi
+} &&
+complete -F _dpkg_reconfigure $default dpkg-reconfigure
+
+# Debian dpkg-source completion
+#
+have dpkg-source &&
+_dpkg_source()
+{
+ local cur prev options work i action packopts unpackopts
+
+ packopts="-c -l -F -V -T -D -U -W -E -sa -i -I -sk -sp -su -sr -ss -sn -sA -sK -sP -sU -sR"
+ unpackopts="-sp -sn -su"
+ options=`echo "-x -b $packopts $unpackopts" | xargs echo | sort -u | xargs echo`
+
+ COMPREPLY=()
+ if [ "$1" != "dpkg-source" ]; then
+ exit 1
+ fi
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ action="options"
+ for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
+ if [[ ${COMP_WORDS[$i]} == "-x" ]]; then
+ action=unpack
+ elif [[ ${COMP_WORDS[$i]} == "-b" ]]; then
+ action=pack
+ elif [[ ${COMP_WORDS[$i]} == "-h" ]]; then
+ action=help
+ fi
+ done
+ # if currently seeing a complete option, return just itself.
+ for i in $options; do
+ if [ "$cur" = "$i" ]; then
+ COMPREPLY=( "$cur" )
+ return 0
+ fi
+ done
+ case "$action" in
+ "unpack")
+ if [ "$cur" = "-" -o "$cur" = "-s" ]; then
+ COMPREPLY=( $unpackots )
+ return 0
+ fi
+ case "$prev" in
+ "-x")
+ COMPREPLY=( $( compgen -d -- "$cur" ) \
+ $( compgen -f -X '!*.dsc' -- "$cur" ) )
+ return 0
+ ;;
+ *)
+ COMPREPLY=( $unpackopts $(compgen -d -f -- "$cur" ) )
+ return 0
+ ;;
+ esac
+ return 0
+ ;;
+ "pack")
+ if [ "$cur" = "-" ]; then
+ COMPREPLY=( $packopts )
+ return 0
+ fi
+ if [ "$cur" = "-s" ]; then
+ COMPREPLY=( "-sa" "-sk" "-sp" "-su" "-sr" "-ss" "-sn" \
+ "-sA" "-sK" "-sP" "-sU" "-sR" )
+ return 0
+ fi
+ case "$prev" in
+ "-b")
+ COMPREPLY=( $( compgen -d -- "$cur" ) )
+ return 0
+ ;;
+ "-c"|"-l"|"-T"|"-i"|"-I")
+ # -c: get controlfile
+ # -l: get per-version info from this file
+ # -T: read variables here, not debian/substvars
+ # -i: <regexp> filter out files to ignore diffs of.
+ # -I: filter out files when building tarballs.
+ # return directory names and file names
+ COMPREPLY=( $( compgen -d -f ) )
+ return 0
+ ;;
+ "-F")
+ # -F: force change log format
+ COMPREPLY=( $( ( cd /usr/lib/dpkg/parsechangelog; compgen -f "$cur" ) ) )
+ return 0
+ ;;
+ "-V"|"-D")
+ # -V: set a substitution variable
+ # we don't know anything about possible variables or values
+ # so we don't try to suggest any completion.
+ COMPREPLY=()
+ return 0
+ ;;
+ "-D")
+ # -D: override or add a .dsc field and value
+ # if $cur doesn't contain a = yet, suggest variable names
+ if echo -- "$cur" | grep -q "="; then
+ # $cur contains a "="
+ COMPREPLY=()
+ return 0
+ else
+ COMPREPLY=( Format Source Version Binary Maintainer Uploader Architecture Standards-Version Build-Depends Files )
+ return 0
+ fi
+ ;;
+ "-U")
+ # -U: remove a field
+ # Suggest possible fieldnames
+ COMPREPLY=( Format Source Version Binary Maintainer Uploader Architecture Standards-Version Build-Depends Files )
+ return 0
+ ;;
+ *)
+ COMPREPLY=( $packopts )
+ return 0
+ ;;
+ esac
+ return 0
+ ;;
+ *)
+ # if seeing a partial option, return possible completions.
+ if [ "$cur" = "-s" ]; then
+ COMPREPLY=( "-sa" "-sk" "-sp" "-su" "-sr" "-ss" "-sn" \
+ "-sA" "-sK" "-sP" "-sU" "-sR" )
+ return 0
+ fi
+ # else return all possible options.
+ COMPREPLY=( $options )
+ return 0
+ ;;
+ esac
+} &&
+complete -F _dpkg_source dpkg-source
+
+# Debian Linux dselect(8) completion.
+#
+have dselect &&
+_dselect()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ --admindir)
+ _filedir -d
+ return 0
+ ;;
+
+ -@(D|debug))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--admindir --help --version --licence \
+ --license --expert --debug' -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -W 'access update select install config \
+ remove quit' -- $cur ) )
+ fi
+
+
+ return 0
+} &&
+complete -F _dselect $filenames dselect
+
+# Java completion
+#
+
+# available path elements completion
+have java && {
+_java_path()
+{
+ cur=${cur##*:}
+ _filedir '@(jar|zip)'
+}
+
+# exact classpath determination
+_java_find_classpath()
+{
+ local i
+
+ # search first in current options
+ for (( i=1; i < COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" == -@(cp|classpath) ]]; then
+ classpath=${COMP_WORDS[i+1]}
+ break
+ fi
+ done
+
+ # default to environment
+ [ -z "$classpath" ] && classpath=$CLASSPATH
+
+ # default to current directory
+ [ -z "$classpath" ] && classpath=.
+}
+
+# exact sourcepath determination
+_java_find_sourcepath()
+{
+ local i
+
+ # search first in current options
+ for (( i=1; i < COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" == -sourcepath ]]; then
+ sourcepath=${COMP_WORDS[i+1]}
+ break
+ fi
+ done
+
+ # default to classpath
+ [ -z "$sourcepath" ] && _java_find_classpath
+ sourcepath=$classpath
+}
+
+# available classes completion
+_java_classes()
+{
+ local classpath i
+
+ # find which classpath to use
+ _java_find_classpath
+
+ # convert package syntax to path syntax
+ cur=${cur//.//}
+ # parse each classpath element for classes
+ for i in ${classpath//:/ }; do
+ if [ -r $i ] && [[ "$i" == *.@(jar|zip) ]]; then
+ if type zipinfo &> /dev/null; then
+ COMPREPLY=( "${COMPREPLY[@]}" $( zipinfo -1 \
+ "$i" | grep "^$cur" | grep '\.class$' | \
+ grep -v "\\$" ) )
+ else
+ COMPREPLY=( "${COMPREPLY[@]}" $( jar tf "$i" \
+ "$cur" | grep "\.class$" | grep -v "\\$" ) )
+ fi
+
+ elif [ -d $i ]; then
+ i=${i%/}
+ COMPREPLY=( "${COMPREPLY[@]}" $( find "$i" -type f \
+ -path "$i/$cur*.class" 2>/dev/null | \
+ grep -v "\\$" | sed -e "s|^$i/||" ) )
+ fi
+ done
+
+ # remove class extension
+ COMPREPLY=( ${COMPREPLY[@]%.class} )
+ # convert path syntax to package syntax
+ COMPREPLY=( ${COMPREPLY[@]//\//.} )
+}
+
+# available packages completion
+_java_packages()
+{
+ local sourcepath i
+
+ # find wich sourcepath to use
+ _java_find_sourcepath
+
+ # convert package syntax to path syntax
+ cur=${cur//.//}
+ # parse each sourcepath element for packages
+ for i in ${sourcepath//:/ }; do
+ if [ -d $i ]; then
+ COMPREPLY=( "${COMPREPLY[@]}" $( command ls -F -d \
+ $i/$cur* 2>/dev/null | sed -e 's|^'$i'/||' ) )
+ fi
+ done
+ # keep only packages
+ COMPREPLY=( $( echo "${COMPREPLY[@]}" | tr " " "\n" | grep "/$" ) )
+ # remove packages extension
+ COMPREPLY=( ${COMPREPLY[@]%/} )
+ # convert path syntax to package syntax
+ cur=${COMPREPLY[@]//\//.}
+}
+
+# java completion
+#
+_java()
+{
+ local cur prev i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ for ((i=1; i < $COMP_CWORD; i++)); do
+ case ${COMP_WORDS[$i]} in
+ -cp|-classpath)
+ ((i++)) # skip the classpath string.
+ ;;
+ -*)
+ # this is an option, not a class/jarfile name.
+ ;;
+ *)
+ # once we've seen a class, just do filename completion
+ _filedir
+ return 0
+ ;;
+ esac
+ done
+
+ case $prev in
+ -@(cp|classpath))
+ _java_path
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ # relevant options completion
+ COMPREPLY=( $( compgen -W '-client -hotspot -server -classic \
+ -cp -classpath -D -verbose -verbose:class \
+ -verbose:gc -version:jni -version \
+ -showversion -? -help -X -jar \
+ -ea -enableassertions -da -disableassertions \
+ -esa -enablesystemassertions \
+ -dsa -disablesystemassertions ' -- $cur ) )
+ else
+ if [[ "$prev" == -jar ]]; then
+ # jar file completion
+ _filedir jar
+ else
+ # classes completion
+ _java_classes
+ fi
+ fi
+}
+complete -F _java $filenames java
+}
+
+# javadoc completion
+#
+have javadoc &&
+_javadoc()
+{
+ COMPREPLY=()
+ local cur prev
+
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case $prev in
+ -@(overview|helpfile|stylesheetfile))
+ _filedir
+ return 0
+ ;;
+ -d)
+ _filedir -d
+ return 0
+ ;;
+ -@(classpath|bootclasspath|docletpath|sourcepath|extdirs))
+ _java_path
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ # relevant options completion
+ COMPREPLY=( $( compgen -W '-overview -public -protected \
+ -package -private -help -doclet -docletpath \
+ -sourcepath -classpath -exclude -subpackages \
+ -breakiterator -bootclasspath -source -extdirs \
+ -verbose -locale -encoding -J -d -use -version \
+ -author -docfilessubdirs -splitindex \
+ -windowtitle -doctitle -header -footer -bottom \
+ -link -linkoffline -excludedocfilessubdir \
+ -group -nocomment -nodeprecated -noqualifier \
+ -nosince -nodeprecatedlist -notree -noindex \
+ -nohelp -nonavbar -quiet -serialwarn -tag \
+ -taglet -tagletpath -charset -helpfile \
+ -linksource -stylesheetfile -docencoding' -- \
+ $cur ) )
+ else
+ # source files completion
+ _filedir java
+ # packages completion
+ _java_packages
+ fi
+} &&
+complete -F _javadoc $filenames javadoc
+
+# javac completion
+#
+have javac &&
+_javac()
+{
+ COMPREPLY=()
+ local cur prev
+
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case $prev in
+ -d)
+ _filedir -d
+ return 0
+ ;;
+ -@(classpath|bootclasspath|sourcepath|extdirs))
+ _java_path
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ # relevant options completion
+ COMPREPLY=( $( compgen -W '-g -g:none -g:lines -g:vars\
+ -g:source -O -nowarn -verbose -deprecation -classpath\
+ -sourcepath -bootclasspath -extdirs -d -encoding -source\
+ -target -help' -- $cur ) )
+ else
+ # source files completion
+ _filedir java
+ fi
+} &&
+complete -F _javac $filenames javac
+
+# PINE address-book completion
+#
+have pine &&
+_pineaddr()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ COMPREPLY=( $( compgen -W '$( awk "{print \$1}" ~/.addressbook 2>/dev/null)' \
+ -- $cur ) )
+} &&
+complete -F _pineaddr $default pine
+
+# mutt completion
+#
+# Mutt doesn't have an "addressbook" like Pine, but it has aliases and
+# a "query" function to retrieve addresses, so that's what we use here.
+have mutt || have muttng && {
+_muttaddr()
+{
+ _muttaliases
+ _muttquery
+ return 0
+}
+
+_muttconffiles()
+{
+ local file sofar
+ local -a newconffiles
+
+ sofar=" $1 "
+ shift
+ while [[ "$1" ]]; do
+ newconffiles=( $(sed -rn 's|^source[[:space:]]+([^[:space:]]+).*$|\1|p' $(eval echo $1) ) )
+ for file in "${newconffiles[@]}"; do
+ [[ ! "$file" ]] || [[ "${sofar/ ${file} / }" != "$sofar" ]] &&
+ continue
+ sofar="$sofar $file"
+ sofar=" $(eval _muttconffiles \"$sofar\" $file) "
+ done
+ shift
+ done
+ echo $sofar
+}
+
+_muttaliases()
+{
+ local cur muttrc
+ local -a conffiles aliases
+ cur=`_get_cword`
+
+ [ -f ~/.${muttcmd}/${muttcmd}rc ] && muttrc="~/.${muttcmd}/${muttcmd}rc"
+ [ -f ~/.${muttcmd}rc ] && muttrc="~/.${muttcmd}rc"
+ [ -z "$muttrc" ] && return 0
+
+ conffiles=( $(eval _muttconffiles $muttrc $muttrc) )
+ aliases=( $( sed -rn 's|^alias[[:space:]]+([^[:space:]]+).*$|\1|p' \
+ $(eval echo "${conffiles[@]}") ) )
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "${aliases[*]}" -- $cur ) )
+
+ return 0
+}
+
+_muttquery()
+{
+ local cur querycmd
+ local -a queryresults
+ cur=`_get_cword`
+
+ querycmd="$( $muttcmd -Q query_command | sed -r 's|^query_command=\"(.*)\"$|\1|; s|%s|'$cur'|' )"
+ if [ -z "$cur" -o -z "$querycmd" ]; then
+ queryresults=()
+ else
+ queryresults=( $( $querycmd | \
+ sed -nr '2,$s|^([^[:space:]]+).*|\1|p' ) )
+ fi
+
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "${queryresults[*]}" \
+ -- $cur ) )
+
+ return 0
+}
+
+_muttfiledir()
+{
+ local cur folder spoolfile
+ cur=`_get_cword`
+
+ # This is currently not working so well. Perhaps this function should
+ # just call _filedir() for the moment.
+ if [[ $cur == [=+]* ]]; then
+ folder="$( $muttcmd -Q folder | sed -r 's|^folder=\"(.*)\"$|\1|' )"
+ : folder:=~/Mail
+
+ # Match any file in $folder beginning with $cur
+ # (minus the leading '=' sign).
+ COMPREPLY=( $( compgen -f -- "$folder/${cur:1}" ) )
+ COMPREPLY=( ${COMPREPLY[@]#$folder/} )
+ return 0
+ elif [ "$cur" == !* ]; then
+ spoolfile="$( $muttcmd -Q spoolfile | sed -r 's|^spoolfile=\"(.*)\"$|\1|' )"
+ [ ! -z "$spoolfile" ] && eval cur="${cur/^!/$spoolfile}";
+ fi
+ _filedir
+
+ return 0
+}
+
+_mutt()
+{
+ local cur prev
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ COMPREPLY=()
+
+ [ ${COMP_WORDS[0]} == muttng ] && muttcmd="muttng" || muttcmd="mutt"
+
+ case "$cur" in
+ -*)
+ COMPREPLY=( $( compgen -W '-A -a -b -c -e -f -F -H -i -m -n \
+ -p -Q -R -s -v -x -y -z -Z -h' \
+ -- $cur ) )
+ return 0
+ ;;
+ *)
+ case "$prev" in
+ -@(a|f|F|H|i))
+ _muttfiledir
+ return 0
+ ;;
+ -A)
+ _muttaliases
+ return 0
+ ;;
+ -@(e|m|Q|s|h|p|R|v|y|z|Z))
+ return 0
+ ;;
+ *)
+ _muttaddr
+ return 0
+ ;;
+ esac
+ ;;
+ esac
+
+}
+complete -F _mutt $default $filenames mutt muttng
+}
+
+_configure_func()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ # if $COMP_CONFIGURE_HINTS is not null, then completions of the form
+ # --option=SETTING will include 'SETTING' as a contextual hint
+ [[ "$cur" != -* ]] && return 0
+
+ if [ -n "$COMP_CONFIGURE_HINTS" ]; then
+ COMPREPLY=( $( $1 --help | awk '/^ --[A-Za-z]/ { print $1; if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,].*//g' | grep ^$cur ) )
+
+ else
+ COMPREPLY=( $( $1 --help | awk '/^ --[A-Za-z]/ { print $1; if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,=].*//g' | grep ^$cur ) )
+ fi
+}
+complete -F _configure_func $default configure
+
+# Debian reportbug(1) completion
+#
+have reportbug &&
+_reportbug()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -f|--filename|-i|--include|--mta|-o|--output)
+ _filedir
+ return 0
+ ;;
+ -B|--bts)
+ COMPREPLY=( $( compgen -W "debian guug kde mandrake help" -- \
+ $cur ))
+ return 0
+ ;;
+ -e|--editor|--mua)
+ COMP_WORDS=(COMP_WORDS[0] $cur)
+ COMP_CWORD=1
+ _command
+ return 0
+ ;;
+ --mode)
+ COMPREPLY=( $( compgen -W "novice standard expert" -- $cur ) )
+ return 0
+ ;;
+ -S|--severity)
+ COMPREPLY=( $( compgen -W "grave serious important normal \
+ minor wishlist" -- $cur ) )
+ return 0
+ ;;
+ -u|--ui|--interface)
+ COMPREPLY=( $( compgen -W "newt text gnome" -- $cur ) )
+ return 0
+ ;;
+ -t|--type)
+ COMPREPLY=( $( compgen -W "gnats debbugs" -- $cur ) )
+ return 0
+ ;;
+ -T|--tags)
+ COMPREPLY=( $( compgen -W "none patch security upstream sid \
+ woody potato sarge fixed" -- $cur ))
+ return 0
+ ;;
+ *)
+ ;;
+ esac
+
+ COMPREPLY=($( compgen -W '-h --help -v --version -a --af -b \
+ --no-query-bts --query-bts -B --bts -c --configure \
+ --no-config-files --check-available -d --debug \
+ --no-check-available -e --editor --email -f \
+ --filename -g --gnupg -H --header -i --include -j \
+ --justification -l --ldap --no-ldap -L --list-cc -m \
+ --maintonly --mode --mua --mta --mutt -n --mh --nmh \
+ -o --output -p --print -P --pgp --proxy --http_proxy\
+ -q --quiet -Q --query-only --realname --report-quiet \
+ --reply-to --replyto -s --subject -S --severity \
+ --smtphost -t --type -T --tags --template -V -x \
+ --no-cc --package-version -z --no-compress \
+ --ui --interface -u \
+ wnpp boot-floppies kernel-image' -- $cur ) \
+ $( apt-cache pkgnames -- $cur 2> /dev/null ) )
+ _filedir
+ return 0
+} &&
+complete -F _reportbug $filenames reportbug
+
+# Debian querybts(1) completion
+#
+have querybts &&
+_querybts()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -B|--bts)
+ COMPREPLY=( $( compgen -W "debian guug kde mandrake help" -- \
+ $cur ))
+ return 0
+ ;;
+ -u|--ui|--interface)
+ COMPREPLY=($( compgen -W "newt text gnome" -- $cur ))
+ return 0
+ ;;
+ *)
+ ;;
+ esac
+
+ COMPREPLY=($( compgen -W '-h --help -v --version -A --archive \
+ -B --bts -l --ldap --no-ldap --proxy= --http_proxy= \
+ -s --source -w --web -u --ui --interface \
+ wnpp boot-floppies' -- $cur ) \
+ $( apt-cache pkgnames -- $cur 2> /dev/null ) )
+} &&
+complete -F _querybts $filenames querybts
+
+# update-alternatives completion
+#
+have update-alternatives && {
+installed_alternatives()
+{
+ local admindir
+ # find the admin dir
+ for i in alternatives dpkg/alternatives rpm/alternatives; do
+ [ -d /var/lib/$i ] && admindir=/var/lib/$i && break
+ done
+ for (( i=1; i < COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" == --admindir ]]; then
+ admindir=${COMP_WORDS[i+1]}
+ break
+ fi
+ done
+ COMPREPLY=( $( command ls $admindir | grep "^$cur" ) )
+}
+
+_update_alternatives()
+{
+ local cur prev mode args i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ --@(altdir|admindir))
+ _filedir -d
+ return 0
+ ;;
+ --@(help|version))
+ return 0
+ ;;
+ esac
+
+ # find wich mode to use and how many real args used so far
+ for (( i=1; i < COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config|remove-all) ]]; then
+ mode=${COMP_WORDS[i]}
+ args=$(($COMP_CWORD - i))
+ break
+ fi
+ done
+
+ case $mode in
+ --install)
+ case $args in
+ 1)
+ _filedir
+ ;;
+ 2)
+ installed_alternatives
+ ;;
+ 3)
+ _filedir
+ ;;
+ esac
+ ;;
+ --remove)
+ case $args in
+ 1)
+ installed_alternatives
+ ;;
+ 2)
+ _filedir
+ ;;
+ esac
+ ;;
+ --auto)
+ installed_alternatives
+ ;;
+ --remove-all)
+ installed_alternatives
+ ;;
+ --display)
+ installed_alternatives
+ ;;
+ --config)
+ installed_alternatives
+ ;;
+ *)
+ COMPREPLY=( $( compgen -W '--verbose --quiet --help --version \
+ --altdir --admindir' -- $cur ) \
+ $( compgen -W '--install --remove --auto --display \
+ --config' -- $cur ) )
+ esac
+}
+complete -F _update_alternatives update-alternatives
+}
+
+# Python completion
+#
+have python &&
+_python()
+{
+ local prev cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]##*/}
+
+ case "$prev" in
+ -Q)
+ COMPREPLY=( $( compgen -W "old new warn warnall" -- $cur ) )
+ return 0
+ ;;
+ -W)
+ COMPREPLY=( $( compgen -W "ignore default all module once error" -- $cur ) )
+ return 0
+ ;;
+ -c)
+ _filedir '@(py|pyc|pyo)'
+ return 0
+ ;;
+ !(python|-?))
+ [[ ${COMP_WORDS[COMP_CWORD-2]} != -@(Q|W) ]] && _filedir
+ ;;
+ esac
+
+
+ # if '-c' is already given, complete all kind of files.
+ for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
+ if [[ ${COMP_WORDS[i]} == -c ]]; then
+ _filedir
+ fi
+ done
+
+
+ if [[ "$cur" != -* ]]; then
+ _filedir '@(py|pyc|pyo)'
+ else
+ COMPREPLY=( $( compgen -W "- -d -E -h -i -O -Q -S -t -u \
+ -U -v -V -W -x -c" -- $cur ) )
+ fi
+
+
+
+ return 0
+} &&
+complete -F _python $filenames python
+
+# Perl completion
+#
+have perl &&
+{
+_perlmodules()
+{
+ COMPREPLY=( $( compgen -P "$prefix" -W "$( perl -e 'sub mods { my ($base,$dir)=@_; return if $base !~ /^\Q$ENV{cur}/; chdir($dir) or return; for (glob(q[*.pm])) {s/\.pm$//; print qq[$base$_\n]}; mods(/^(?:[.\d]+|$Config{archname}-$Config{osname}|auto)$/ ? undef : qq[${base}${_}\\\\:\\\\:],qq[$dir/$_]) for grep {-d} glob(q[*]); } mods(undef,$_) for @INC;' )" -- $cur ) )
+}
+
+_perl()
+{
+ local cur prev prefix temp
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ prefix=""
+
+ # completing an option (may or may not be separated by a space)
+ if [[ "$cur" == -?* ]]; then
+ temp=$cur
+ prev=${temp:0:2}
+ cur=${temp:2}
+ prefix=$prev
+ fi
+
+ # only handle module completion for now
+ case "$prev" in
+ -I|-x)
+ COMPREPLY=( $( compgen -d -P "$prev" -- "$cur" ) )
+ return 0
+ ;;
+ -m|-M)
+ _perlmodules
+ return 0
+ ;;
+ esac
+
+ # handle case where first parameter is not a dash option
+ if [[ "${COMP_WORDS[COMP_CWORD]}" != -* ]]; then
+ _filedir
+ return 0
+ fi
+
+ # complete using basic options
+ COMPREPLY=( $( compgen -W '-C -s -T -u -U -W -X -h -v -V -c -w -d -D -p \
+ -n -a -F -l -0 -I -m -M -P -S -x -i -e ' -- $cur ) )
+ return 0
+}
+complete -F _perl $filenames perl
+
+_perldoc()
+{
+ local cur prev prefix temp
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ prefix=""
+
+ # completing an option (may or may not be separated by a space)
+ if [[ "$cur" == -?* ]]; then
+ temp=$cur
+ prev=${temp:0:2}
+ cur=${temp:2}
+ prefix=$prev
+ fi
+
+ # complete builtin perl functions
+ case $prev in
+ -f)
+ COMPREPLY=( $( compgen -W 'chomp chop chr crypt hex index lc \
+ lcfirst length oct ord pack q qq reverse rindex sprintf \
+ substr tr uc ucfirst y m pos quotemeta s split study qr abs \
+ atan2 cos exp hex int log oct rand sin sqrt srand pop push \
+ shift splice unshift grep join map qw reverse sort unpack \
+ delete each exists keys values binmode close closedir \
+ dbmclose dbmopen die eof fileno flock format getc print \
+ printf read readdir rewinddir seek seekdir select syscall \
+ sysread sysseek syswrite tell telldir truncate warn write \
+ pack read syscall sysread syswrite unpack vec -X chdir chmod \
+ chown chroot fcntl glob ioctl link lstat mkdir open opendir \
+ readlink rename rmdir stat symlink umask unlink utime caller \
+ continue do dump eval exit goto last next redo return \
+ sub wantarray caller import local my our package use defined \
+ formline reset scalar undef \
+ alarm exec fork getpgrp getppid getpriority kill pipe qx \
+ setpgrp setpriority sleep system times wait waitpid \
+ import no package require use bless dbmclose dbmopen package \
+ ref tie tied untie use accept bind connect getpeername \
+ getsockname getsockopt listen recv send setsockopt shutdown \
+ socket socketpair msgctl msgget msgrcv msgsnd semctl semget \
+ semop shmctl shmget shmread shmwrite endgrent endhostent \
+ endnetent endpwent getgrent getgrgid getgrnam getlogin \
+ getpwent getpwnam getpwuid setgrent setpwent endprotoent \
+ endservent gethostbyaddr gethostbyname gethostent \
+ getnetbyaddr getnetbyname getnetent getprotobyname \
+ getprotobynumber getprotoent getservbyname getservbyport \
+ getservent sethostent setnetent setprotoent setservent \
+ gmtime localtime time times' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ case $cur in
+ -*)
+ COMPREPLY=( $( compgen -W '-h -v -t -u -m -l -F -X -f -q' -- $cur ))
+ return 0
+ ;;
+ */*)
+ return 0
+ ;;
+ *)
+ _perlmodules
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W '$( PAGER=cat man perl 2>/dev/null | sed -ne "/perl.*Perl overview/,/perlwin32/s/^[^a-z0-9]*\([a-z0-9]*\).*$/\1/p")' -- $cur ) )
+
+ return 0
+ ;;
+ esac
+}
+complete -F _perldoc $default perldoc
+}
+
+# rcs(1) completion
+#
+have rcs &&
+_rcs()
+{
+ local cur prev file dir i
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ file=${cur##*/}
+ dir=${cur%/*}
+
+ # deal with relative directory
+ [ "$file" = "$dir" ] && dir=.
+
+ COMPREPLY=( $( compgen -f "$dir/RCS/$file" ) )
+
+ for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
+ file=${COMPREPLY[$i]##*/}
+ dir=${COMPREPLY[$i]%RCS/*}
+ COMPREPLY[$i]=$dir$file
+ done
+
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -G "$dir/$file*,v" ) )
+
+ for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
+ COMPREPLY[$i]=${COMPREPLY[$i]%,v}
+ done
+
+ # default to files if nothing returned and we're checking in.
+ # otherwise, default to directories
+ [ ${#COMPREPLY[@]} -eq 0 -a $1 = ci ] && _filedir || _filedir -d
+} &&
+complete -F _rcs $filenames ci co rlog rcs rcsdiff
+
+# lilo(8) completion
+#
+have lilo && {
+_lilo_labels()
+{
+ COMPREPLY=( $( awk -F'=' '/label/ {print $2}' \
+ /etc/lilo.conf | sed -e 's/"//g' | grep "^$cur" ) )
+}
+
+_lilo()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case $prev in
+ -@(C|i|m|s|S))
+ _filedir
+ return 0
+ ;;
+ -r)
+ _filedir -d
+ return 0
+ ;;
+ -@(I|D|R))
+ # label completion
+ _lilo_labels
+ return 0
+ ;;
+ -@(A|b|M|u|U))
+ # device completion
+ cur=${cur:=/dev/}
+ _filedir
+ return 0
+ ;;
+ -T)
+ # topic completion
+ COMPREPLY=( $( compgen -W 'help ChRul EBDA geom geom= \
+ table= video' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ # relevant options completion
+ COMPREPLY=( $( compgen -W '-A -b -c -C -d -f -g -i -I -l -L -m \
+ -M -p -P -q -r -R -s -S -t -T -u -U -v -V -w -x -z' -- \
+ $cur ) )
+ fi
+}
+complete -F _lilo lilo
+}
+
+# links completion
+#
+have links &&
+_links()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ case "$cur" in
+ --*)
+ COMPREPLY=( $( compgen -W '--help' -- $cur ) )
+ ;;
+ -*)
+ COMPREPLY=( $( compgen -W '-async-dns -max-connections \
+ -max-connections-to-host -retries \
+ -receive-timeout -unrestartable-receive-timeout\
+ -format-cache-size -memory-cache-size \
+ -http-proxy -ftp-proxy -download-dir \
+ -assume-codepage -anonymous -dump -no-connect \
+ -source -version -help' -- $cur ) )
+ ;;
+ *)
+ if [ -r ~/.links/links.his ]; then
+ COMPREPLY=( $( compgen -W '$( < ~/.links/links.his )' \
+ -- $cur ) )
+ fi
+ _filedir '@(htm|html)'
+ return 0
+ ;;
+ esac
+
+ return 0
+} &&
+complete -F _links $filenames links
+
+[ $UNAME = FreeBSD ] && {
+# FreeBSD package management tool completion
+#
+_pkg_delete()
+{
+ local cur pkgdir prev
+
+ pkgdir=${PKG_DBDIR:-/var/db/pkg}/
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ [ "$prev" = "-o" -o "$prev" = "-p" -o "$prev" = "-W" ] && return 0
+
+ COMPREPLY=( $( compgen -d $pkgdir$cur ) )
+ COMPREPLY=( ${COMPREPLY[@]#$pkgdir} )
+
+ return 0
+}
+complete -F _pkg_delete $dirnames pkg_delete pkg_info
+have pkg_deinstall && complete -F _pkg_delete $dirnames pkg_deinstall
+
+# FreeBSD kernel module commands
+#
+_kldload()
+{
+ local cur moddir
+
+ moddir=/modules/
+ [ -d $moddir ] || moddir=/boot/kernel/
+ cur=`_get_cword`
+
+ COMPREPLY=( $( compgen -f $moddir$cur ) )
+ COMPREPLY=( ${COMPREPLY[@]#$moddir} )
+ COMPREPLY=( ${COMPREPLY[@]%.ko} )
+
+ return 0
+}
+complete -F _kldload $filenames kldload
+
+_kldunload()
+{
+ local cur
+ cur=`_get_cword`
+ COMPREPLY=( $(kldstat | sed -ne "s/^.*[ \t]\+\($cur[a-z_]\+\).ko$/\1/p") )
+}
+complete -F _kldunload $filenames kldunload
+}
+
+# FreeBSD portupgrade completion
+#
+have portupgrade &&
+_portupgrade()
+{
+ local cur pkgdir prev
+
+ pkgdir=${PKG_DBDIR:-/var/db/pkg}/
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ [ "$prev" = "-l" -o "$prev" = "-L" -o "$prev" = "-o" ] && return 0
+
+ COMPREPLY=( $( compgen -d $pkgdir$cur ) )
+ COMPREPLY=( ${COMPREPLY[@]#$pkgdir} )
+ COMPREPLY=( ${COMPREPLY[@]%-*} )
+
+ return 0
+} &&
+complete -F _portupgrade $dirnames portupgrade
+
+# FreeBSD portinstall completion
+#
+have portinstall &&
+_portinstall()
+{
+ local cur portsdir prev indexfile
+ local -a COMPREPLY2
+
+ portsdir=${PORTSDIR:-/usr/ports}/
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ # First try INDEX-5
+ indexfile=$portsdir/INDEX-5
+ # Then INDEX if INDEX-5 does not exist or system is not FreeBSD 5.x
+ [ "${OSTYPE%.*}" = "freebsd5" -a -f $indexfile ] ||
+ indexfile=$portsdir/INDEX
+
+ [ "$prev" = "-l" -o "$prev" = "-L" -o "$prev" = "-o" ] && return 0
+
+ COMPREPLY=( $( egrep "^$cur" < $indexfile | cut -d'|' -f1 ) )
+ COMPREPLY2=( $( egrep "^[^\|]+\|$portsdir$cur" < $indexfile | \
+ cut -d'|' -f2 ) )
+ COMPREPLY2=( ${COMPREPLY2[@]#$portsdir} )
+ COMPREPLY=( "${COMPREPLY[@]}" "${COMPREPLY2[@]}" )
+
+ return 0
+} &&
+complete -F _portinstall $dirnames portinstall
+
+# Slackware Linux removepkg completion
+#
+have removepkg && [ -f /etc/slackware-version ] &&
+_removepkg()
+{
+ local packages cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ COMPREPLY=( $( (cd /var/log/packages; compgen -f -- "$cur") ) )
+} &&
+complete -F _removepkg $filenames removepkg &&
+ complete $dirnames -f -X '!*.tgz' installpkg upgradepkg explodepkg
+
+# look(1) completion
+#
+have look &&
+_look()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD = 1 ]; then
+ COMPREPLY=( $( compgen -W '$(look $cur)' ) )
+ fi
+} &&
+complete -F _look $default look
+
+# ypcat(1) and ypmatch(1) completion
+#
+have ypmatch &&
+_ypmatch()
+{
+ local cur map
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ [ $1 = ypcat ] && [ $COMP_CWORD -gt 1 ] && return 0
+ [ $1 = ypmatch ] && [ $COMP_CWORD -gt 2 ] && return 0
+
+ if [ $1 = ypmatch ] && [ $COMP_CWORD -eq 1 ] && \
+ [ ${#COMP_WORDS[@]} -eq 3 ]; then
+ map=${COMP_WORDS[2]}
+ COMPREPLY=( $( compgen -W '$( ypcat $map | \
+ cut -d':' -f 1 )' -- $cur) )
+ else
+ [ $1 = ypmatch ] && [ $COMP_CWORD -ne 2 ] && return 0
+ COMPREPLY=( $( compgen -W \
+ '$( echo $(ypcat -x | cut -d"\"" -f 2))' -- $cur))
+ fi
+
+ return 0
+} &&
+complete -F _ypmatch ypmatch ypcat
+
+# mplayer(1) completion
+#
+have mplayer && {
+_mplayer_options_list()
+{
+ cur=${cur%\\}
+ COMPREPLY=( $( $1 $2 help 2> /dev/null | \
+ sed -e '1,/^Available/d' | awk '{print $1}' | \
+ sed -e 's/:$//' -e 's/^'${2#-}'$//' -e 's/<.*//' | \
+ grep "^$cur" ) )
+}
+
+_mplayer()
+{
+ local cmd cur prev skinsdir IFS=$' \t\n' i j k=0
+
+ COMPREPLY=()
+ cmd=${COMP_WORDS[0]}
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(ac|afm|vc|vfm|ao|vo|vop|fstype))
+ _mplayer_options_list mplayer $prev
+ return 0
+ ;;
+ -@(oac|ovc|of))
+ _mplayer_options_list mencoder $prev
+ return 0
+ ;;
+ -audiofile)
+ _filedir '@(mp3|MP3|mpg|MPG|ogg|OGG|wav|WAV|mid|MID|flac|FLAC|mka|MKA)'
+ return 0
+ ;;
+ -font)
+ _filedir '@(desc|ttf)'
+ return 0
+ ;;
+ -sub)
+ _filedir '@(srt|SRT|sub|SUB|txt|TXT|utf|UTF|rar|RAR|mpsub|smi|js|ssa|SSA|aas|AAS)'
+ return 0
+ ;;
+ -vobsub)
+ _filedir '@(idx|IDX|ifo|IFO|sub|SUB)'
+ IFS=$'\t\n'
+ COMPREPLY=( $( for i in "${COMPREPLY[@]}"; do
+ if [ -f $i -a -r $i ]; then
+ echo ${i%.*}
+ else
+ echo $i
+ fi
+ done ) )
+ IFS=$' \t\n'
+ return 0
+ ;;
+ -ifo)
+ _filedir '@(ifo|IFO)'
+ return 0
+ ;;
+ -cuefile)
+ _filedir '@(bin|BIN|cue|CUE)'
+ return 0
+ ;;
+ -skin)
+ # if you don't have installed mplayer in /usr you
+ # may want to set the MPLAYER_SKINS_DIR global variable
+ if [ -n "$MPLAYER_SKINS_DIR" ]; then
+ skinsdir=$MPLAYER_SKINS_DIR
+ else
+ skinsdir=/usr/share/mplayer/Skin
+ fi
+
+ IFS=$'\t\n'
+ for i in ~/.mplayer/Skin $skinsdir; do
+ if [ -d $i -a -r $i ]; then
+ for j in $( compgen -d $i/$cur ); do
+ COMPREPLY[$k]=${j#$i/}
+ k=$((++k))
+ done
+ fi
+ done
+ IFS=$' \t\n'
+ return 0
+ ;;
+ -@(mixer|@(cdrom|dvd)-device|dvdauth|fb|zrdev))
+ cur=${cur:=/dev/}
+ _filedir
+ return 0
+ ;;
+ -@(edl?(out)|lircconf|menu-cfg|playlist|csslib|dumpfile)| \
+ -@(subfile|vobsub|aofile|fbmodeconfig|include|o|dvdkey)| \
+ -passlogfile)
+ _filedir
+ return 0
+ ;;
+ -@(auto@(q|sync)|loop|menu-root|speed|sstep|aid|alang)| \
+ -@(?(@(audio|sub)-)demuxer|bandwidth|cache|chapter)| \
+ -@(dvd?(angle)|fps|frames|mc|passwd|user|sb|srate|ss|vcd)| \
+ -@(vi?(d|vo)|ffactor|sid|slang|spu@(align|aa|gauss))| \
+ -@(vobsubid|delay|bpp|brightness|contrast|dfbopts|display)| \
+ -@(fbmode|geometry|guiwid|hue|icelayer|screen[wh]|wid)| \
+ -@(monitor@(aspect|-@(dotclock|[hv]freq))|panscan|saturation)| \
+ -@(xineramascreen|zr@(crop|norm|quality|[xy]doff|[vh]dec))| \
+ -@(aspect|pp|x|y|xy|z|stereo|audio-@(density|delay|preload))| \
+ -@(endpos|osdlevel|ffourcc|sws|channels|skiplimit|format)| \
+ -@(ofps|aa@(driver|@(osd|sub)color)|vobsubout?(i@(ndex|d)))| \
+ -sub@(-bg-@(alpha|color)|cp|delay|fps|pos|align|width)| \
+ -sub@(font-@(blur|outline|autoscale|encoding|@(osd|text)-scale)))
+ return 0
+ ;;
+ -lavdopts)
+ COMPREPLY=( $( compgen -W 'ec er= bug= idct= gray' \
+ -- $cur ) )
+ return 0
+ ;;
+ -lavcopts)
+ COMPREPLY=( $( compgen -W 'vcodec= vqmin= vqscale= \
+ vqmax= mbqmin= mbqmax= vqdiff= \
+ vmax_b_frames= vme= vhq v4mv \
+ keyint= vb_strategy= vpass= \
+ aspect= vbitrate= vratetol= \
+ vrc_maxrate= vrc_minrate= \
+ vrc_buf_size= vb_qfactor= vi_qfactor= \
+ vb_qoffset= vi_qoffset= vqblur= \
+ vqcomp= vrc_eq= vrc_override= \
+ vrc_init_cplx= vqsquish= vlelim= \
+ vcelim= vstrict= vdpart vpsize= gray \
+ vfdct= idct= lumi_mask= dark_mask= \
+ tcplx_mask= scplx_mask= naq ildct \
+ format= pred qpel precmp= cmp= \
+ subcmp= predia= dia= trell last_pred= \
+ preme= subq= psnr mpeg_quant aic umv' \
+ -- $cur ) )
+ return 0
+ ;;
+ -ssf)
+ COMPREPLY=( $( compgen -W 'lgb= cgb= ls= cs= chs= \
+ cvs=' -- $cur ) )
+ return 0
+ ;;
+ -jpeg)
+ COMPREPLY=( $( compgen -W 'noprogressive progressive \
+ nobaseline baseline optimize= \
+ smooth= quality= outdir=' -- $cur ) )
+ return 0
+ ;;
+ -xvidopts)
+ COMPREPLY=( $( compgen -W 'dr2 nodr2' -- $cur ) )
+ return 0
+ ;;
+ -xvidencopts)
+ COMPREPLY=( $( compgen -W 'pass= bitrate= \
+ fixed_quant= me_quality= 4mv \
+ rc_reaction_delay_factor= \
+ rc_averaging_period= rc_buffer= \
+ quant_range= min_key_interval= \
+ max_key_interval= mpeg_quant \
+ mod_quant lumi_mask hintedme \
+ hintfile debug keyframe_boost= \
+ kfthreshold= kfreduction=' -- $cur ) )
+ return 0
+ ;;
+ -divx4opts)
+ COMPREPLY=( $( compgen -W 'br= key= deinterlace q= \
+ min_quant= max_quant= rc_period= \
+ rc_reaction_period= crispness= \
+ rc_reaction_ratio= pass= vbrpass= \
+ help' -- $cur ) )
+ return 0
+ ;;
+ -info)
+ COMPREPLY=( $( compgen -W 'name= artist= genre= \
+ subject= copyright= srcform= \
+ comment= help' -- $cur ) )
+ return 0
+ ;;
+ -lameopts)
+ COMPREPLY=( $( compgen -W 'vbr= abr cbr br= q= aq= \
+ ratio= vol= mode= padding= fast \
+ preset= help' -- $cur ) )
+ return 0
+ ;;
+ -rawaudio)
+ COMPREPLY=( $( compgen -W 'on channels= rate= \
+ samplesize= format=' -- $cur ) )
+ return 0
+ ;;
+ -rawvideo)
+ COMPREPLY=( $( compgen -W 'on fps= sqcif qcif cif \
+ 4cif pal ntsc w= h= y420 yv12 yuy2 \
+ y8 format= size=' -- $cur ) )
+ return 0
+ ;;
+ -aop)
+ COMPREPLY=( $( compgen -W 'list= delay= format= fout= \
+ volume= mul= softclip' -- $cur ) )
+ return 0
+ ;;
+ -dxr2)
+ COMPREPLY=( $( compgen -W 'ar-mode= iec958-encoded \
+ iec958-decoded mute ucode= 75ire bw \
+ color interlaced macrovision= norm= \
+ square-pixel ccir601-pixel cr-left= \
+ cr-right= cr-top= cr-bot= ck-rmin= \
+ ck-gmin= ck-bmin= ck-rmax= ck-gmax= \
+ ck-bmax= ck-r= ck-g= ck-b= \
+ ignore-cache= ol-osd= olh-cor= \
+ olw-cor= olx-cor= oly-cor= overlay \
+ overlay-ratio= update-cache' -- $cur ))
+ return 0
+ ;;
+ -tv)
+ COMPREPLY=( $( compgen -W 'on noaudio driver= device= \
+ input= freq= outfmt= width= height= \
+ buffersize= norm= channel= chanlist= \
+ audiorate= forceaudio alsa amode= \
+ forcechan= adevice= audioid= volume= \
+ bass= treble= balance= fps= \
+ channels= immediatemode=' -- $cur ) )
+ return 0
+ ;;
+ -mf)
+ COMPREPLY=( $( compgen -W 'on w= h= fps= type=' \
+ -- $cur ) )
+ return 0
+ ;;
+ -cdda)
+ COMPREPLY=( $( compgen -W 'speed= paranoia= \
+ generic-dev= sector-size= overlap= \
+ toc-bias toc-offset= skip noskip' \
+ -- $cur ) )
+ return 0
+ ;;
+ -input)
+ COMPREPLY=( $( compgen -W 'conf= ar-delay ar-rate \
+ keylist cmdlist js-dev file' -- $cur ) )
+ return 0
+ ;;
+ -af)
+ COMPREPLY=( $( compgen -W 'resample resample= \
+ channels channels= format format= \
+ volume volume= delay delay= pan \
+ pan= sub sub= surround surround=' \
+ -- $cur ) )
+ return 0
+ ;;
+ -af-adv)
+ COMPREPLY=( $( compgen -W 'force= list=' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ case "$cur" in
+ -*)
+ COMPREPLY=( $( compgen -W '-aid -alang -audio-demuxer \
+ -audiofile -cdrom-device -cache -cdda \
+ -channels -chapter -csslib -demuxer \
+ -dvd -dvd-device -dvdangle -dvdauth \
+ -dvdkey -dvdnav -forceidx -fps -frames \
+ -hr-mp3-seek -idx -mc -mf -ni -nobps \
+ -passwd -rawaudio -rtsp-stream-over-tcp\
+ -skipopening -sb -srate -ss -tv -user \
+ -vcd -vid -vivo -ifo -ffactor -font \
+ -noautosub -nooverlapsub -sid -slang \
+ -sub -subcc -subcp -sub-demuxer \
+ -subdelay -subfont-autoscale \
+ -subfont-blur -subfont-encoding \
+ -subfont-osd-scale -subfont-outline \
+ -subfont-text-scale -subfps -subfile \
+ -subpos -unicode -utf8 -vobsub \
+ -vobsubid -ac -afm -aspect -flip \
+ -lavdopts -noaspect -nosound -pp -ssf \
+ -stereo -sws -vc -vfm -vop -xvidopts\
+ -xy -zoom -bandwidth -cuefile \
+ -noextbased -rawvideo -overlapsub \
+ -sub-bg-alpha -sub-bg-color -subalign \
+ -subwidth -sub-no-text-pp -spualign \
+ -spuaa -spugauss -pphelp -verbose -v \
+ -noni -noidx -nohr-mp3-seek -extbased \
+ -bps -oldpp -nozoom -noflip -nounicode \
+ -noutf8' -- $cur ) )
+ # add mplayer specific options
+ [[ "$cmd" == @(?(g)mplayer) ]] && COMPREPLY=( "${COMPREPLY[@]}" \
+ $(compgen -W '-autoq -autosync -benchmark \
+ -framedrop -h -help -hardframedrop \
+ -identify -input -lircconf -loop \
+ -nojoystick -nolirc -nortc -playlist \
+ -quiet -really-quiet -rnd -sdp -skin \
+ -slave -softsleep -speed -sstep \
+ -use-stdin -dumpaudio -dumpfile \
+ -dumpstream -dumpvideo -dumpmicrodvdsub\
+ -dumpmpsub -dumpsrtsub -dumpjacosub \
+ -dumpsami -dumpsub -osdlevel -af \
+ -af-adv -ao -aofile -aop -delay -mixer \
+ -nowaveheader -bpp -brightness \
+ -contrast -display -double -dr -dxr2 \
+ -fb -fbmode -fbmodeconfig -forcexv -fs \
+ -geometry -hue -icelayer -jpeg \
+ -monitor-dotclock -monitor-hfreq \
+ -monitor-vfreq -monitoraspect \
+ -nograbpointer -noslices -panscan \
+ -rootwin -saturation -screenw -screenh \
+ -stop-xscreensaver -vm -vo -vsync -wid \
+ -xineramascreen -z -zrbw -zrcrop \
+ -zrdev -zrfd -zrhelp -zrnorm -zrquality \
+ -zrvdec -zrhdec -zrxdoff -zrydoff -y \
+ -edl -edlout -enqueue -fixed-vo \
+ -menu -menu-root -menu-cfg -shuffle \
+ -format -aahelp -dfbopts -fstype \
+ -guiwid -nokeepaspect -x --help \
+ -aaosdcolor -aasubcolor -aadriver \
+ -aaextended -aaeight' -- $cur) )
+ # add mencoder specific options
+ [[ "$cmd" = mencoder ]] && COMPREPLY=( "${COMPREPLY[@]}" \
+ $(compgen -W '-audio-density -audio-delay \
+ -audio-preload -divx4opts -endpos \
+ -ffourcc -include -info -lameopts \
+ -lavcopts -noskip -o -oac -ofps -ovc \
+ -passlogfile -skiplimit -vobsubout \
+ -vobsuboutindex -vobsuboutid \
+ -xvidencopts -of --verbose' -- $cur) )
+ ;;
+ *)
+ _filedir '@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|ASF|vob|VOB|bin|BIN|dat|DAT|vcd|VCD|ps|PS|pes|PES|fli|FLI|flv|FLV|viv|VIV|rm?(j)|RM?(J)|ra?(m)|RA?(M)|yuv|YUV|mov|MOV|qt|QT|mp[34]|MP[34]|m4v|M4V|og[gm]|OG[GM]|wav|WAV|dump|DUMP|mk[av]|MK[AV]|m4a|M4A|aac|AAC|m2v|M2V|dv|DV|rmvb|RMVB|mid|MID|ts|TS|3gp|mpc|MPC|flac|FLAC|flv|FLV|divx|DIVX)'
+ ;;
+ esac
+
+ return 0
+}
+complete $filenames -F _mplayer mplayer mencoder gmplayer kplayer
+}
+
+# KDE dcop completion
+#
+have dcop &&
+_dcop()
+{
+ local cur compstr
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ if [ -z $cur ]; then
+ compstr=${COMP_WORDS[*]}
+ else
+ compstr=$( command echo ${COMP_WORDS[*]} | sed "s/ $cur$//" )
+ fi
+ COMPREPLY=( $( compgen -W '$( command $compstr | sed s/\(.*\)// )' -- $cur ) )
+} &&
+complete -F _dcop dcop
+
+# wvdial(1) completion
+#
+have wvdial &&
+_wvdial()
+{
+ local cur prev config i IFS=$'\t\n'
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case $prev in
+ --config)
+ _filedir
+ return 0
+ ;;
+ esac
+
+ case $cur in
+ -*)
+ COMPREPLY=( $( compgen -W '--config --chat \
+ --remotename --help --version --no-syslog' \
+ -- $cur ) )
+ ;;
+ *)
+ # start with global and personal config files
+ config="/etc/wvdial.conf"$'\t'"$HOME/.wvdialrc"
+ # replace with command line config file if present
+ for (( i=1; i < COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" == "--config" ]]; then
+ config=${COMP_WORDS[i+1]}
+ break
+ fi
+ done
+ # parse config files for sections and
+ # remove default section
+ COMPREPLY=( $( sed -ne \
+ "s|^\[Dialer \($cur.*\)\]$|\1|p" \
+ $config 2>/dev/null |grep -v '^Defaults$'))
+ # escape spaces
+ COMPREPLY=${COMPREPLY// /\\ }
+ ;;
+ esac
+
+} &&
+complete -F _wvdial wvdial
+
+# gpg(1) completion
+#
+have gpg &&
+_gpg()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(s|-sign|-clearsign|-decrypt-files|-load-extension))
+ _filedir
+ return 0
+ ;;
+ --@(export|@(?(l|nr|nrl)sign|edit)-key))
+ # return list of public keys
+ COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*/\([^ ]*\).*\(<\([^>]*\)>\).*$@\1 \3@p')" -- "$cur" ))
+ return 0
+ ;;
+ -@(r|-recipient))
+ COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*<\([^>]*\)>.*$@\1@p')" -- "$cur" ))
+ if [ -e ~/.gnupg/gpg.conf ]; then
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$( sed -ne 's@^[ \t]*group[ \t][ \t]*\([^=]*\).*$@\1@p' ~/.gnupg/gpg.conf )" -- "$cur") )
+ fi
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-s -b -e -f -c -d -a -r -u -Z -o -v\
+ -q -n -N $(gpg --dump-options)' -- $cur ) )
+ fi
+
+} &&
+complete -F _gpg $default gpg
+
+# iconv(1) completion
+#
+have iconv &&
+_iconv()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(f|t|-@(from|to)-code))
+ COMPREPLY=( $( compgen -W \
+ '$( iconv --list | sed -e "s@//@@;" )' -- "$cur" ) )
+ return 0
+ ;;
+ esac
+
+
+ if [[ "$cur" = -* ]]; then
+ COMPREPLY=( $( compgen -W '--from-code -f --to-code -t --list
+ --output -o --verbose' -- "$cur" ) )
+ return 0
+ fi
+} &&
+complete -F _iconv $default iconv
+
+# dict(1) completion
+#
+{ have dict || have rdict; } && {
+_dictdata()
+{
+ dict $host $port $1 2>/dev/null | sed -ne \
+ 's/^['$'\t '']['$'\t '']*\([^'$'\t '']*\).*$/\1/p'
+}
+
+_dict()
+{
+ local cur prev host port db dictfile
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ dictfile=/usr/share/dict/words
+
+ for (( i=1; i < COMP_CWORD; i++ )); do
+ case "${COMP_WORDS[i]}" in
+ -@(h|--host))
+ host=${COMP_WORDS[i+1]}
+ [ -n "$host" ] && host="-h $host"
+ i=$((++i))
+ ;;
+ -@(p|-port))
+ port=${COMP_WORDS[i+1]}
+ [ -n "$port" ] && port="-p $port"
+ i=$((++i))
+ ;;
+ -@(d|-database))
+ db=${COMP_WORDS[i+1]}
+ [ -n "$db" ] && host="-d $db"
+ i=$((++i))
+ ;;
+ *)
+ ;;
+ esac
+ done
+
+ if [[ "$cur" = -* ]]; then
+ COMPREPLY=( $( compgen -W '-h --host -p --port -d --database \
+ -m --match -s --strategy -c --config -C \
+ --nocorrect -D --dbs -S --strats -H \
+ --serverhelp -i --info -I --serverinfo \
+ -a --noauth -u --user -k --key -V --version \
+ -L --license --help -v --verbose -r --raw \
+ -P --pager --debug --html --pipesize --client' \
+ -- "$cur" ) )
+ return 0
+ fi
+
+ case "$prev" in
+ -@(d|-database|i|info))
+ COMPREPLY=( $( compgen -W '$( _dictdata -D )' -- "$cur" ) )
+ return 0
+ ;;
+ -@(s|-strategy))
+ COMPREPLY=( $( compgen -W '$( _dictdata -S )' -- "$cur" ) )
+ return 0
+ ;;
+ *)
+ ;;
+ esac
+
+ [ -r $dictfile ] && \
+ COMPREPLY=( $( compgen -W '$( cat $dictfile )' -- "$cur" ) )
+}
+complete -F _dict $default dict rdict
+}
+
+# cdrecord(1) completion
+#
+have cdrecord &&
+_cdrecord()
+{
+ local cur prev i generic_options track_options track_mode
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # foo=bar style option
+ if [[ "$cur" == *=* ]]; then
+ prev=${cur/=*/}
+ cur=${cur/*=/}
+ case "$prev" in
+ @(text|cue)file)
+ _filedir
+ return 0
+ ;;
+ blank)
+ COMPREPLY=( $( compgen -W 'help all fast \
+ track unreserve trtail unclose session' \
+ -- $cur ) )
+ return 0
+ ;;
+ driveropts)
+ COMPREPLY=( $( compgen -W 'burnfree noburnfree\
+ varirec= audiomaster forcespeed noforcespeed\
+ speedread nospeedread singlesession \
+ nosinglesession hidecdr nohidecdr tattooinfo\
+ tattoofile=' -- $cur ) )
+ return 0
+ ;;
+ esac
+ fi
+
+ generic_options=(-version -v -V -d -silent -s -force -immed -dummy \
+ -dao -raw -raw96r -raw96p -raw16 -multi -msinfo -toc \
+ -atip -fix -nofix -waiti -load -lock -eject -format \
+ -setdropts -checkdrive -prcap -inq -scanbus -reset \
+ -abort -overburn -ignsize -useinfo -packet -noclose \
+ -text debug= kdebug= kd= minbuf= speed= blank= fs= \
+ dev= gracetime= timeout= driver= driveropts= \
+ defpregap= pktsize= mcn= textfile= cuefile=)
+ track_options=(-audio -swab -data -mode2 -xa -xa1 -xa2 -xamix -cdi \
+ -isosize -pad padsize= -nopad -shorttrack -noshorttrack\
+ pregap= -preemp -nopreemp -copy -nocopy -scms tcsize= \
+ isrc= index=)
+ # look if previous was either a file or a track option
+ track_mode=0
+ if [ $COMP_CWORD -gt 1 ]; then
+ if [ -f "$prev" ]; then
+ track_mode=1
+ else
+ for (( i=0; i < ${#track_options[@]}; i++ )); do
+ if [[ "${track_options[i]}" == "$prev" ]]; then
+ track_mode=1
+ break
+ fi
+ done
+ fi
+ fi
+
+ # files are always eligible completion
+ _filedir
+ # track options are always available
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W '${track_options[@]}' -- $cur ) )
+ # general options are no more available after file or track option
+ if [ $track_mode -eq 0 ]; then
+ COMPREPLY=( "${COMPREPLY[@]}" \
+ $( compgen -W '${generic_options[@]}' -- $cur ) )
+ fi
+
+} &&
+complete -F _cdrecord $filenames cdrecord
+
+# mkisofs(8) completion
+#
+have mkisofs &&
+_mkisofs()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(o|abstract|biblio|check-session|copyright|log-file|root-info|prep-boot|*-list))
+ _filedir
+ return 0
+ ;;
+ -*-charset)
+ COMPREPLY=( $( mkisofs -input-charset help 2>&1 | \
+ tail +3 | grep "^$cur") )
+ return 0
+ ;;
+ -uid)
+ _uids
+ return 0
+ ;;
+ -gid)
+ _gids
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-abstract -A -allow-lowercase \
+ -allow-multidot -biblio -cache-inodes \
+ -no-cache-inodes -b -eltorito-alt-boot -B -G \
+ -hard-disk-boot -no-emul-boot -no-boot \
+ -boot-load-seg -boot-load-size \
+ -boot-info-table -C -c -check-oldname \
+ -check-session -copyright -d -D -dir-mode \
+ -dvd-video -f -file-mode -gid -gui \
+ -graft-points -hide -hide-list -hidden \
+ -hidden-list -hide-joliet -hide-joliet-list \
+ -hide-joliet-trans-tbl -hide-rr-moved \
+ -input-charset -output-charset -iso-level -J \
+ -joliet-long -jcharset -l -L -log-file -m \
+ -exclude-list -max-iso9660-filenames -M -N \
+ -new-dir-mode -nobak -no-bak -force-rr -no-rr \
+ -no-split-symlink-components \
+ -no-split-symlink-fields -o -pad -no-pad \
+ -path-list -P -p -print-size -quiet -R -r \
+ -relaxed-filenames -sort -split-output \
+ -stream-media-size -stream-file-name -sysid -T\
+ -table-name -ucs-level -udf -uid \
+ -use-fileversion -U -no-iso-translate -V \
+ -volset -volset-size -volset-seqno -v -x -z \
+ -hfs -apple -map -magic -hfs-creator \
+ -hfs-type -probe -no-desktop -mac-name \
+ -boot-hfs-file -part -auto -cluster-size \
+ -hide-hfs -hide-hfs-list -hfs-volid \
+ -icon-position -root-info -prep-boot \
+ -input-hfs-charset -output-hfs-charset \
+ -hfs-unlock -hfs-bless -hfs-parms --cap \
+ --netatalk --double --ethershare --ushare \
+ --exchange --sgi --xinet --macbin --single \
+ --dave --sfm --osx-double --osx-hfs' -- $cur ))
+ else
+ _filedir
+ fi
+
+} &&
+complete -F _mkisofs $filenames mkisofs
+
+# mc(1) completion
+#
+have mc &&
+_mc()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # -name value style option
+ case "$prev" in
+ -@(e|v|l|P))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ # --name=value style option
+ if [[ "$cur" == *=* ]]; then
+ prev=${cur/=*/}
+ cur=${cur/*=/}
+ case "$prev" in
+ --@(edit|view|ftplog|printwd))
+ _filedir
+ return 0
+ ;;
+ esac
+ fi
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-a --stickchars -b --nocolor -c \
+ --color -C --colors= -d --nomouse -e --edit= -f \
+ --datadir -k --resetsoft -l --ftplog= -P --printwd= \
+ -s --slow -t --termcap -u --nosubshell -U --subshell \
+ -v --view= -V --version -x --xterm -h --help' -- $cur ) )
+ else
+ _filedir -d
+ fi
+} &&
+complete -F _mc $filenames mc
+
+# yum(8) completion
+#
+have yum && {
+_yum()
+{
+ local cur prev special
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
+ if [[ ${COMP_WORDS[i]} == @(install|update|upgrade|remove|erase|deplist) ]]; then
+ special=${COMP_WORDS[i]}
+ fi
+ done
+
+ if [ -n "$special" ]; then
+ case $special in
+ install|deplist)
+ COMPREPLY=( $( compgen -W '$( yum -C list | cut -d" " -f1 )' -- $cur ) )
+ return 0
+ ;;
+ *)
+ _rpm_installed_packages
+ return 0
+ ;;
+ esac
+ fi
+
+ case $cur in
+ --*)
+ COMPREPLY=( $( compgen -W '--installroot --version --help --enablerepo --disablerepo --exclude --obsoletes --noplugins' -- $cur ) )
+ return 0
+ ;;
+ -*)
+ COMPREPLY=( $( compgen -W '-c -e -d -y -t -R -C -h' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ case $prev in
+ list)
+ COMPREPLY=( $( compgen -W 'all available updates installed extras obsoletes recent' -- $cur ) )
+ ;;
+ clean)
+ COMPREPLY=( $( compgen -W 'packages headers metadata cache dbcache all' -- $cur ) )
+ ;;
+ localinstall)
+ _filedir rpm
+ ;;
+ -c)
+ _filedir
+ ;;
+ --installroot)
+ _filedir -d
+ ;;
+ *)
+ COMPREPLY=( $( compgen -W 'install update check-update upgrade remove list \
+ search info provides clean groupinstall groupupdate \
+ grouplist deplist erase groupinfo groupremove \
+ localinstall localupdate makecache resolvedep \
+ shell whatprovides' -- $cur ) )
+ ;;
+ esac
+}
+complete -F _yum $filenames yum
+
+# yum-arch(8) completion
+#
+_yum_arch()
+{
+ local cur
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ case "$cur" in
+ -*)
+ COMPREPLY=( $( compgen -W '-d -v -vv -n -c -z -s -l -q' -- $cur ) )
+ ;;
+ *)
+ _filedir -d
+ ;;
+ esac
+
+ return 0
+
+}
+complete -F _yum_arch $filenames yum-arch
+}
+
+# ImageMagick completion
+#
+have convert && {
+_ImageMagick()
+{
+ local prev
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -channel)
+ COMPREPLY=( $( compgen -W 'Red Green Blue Opacity \
+ Matte Cyan Magenta Yellow Black' -- $cur ) )
+ return 0
+ ;;
+ -colormap)
+ COMPREPLY=( $( compgen -W 'shared private' -- $cur ) )
+ return 0
+ ;;
+ -colorspace)
+ COMPREPLY=( $( compgen -W 'GRAY OHTA RGB Transparent \
+ XYZ YCbCr YIQ YPbPr YUV CMYK' -- $cur ) )
+ return 0
+ ;;
+ -compose)
+ COMPREPLY=( $( compgen -W 'Over In Out Atop Xor Plus \
+ Minus Add Subtract Difference Multiply Bumpmap\
+ Copy CopyRed CopyGreen CopyBlue CopyOpacity' \
+ -- $cur ) )
+ return 0
+ ;;
+ -compress)
+ COMPREPLY=( $( compgen -W 'None BZip Fax Group4 JPEG \
+ Lossless LZW RLE Zip' -- $cur ) )
+ return 0
+ ;;
+ -dispose)
+ COMPREPLY=( $( compgen -W 'Undefined None Background \
+ Previous' -- $cur ) )
+ return 0
+ ;;
+ -encoding)
+ COMPREPLY=( $( compgen -W 'AdobeCustom AdobeExpert \
+ AdobeStandard AppleRoman BIG5 GB2312 Latin2 \
+ None SJIScode Symbol Unicode Wansung' -- $cur))
+ return 0
+ ;;
+ -endian)
+ COMPREPLY=( $( compgen -W 'MSB LSB' -- $cur ) )
+ return 0
+ ;;
+ -filter)
+ COMPREPLY=( $( compgen -W 'Point Box Triangle Hermite \
+ Hanning Hamming Blackman Gaussian Quadratic \
+ Cubic Catrom Mitchell Lanczos Bessel Sinc' \
+ -- $cur ) )
+ return 0
+ ;;
+ -format)
+ COMPREPLY=( $( convert -list format | \
+ awk '/ [r-][w-][+-] / {print $1}' | \
+ tr -d '*' | tr [:upper:] [:lower:] | \
+ grep "^$cur" ) )
+ return 0
+ ;;
+ -gravity)
+ COMPREPLY=( $( compgen -W 'Northwest North NorthEast \
+ West Center East SouthWest South SouthEast' \
+ -- $cur ) )
+ return 0
+ ;;
+ -intent)
+ COMPREPLY=( $( compgen -W 'Absolute Perceptual \
+ Relative Saturation' -- $cur ) )
+ return 0
+ ;;
+ -interlace)
+ COMPREPLY=( $( compgen -W 'None Line Plane Partition' \
+ -- $cur ) )
+ return 0
+ ;;
+ -limit)
+ COMPREPLY=( $( compgen -W 'Disk File Map Memory' \
+ -- $cur ) )
+ return 0
+ ;;
+ -list)
+ COMPREPLY=( $( compgen -W 'Delegate Format Magic \
+ Module Resource Type' -- $cur ) )
+ return 0
+ ;;
+ -map)
+ COMPREPLY=( $( compgen -W 'best default gray red \
+ green blue' -- $cur ) )
+ _filedir
+ return 0
+ ;;
+ -noise)
+ COMPREPLY=( $( compgen -W 'Uniform Gaussian \
+ Multiplicative \
+ Impulse Laplacian Poisson' -- $cur ) )
+ return 0
+ ;;
+ -preview)
+ COMPREPLY=( $( compgen -W 'Rotate Shear Roll Hue \
+ Saturation Brightness Gamma Spiff \
+ Dull Grayscale Quantize Despeckle \
+ ReduceNoise AddNoise Sharpen Blur \
+ Treshold EdgeDetect Spread Shade \
+ Raise Segment Solarize Swirl Implode \
+ Wave OilPaint CharcoalDrawing JPEG' \
+ -- $cur ) )
+ return 0
+ ;;
+ -@(mask|profile|texture|tile|write))
+ _filedir
+ return 0
+ ;;
+ -type)
+ COMPREPLY=( $( compgen -W 'Bilevel Grayscale Palette \
+ PaletteMatte TrueColor TrueColorMatte \
+ ColorSeparation ColorSeparationlMatte \
+ Optimize' -- $cur ) )
+ return 0
+ ;;
+ -units)
+ COMPREPLY=( $( compgen -W 'Undefined PixelsPerInch \
+ PixelsPerCentimeter' -- $cur ) )
+ return 0
+ ;;
+ -virtual-pixel)
+ COMPREPLY=( $( compgen -W 'Constant Edge mirror tile' \
+ -- $cur ) )
+ return 0
+ ;;
+ -visual)
+ COMPREPLY=( $( compgen -W 'StaticGray GrayScale \
+ StaticColor PseudoColor TrueColor \
+ DirectColor defaut visualid' -- $cur ))
+ return 0
+ ;;
+ esac
+}
+
+_convert()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _ImageMagick
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-adjoin -affine -antialias -append \
+ -authenticate -average -background -black-threshold \
+ -blue-primary -blur -border -bordercolor -channel \
+ -charcoal -chop -clip -coalesce -colorize -colors \
+ -colorspace -comment -compress -contrast -convolve \
+ -crop -cycle -debug -deconstruct -delay -density \
+ -depth -despeckle -display -dispose -dither -draw \
+ -edge -emboss -encoding -endian -enhance -equalize \
+ -extract -fill -filter -flatten -flip -flop -font \
+ -frame -fuzz -gamma -gaussian -geometry \
+ -green-primary -gravity -help -implode -intent \
+ -interlace -label -lat -level -limit -list -log -loop \
+ -map -mask -matte -median -modulate -monochrome \
+ -morph -mosaic -negate -noop -noise -normalize \
+ -opaque -ordered-dither -page -paint -ping -pointsize \
+ -preview -profile -quality -raise -random-threshold \
+ -region -raise -red-primary -render -resize -resample \
+ -roll -rotate -sample -sampling-factor -scale -scene \
+ -seed -segment -shade -sharpen -shave -shear -size \
+ -solarize -spread -stroke -strokewidth -swirl \
+ -texture -threshold -thumbnail -tile -transform \
+ -transparent -treedepth -trim -type -undercolor \
+ -units -unsharp -verbose -version -view \
+ -virtual-pixel -wave -white-point -white-threshold \
+ -write' -- $cur ) )
+ elif [[ "$cur" == +* ]]; then
+ COMPREPLY=( $( compgen -W '+adjoin +append +compress \
+ +contrast +debug +dither +endian +gamma +label +map \
+ +mask +matte +negate +noise +page +raise +render \
+ +write' -- $cur ) )
+ else
+ _filedir
+ fi
+}
+complete -F _convert $filenames convert
+
+_mogrify()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _ImageMagick
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-affine -antialias -authenticate \
+ -background -black-threshold -blue-primary -blur \
+ -border -bordercolor -channel -charcoal -chop \
+ -colorize -colors -colorspace -comment -compress \
+ -contrast -convolve -crop -cycle -debug -delay \
+ -density -depth -despeckle -display -dispose -dither \
+ -draw -edge -emboss -encoding -endian -enhance \
+ -equalize -extract -fill -filter -flip -flop -font \
+ -format -frame -fuzz -gamma -gaussian -geometry \
+ -green-primary -implode -interlace -help -label -lat \
+ -level -limit -list -log -loop -map -mask -matte \
+ -median -modulate -monochrome -negate -noop \
+ -normalize -opaque -page -paint -fill -ordered-dither \
+ -pointsize -profile -quality -raise -random-threshold \
+ -red-primary -region -resample -resize -roll -rotate \
+ -sample -sampling-factor -scale -scene -seed -segment \
+ -shade -sharpen -shear -size -solarize -spread \
+ -stroke -strokewidth -swirl -texture -threshold \
+ -thumbnail -tile -transform -transparent -treedepth \
+ -trim -type -undercolor -units -unsharp -verbose \
+ -version -view -virtual-pixel -wave -white-point \
+ -white-threshold' -- $cur ) )
+ elif [[ "$cur" == +* ]]; then
+ COMPREPLY=( $( compgen -W '+compress +contrast +debug +dither \
+ +endian +gamma +label +map +mask +matte +negate +page \
+ +raise' -- $cur ) )
+ else
+ _filedir
+ fi
+}
+complete -F _mogrify $filenames mogrify
+
+_display()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _ImageMagick
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-authenticate -backdrop -border \
+ -colormap -colors -colorspace -comment -compress \
+ -contrast -crop -debug -delay -density -depth \
+ -despeckle -display -dispose -dither -edge -endian \
+ -enhance -extract -filter -flip -flop -frame -gamma \
+ -geometry -help -immutable -interlace -label -limit \
+ -log -map -matte -monochrome -negate -noop -page \
+ -quality -raise -remote -roll -rotate -sample \
+ -sampling-factor -scene -segment -sharpen -size \
+ -texture -treedepth -trim -update -verbose -version \
+ -virtual-pixel -window -window_group -write' -- $cur))
+ elif [[ "$cur" == +* ]]; then
+ COMPREPLY=( $( compgen -W '+compress +contrast +debug +dither \
+ +endian +gamma +label +map +matte +negate +page \
+ +raise +write' -- $cur ) )
+ else
+ _filedir
+ fi
+}
+complete -F _display $filenames display
+
+_animate()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _ImageMagick
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-authenticate -backdrop -colormap \
+ -colors -colorspace -crop -debug -delay -density \
+ -depth -display -dither -extract -gamma -geometry \
+ -help -interlace -limit -log -matte -map -monochrome \
+ -noop -pause -remote -rotate -sampling-factor -scene \
+ -size -treedepth -trim -verbose -version -visual \
+ -virtual-pixel -window' -- $cur ) )
+ elif [[ "$cur" == +* ]]; then
+ COMPREPLY=( $( compgen -W '+debug +dither +gamma +map +matte' -- $cur ) )
+ else
+ _filedir
+ fi
+}
+complete -F _animate $filenames animate
+
+_identify()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _ImageMagick
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-authenticate -debug -density \
+ -depth -extract -format -help -interlace -limit -list \
+ -log -size -sampling-factor -verbose -version \
+ -virtual-pixel' -- $cur ) )
+ elif [[ "$cur" == +* ]]; then
+ COMPREPLY=( $( compgen -W '+debug ' -- $cur ) )
+ else
+ _filedir
+ fi
+}
+complete -F _identify $filenames identify
+
+_montage()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _ImageMagick
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-adjoin -affine -authenticate \
+ -blue-primary -blur -colors -colorspace -comment \
+ -compose -compress -crop -debug -density -depth \
+ -display -dispose -dither -draw -encoding -endian \
+ -extract -fill -filter -flip -flop -frame -gamma \
+ -geometry -gravity -green-primary -interlace -help \
+ -label -limit -log -matte -mode -monochrome -noop \
+ -page -pointsize -quality -red-primary -resize \
+ -rotate -sampling-factor -scene -shadow -size \
+ -stroke -texture -thumbnail -tile -transform \
+ -transparent -treedepth -trim -type -verbose \
+ -version -virtual-pixel -white-point' -- $cur ) )
+ elif [[ "$cur" == +* ]]; then
+ COMPREPLY=( $( compgen -W '+adjoin +compress +debug +dither \
+ +endian +gamma +label +matte +page' -- $cur ) )
+ else
+ _filedir
+ fi
+}
+complete -F _montage $filenames montage
+
+_composite()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _ImageMagick
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-affine -authenticate \
+ -blue-primary -colors -colorspace -comment -compose \
+ -compress -debug -density -depth -displace -display \
+ -dispose -dissolve -dither -encoding -endian -extract \
+ -filter -font -geometry -gravity -green-primary -help \
+ -interlace -label -limit -log -matte -monochrome \
+ -negate -page -profile -quality -red-primary -rotate \
+ -resize -sampling-factor -scene -sharpen -size \
+ -stegano -stereo -thumbnail -tile -transform \
+ -treedepth -type -units -unsharp -verbose -version \
+ -virtual-pixel -watermark -white-point -write' \
+ -- $cur ) )
+ elif [[ "$cur" == +* ]]; then
+ COMPREPLY=( $( compgen -W '+compress +debug +dither +endian +label \
+ +matte +negate +page +write' -- $cur ) )
+ else
+ _filedir
+ fi
+}
+complete -F _composite $filenames composite
+}
+
+# dd(1) completion
+#
+have dd &&
+_dd()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ case "$cur" in
+ if=*|of=*)
+ cur=${cur#*=}
+ _filedir
+ return 0
+ ;;
+ conv=*)
+ cur=${cur#*=}
+ COMPREPLY=( $( compgen -W 'ascii ebcdic ibm block unblock \
+ lcase notrunc ucase swab noerror sync' \
+ -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ _expand || return 0
+
+ COMPREPLY=( $( compgen -W '--help --version' -- $cur ) \
+ $( compgen -W 'bs cbs conv count ibs if obs of seek skip'\
+ -S '=' -- $cur ) )
+} &&
+complete -F _dd $nospace $filenames dd
+
+# CUPS cancel(1) completion
+#
+have cancel &&
+_cancel()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ COMPREPLY=( $( lpstat | cut -d' ' -f1 | grep "^$cur" ) )
+} &&
+complete -F _cancel $filenames cancel
+
+# aspell(1) completion
+#
+have aspell && {
+_aspell_dictionary()
+{
+ local datadir
+ datadir=/usr/lib/aspell
+ COMPREPLY=( $( command ls $datadir/*.@(multi|alias) ) )
+ COMPREPLY=( ${COMPREPLY[@]%.@(multi|alias)} )
+ COMPREPLY=( $( compgen -W '${COMPREPLY[@]#$datadir/}' -- $cur ) )
+}
+
+_aspell()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # --name value style option
+ case "$prev" in
+ @(-c|-p|check))
+ _filedir
+ return 0
+ ;;
+ @(dump|create|merge))
+ COMPREPLY=( $( compgen -W 'master personal repl' -- $cur ) )
+ return 0
+ ;;
+ -d)
+ _aspell_dictionary
+ return 0
+ ;;
+ esac
+
+ # --name=value style option
+ if [[ "$cur" == *=* ]]; then
+ prev=${cur/=*/}
+ cur=${cur/*=/}
+ case "$prev" in
+ --@(conf|personal|repl|per-conf))
+ _filedir
+ return 0
+ ;;
+ --@(conf-dir|data-dir|dict-dir|home-dir|local-data-dir|prefix))
+ _filedir -d
+ return 0
+ ;;
+ --master)
+ _aspell_dictionary
+ return 0
+ ;;
+ --mode)
+ COMPREPLY=( $( compgen -W 'none url email sgml tex' -- $cur ) )
+ return 0
+ ;;
+ --sug-mode)
+ COMPREPLY=( $( compgen -W 'ultra fast normal bad-speller' -- $cur ) )
+ return 0
+ ;;
+ --keymapping)
+ COMPREPLY=( $( compgen -W 'aspell ispell' -- $cur ) )
+ return 0
+ ;;
+ esac
+ fi
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--conf= --conf-dir= --data-dir= --dict-dir= \
+ --encoding= --add-filter= --rem-filter= --mode= -e \
+ -H -t --add-extra-dicts= --rem-extra-dicts= \
+ --home-dir= -W --ignore= --ignore-accents \
+ --dont-ignore-accents --ignore-case --dont-ignore-case \
+ --ignore-repl --dont-ignore-repl --jargon= --keyboard= \
+ --lang= --language-tag= --local-data-dir= -d --master= \
+ --module= --add-module-search-order= \
+ --rem-module-search-order= --per-conf= -p --personal= \
+ --prefix= --repl= -C -B --run-together --dont-run-together \
+ --run-together-limit= --run-together-min= --save-repl \
+ --dont-save-repl --set-prefix --dont-set-prefix --size= \
+ --spelling= --strip-accents --dont-strip-accents \
+ --sug-mode= --add-word-list-path= --rem-word-list-path= \
+ -b -x --backup -b|-x --dont-backup --reverse --dont-reverse \
+ --time --dont-time --keymapping= --add-email-quote= \
+ --rem-email-quote= --email-margin= --add-tex-command= \
+ --rem-tex-command= --tex-check-comments \
+ --dont-tex-check-comments --add-tex-extension= \
+ --rem-tex-extension= --add-sgml-check= --rem-sgml-check= \
+ --add-sgml-extension= --rem-sgml-extension=' -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -W '-? help -c check -a pipe -l list \
+ config config soundslike filter -v version dump \
+ create merge' -- $cur ) )
+ fi
+
+}
+complete -F _aspell $filenames aspell
+}
+
+# xmms(1) completion
+#
+have xmms &&
+_xmms()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-h --help -r --rew -p --play \
+ -u --pause -s --stop -t --play-pause -f --fwd -e \
+ --enqueue -m --show-main-window -i --sm-client-id \
+ -v --version' -- $cur ) )
+ else
+ _filedir '@(mp[23]|MP[23]|ogg|OGG|wav|WAV|pls|m3u|xm|mod|s[3t]m|it|mtm|ult|flac)'
+
+ fi
+
+} &&
+complete -F _xmms $filenames xmms
+
+# info(1) completion
+#
+have info &&
+_info()
+{
+ local cur infopath UNAME
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _expand || return 0
+
+ # default completion if parameter contains /
+ if [[ "$cur" == */* ]]; then
+ _filedir
+ return 0
+ fi
+
+ infopath='/usr/share/info'
+
+ if [ "${INFOPATH: -1:1}" == ':' ]; then
+ infopath=${INFOPATH}${infopath}
+ elif [ ${INFOPATH:+set} ]; then
+ infopath=$INFOPATH
+ fi
+
+ infopath=$infopath:
+ if [ -n "$cur" ]; then
+ infopath="${infopath//://$cur* }"
+ else
+ infopath="${infopath//:// }"
+ fi
+
+ # redirect stderr for when path doesn't exist
+ COMPREPLY=( $( eval command ls "$infopath" 2>/dev/null ) )
+ # weed out directory path names and paths to info pages
+ COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
+ # weed out info dir file
+ for (( i=0 ; i < ${#COMPREPLY[@]} ; ++i )); do
+ if [ "${COMPREPLY[$i]}" == 'dir' ]; then
+ unset COMPREPLY[$i];
+ fi;
+ done
+ # strip suffix from info pages
+ COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
+ COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
+
+ return 0
+} &&
+complete -F _info $filenames info
+
+# dhclient(1) completion
+#
+have dhclient && _dhclient()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(cf|lf|pf|sf))
+ _filedir
+ return 0
+ ;;
+ -s)
+ _known_hosts
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-p -d -q -1 -r -lf -pf \
+ -cf -sf -s -g -n -nw -w' -- $cur ) )
+ else
+ _available_interfaces
+ fi
+} &&
+complete -F _dhclient dhclient
+
+# lvm(8) completion
+#
+have lvm && {
+_volumegroups()
+{
+ COMPREPLY=( $(compgen -W "$( vgscan 2>/dev/null | \
+ sed -n -e 's|.*Found.*"\(.*\)".*$|\1|p' )" -- $cur ) )
+}
+
+_physicalvolumes()
+{
+ COMPREPLY=( $(compgen -W "$( pvscan 2>/dev/null | \
+ sed -n -e 's|^.*PV \(.*\) VG.*$|\1|p' )" -- $cur ) )
+}
+
+_logicalvolumes()
+{
+ COMPREPLY=( $(compgen -W "$( lvscan 2>/dev/null | \
+ sed -n -e "s|^.*'\(.*\)'.*$|\1|p" )" -- $cur ) )
+}
+
+_units()
+{
+ COMPREPLY=( $( compgen -W 'h s b k m g t H K M G T' -- $cur ) )
+}
+
+_sizes()
+{
+ COMPREPLY=( $( compgen -W 'k K m M g G t T' -- $cur ) )
+}
+
+_args()
+{
+ args=0
+ if [[ "${COMP_WORDS[0]}" == lvm ]]; then
+ offset=2
+ else
+ offset=1
+ fi
+ for (( i=$offset; i < COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" != -* ]]; then
+ args=$(($args + 1))
+ fi
+ done
+}
+
+_lvmdiskscan()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-d --debug -h -? --help -l \
+ --lvmpartition -v --verbose --version' -- $cur ) )
+ fi
+}
+complete -F _lvmdiskscan lvmdiskscan
+
+_pvscan()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-d --debug -e \
+ --exported -n --novolumegroup -h -? \
+ --help --ignorelockingfailure -P \
+ --partial -s --short -u --uuid -v \
+ --verbose --version' -- $cur ) )
+ fi
+}
+complete -F _pvscan pvscan
+
+_pvs()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(o|O|-options|-sort))
+ COMPREPLY=( $( compgen -W 'pv_fmt pv_uuid \
+ pv_size pv_free pv_used pv_name \
+ pv_attr pv_pe_count \
+ pv_pe_alloc_count' -- $cur ) )
+ return 0
+ ;;
+ --units)
+ _units
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--aligned -a --all -d --debug \
+ -h -? --help --ignorelockingfailure --noheadings \
+ --nosuffix -o --options -O --sort \
+ --separator --unbuffered --units \
+ -v --verbose --version' -- $cur ) )
+ else
+ _physicalvolumes
+ fi
+}
+complete -F _pvs pvs
+
+_pvdisplay()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ --units)
+ _units
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \
+ -v --verbose -d --debug -h --help --version' -- $cur ) )
+ else
+ _physicalvolumes
+ fi
+}
+complete -F _pvdisplay pvdisplay
+
+_pvchange()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|x|-autobackup|--allocatable))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-a --all -A --autobackup \
+ -d --debug -h --help -t --test -u --uuid -x \
+ --allocatable -v --verbose --addtag --deltag \
+ --version' -- $cur ) )
+ else
+ _physicalvolumes
+ fi
+}
+complete -F _pvchange pvchange
+
+_pvcreate()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ --restorefile)
+ _filedir
+ return 0
+ ;;
+ -@(M|-metadatatype))
+ COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
+ return 0
+ ;;
+ --metadatacopies)
+ COMPREPLY=( $( compgen -W '0 1 2' -- $cur ) )
+ return 0
+ ;;
+ --@(metadatasize|setphysicalvolumesize))
+ _sizes
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--restorefile -d --debug -f \
+ --force -h -? --help --labelsector -M --metadatatype \
+ --metadatacopies --metadatasize \
+ --setphysicalvolumesize -t --test -u --uuid uuid -v \
+ --verbose -y --yes --version' -- $cur ) )
+ else
+ _physicalvolumes
+ fi
+}
+complete -F _pvcreate pvcreate
+
+_pvmove()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ -@(n|-name))
+ _logicalvolumes
+ return 0
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--abort -A --autobackup \
+ -b --background -d --debug -f --force -h -? \
+ --help -i --interval -t --test -v --verbose \
+ --version -n --name' -- $cur ) )
+ else
+ _physicalvolumes
+ fi
+}
+complete -F _pvmove pvmove
+
+_pvremove()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-d --debug -f --force -h -? \
+ --help -y --yes -t --test -v --verbose \
+ --version' -- $cur ) )
+ else
+ _physicalvolumes
+ fi
+}
+complete -F _pvremove pvremove
+
+_vgscan()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-d --debug -h --help \
+ --ignorelockingfailure --mknodes -P \
+ --partial -v --verbose --version' -- $cur ) )
+ fi
+}
+complete -F _vgscan vgscan
+
+_vgs()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(o|O|-options|-sort))
+ COMPREPLY=( $( compgen -W 'vg_fmt vg_uuid vg_name \
+ vg_attr vg_size vg_free vg_sysid \
+ vg_extent_size vg_extent_count vg_free_count \
+ max_lv max_pv pv_count lv_count snap_count \
+ vg_seqno' -- $cur ) )
+ return 0
+ ;;
+ --units)
+ _units
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--aligned -d --debug \
+ -h --help --ignorelockingfailure --noheadings \
+ --nosuffix -o --options -O --sort -P --partial \
+ --separator --unbuffered --units \
+ -v --verbose --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgs vgs
+
+_vgdisplay()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ --units)
+ _units
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \
+ -P --partial -A --activevolumegroups -v --verbose \
+ -d --debug -h --help --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgdisplay vgdisplay
+
+_vgchange()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(a|A|x|-available|-autobackup|-resizeable))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup --alloc -P \
+ --partial -d --debug -h --help --ignorelockingfailure \
+ -t --test -u --uuid -v --verbose --version -a \
+ --available -x --resizeable -l --logicalvolume \
+ --addtag --deltag' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgchange vgchange
+
+_vgcreate()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ -@(M|-metadatatype))
+ COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
+ return 0
+ ;;
+ -@(s|-physicalextentsize))
+ _sizes
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup --addtag \
+ --alloc -d --debug -h --help -l --maxlogicalvolumes \
+ -M --metadatatype -p --maxphysicalvolumes -s \
+ --physicalextentsize -t --test -v --verbose \
+ --version' -- $cur ) )
+ else
+ _args
+ if [ $args -eq 0 ]; then
+ _volumegroups
+ else
+ _physicalvolumes
+ fi
+ fi
+}
+complete -F _vgcreate vgcreate
+
+_vgremove()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-d --debug -h --help -t --test \
+ -v --verbose --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgremove vgremove
+
+_vgrename()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \
+ -? --help -t --test -v --verbose --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgrename vgrename
+
+_vgreduce()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-a --all -A --autobackup -d \
+ --debug -h --help --removemissing -t --test -v \
+ --verbose --version' -- $cur ) )
+
+ else
+ _args
+ if [ $args -eq 0 ]; then
+ _volumegroups
+ else
+ _physicalvolumes
+ fi
+ fi
+}
+complete -F _vgreduce vgreduce
+
+_vgextend()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ -@(L|-size))
+ _sizes
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \
+ -? --help -t --test -v --verbose --version' -- $cur ) )
+ else
+ _args
+ if [ $args -eq 0 ]; then
+ _volumegroups
+ else
+ _physicalvolumes
+ fi
+ fi
+}
+complete -F _vgextend vgextend
+
+_vgport()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-a --all -d --debug -h \
+ -? --help -v --verbose --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgport vgimport vgexport
+
+_vgck()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-d --debug -h \
+ -? --help -v --verbose --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgck vgck
+
+_vgconvert()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(M|-metadatatype))
+ COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
+ return 0
+ ;;
+ --metadatacopies)
+ COMPREPLY=( $( compgen -W '0 1 2' -- $cur ) )
+ return 0
+ ;;
+ --metadatasize)
+ _sizes
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-d --debug -h --help --labelsector \
+ -M --metadatatype --metadatacopies --metadatasize \
+ -t --test -v --verbose --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgconvert vgconvert
+
+_vgcfgbackup()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(f|-file))
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-d --debug -f --file -h --help \
+ --ignorelockingfailure -P --partial -v --verbose \
+ --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgcfgbackup vgcfgbackup
+
+_vgcfgrestore()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(f|-file))
+ _filedir
+ return 0
+ ;;
+ -@(M|-metadatatype))
+ COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
+ return 0
+ ;;
+ -@(n|-name))
+ _volumegroups
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-d --debug -f --file -l --list \
+ -h --help -M --Metadatatype -n --name -t --test \
+ -v --verbose --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgcfgrestore vgcfgrestore
+
+_vgmerge()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup -d --debug \
+ -h --help -l --list -t --test -v --verbose \
+ --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgmerge vgmerge
+
+_vgsplit()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ -@(M|-metadatatype))
+ COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup -d --debug \
+ -h --help -l --list -M --metadatatype -t --test \
+ -v --verbose --version' -- $cur ) )
+ else
+ _args
+ if [ $args -eq 0 -o $args -eq 1 ]; then
+ _volumegroups
+ else
+ _physicalvolumes
+ fi
+ fi
+}
+complete -F _vgsplit vgsplit
+
+_vgmknodes()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-d --debug -h --help -v --verbose \
+ --version' -- $cur ) )
+ else
+ _volumegroups
+ fi
+}
+complete -F _vgmknodes vgmknodes
+
+_lvscan()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-b --blockdevice -d --debug \
+ -h -? --help --ignorelockingfailure -P \
+ --partial -v --verbose --version' -- $cur ) )
+ fi
+}
+complete -F _lvscan lvscan
+
+_lvs()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(o|O|-options|-sort))
+ COMPREPLY=( $( compgen -W 'lv_uuid lv_name \
+ lv_attr lv_minor lv_size seg_count \
+ origin snap_percent segtype stripes \
+ stripesize chunksize seg_start \
+ seg_size' -- $cur ) )
+ return 0
+ ;;
+ --units)
+ _units
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--aligned -d --debug \
+ -h --help --ignorelockingfailure --noheadings \
+ --nosuffix -o --options -O --sort -P --partial \
+ --segments --separator --unbuffered --units \
+ -v --verbose --version' -- $cur ) )
+ else
+ _logicalvolumes
+ fi
+}
+complete -F _lvs lvs
+
+_lvdisplay()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ --units)
+ _units
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \
+ -P --partial -m --maps -v --verbose -d --debug -h \
+ --help --version' -- $cur ) )
+ else
+ _logicalvolumes
+ fi
+}
+complete -F _lvdisplay lvdisplay
+
+_lvchange()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(a|A|C|M|-available|-autobackup|-continguous|-persistent))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ -@(p|-permission))
+ COMPREPLY=( $( compgen -W 'r rw' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup -a --available \
+ --addtag --alloc -C --contiguous -d --debug --deltag \
+ -f --force -h --help --ignorelockingfailure -M \
+ --persistent --major major --minor minor -P --partial \
+ -p --permission -r --readahead --refresh -t --test \
+ -v --verbose --version' -- $cur ) )
+ else
+ _logicalvolumes
+ fi
+}
+complete -F _lvchange lvchange
+
+_lvcreate()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|C|M|Z|-autobackup|-continguous|-persistent|-zero))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ -@(L|-size))
+ _sizes
+ return 0
+ ;;
+ -@(p|-permission))
+ COMPREPLY=( $( compgen -W 'r rw' -- $cur ) )
+ return 0
+ ;;
+ -@(n|-name))
+ _logicalvolumes
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup --addtag --alloc \
+ -C --contiguous -d --debug -h -? --help -i --stripes \
+ -I --stripesize -l --extents -L --size -M --persistent \
+ --major --minor -n --name -p --permission -r \
+ --readahead -t --test --type -v --verbose -Z --zero \
+ --version' -- $cur ) )
+ else
+ _args
+ if [ $args -eq 0 ]; then
+ _volumegroups
+ else
+ _physicalvolumes
+ fi
+ fi
+}
+complete -F _lvcreate lvcreate
+
+_lvremove()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -f \
+ --force -h -? --help -t --test -v --verbose \
+ --version' -- $cur ) )
+ else
+ _logicalvolumes
+ fi
+}
+complete -F _lvremove lvremove
+
+_lvrename()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \
+ -? --help -t --test -v --verbose --version' -- $cur ) )
+ else
+ _logicalvolumes
+ fi
+}
+complete -F _lvrename lvrename
+
+_lvreduce()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ -@(L|-size))
+ _sizes
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup -d \
+ --debug -f --force -h --help -l --extents \
+ -L --size -n --nofsck -r --resizefs -t --test \
+ -v --verbose --version' -- $cur ) )
+ else
+ _logicalvolumes
+ fi
+}
+complete -F _lvreduce lvreduce
+
+_lvresize()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ -@(L|-size))
+ _sizes
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup --alloc -d \
+ --debug -h --help -i --stripes -I --stripesize \
+ -l --extents -L --size -n --nofsck -r --resizefs \
+ -t --test --type -v --verbose --version' -- $cur ) )
+ else
+ _args
+ if [ $args -eq 0 ]; then
+ _logicalvolumes
+ else
+ _physicalvolumes
+ fi
+ fi
+}
+complete -F _lvresize lvresize
+
+_lvextend()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(A|-autobackup))
+ COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
+ return 0
+ ;;
+ -@(L|-size))
+ _sizes
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A --autobackup --alloc -d \
+ --debug -h --help -i --stripes -I --stripesize \
+ -l --extents -L --size -n --nofsck -r --resizefs \
+ -t --test --type -v --verbose --version' -- $cur ) )
+ else
+ _args
+ if [ $args -eq 0 ]; then
+ _logicalvolumes
+ else
+ _physicalvolumes
+ fi
+ fi
+}
+complete -F _lvextend lvextend
+
+_lvm()
+{
+ local prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $( compgen -W 'dumpconfig help lvchange \
+ lvcreate lvdisplay lvextend lvmchange \
+ lvmdiskscan lvmsadc lvmsar lvreduce \
+ lvremove lvrename lvresize lvs lvscan \
+ pvchange pvcreate pvdata pvdisplay pvmove \
+ pvremove pvresize pvs pvscan vgcfgbackup \
+ vgcfgrestore vgchange vgck vgconvert \
+ vgcreate vgdisplay vgexport vgextend \
+ vgimport vgmerge vgmknodes vgreduce \
+ vgremove vgrename vgs vgscan vgsplit \
+ version' -- $cur ) )
+ else
+ case ${COMP_WORDS[1]} in
+ pvchange)
+ _pvchange
+ ;;
+ pvcreate)
+ _pvcreate
+ ;;
+ pvdisplay)
+ _pvdisplay
+ ;;
+ pvmove)
+ _pvmove
+ ;;
+ pvremove)
+ _pvremove
+ ;;
+ pvresize)
+ _pvresize
+ ;;
+ pvs)
+ _pvs
+ ;;
+ pvscan)
+ _pvscan
+ ;;
+ vgcfgbackup)
+ _vgcfgbackup
+ ;;
+ vgcfgrestore)
+ _vgcfgrestore
+ ;;
+ vgchange)
+ _vgchange
+ ;;
+ vgck)
+ _vgck
+ ;;
+ vgconvert)
+ _vgconvert
+ ;;
+ vgcreate)
+ _vgcreate
+ ;;
+ vgdisplay)
+ _vgdisplay
+ ;;
+ vgexport)
+ _vgexport
+ ;;
+ vgextend)
+ _vgextend
+ ;;
+ vgimport)
+ _vgimport
+ ;;
+ vgmerge)
+ _vgmerge
+ ;;
+ vgmknodes)
+ _vgmknodes
+ ;;
+ vgreduce)
+ _vgreduce
+ ;;
+ vgremove)
+ _vgremove
+ ;;
+ vgrename)
+ _vgrename
+ ;;
+ vgs)
+ _vgs
+ ;;
+ vgscan)
+ _vgscan
+ ;;
+ vgsplit)
+ _vgsplit
+ ;;
+ lvchange)
+ _lvchange
+ ;;
+ lvcreate)
+ _lvcreate
+ ;;
+ lvdisplay)
+ _lvdisplay
+ ;;
+ lvextend)
+ _lvextend
+ ;;
+ lvreduce)
+ _lvreduce
+ ;;
+ lvremove)
+ _lvremove
+ ;;
+ lvrename)
+ _lvrename
+ ;;
+ lvresize)
+ _lvresize
+ ;;
+ lvs)
+ _lvs
+ ;;
+ lvscan)
+ _lvscan
+ ;;
+ esac
+ fi
+}
+complete -F _lvm lvm
+}
+
+# mkinitrd(8) completion
+#
+have mkinitrd &&
+_mkinitrd()
+{
+ local cur args
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # --name value style option
+ case "$prev" in
+ --preload)
+ _modules
+ return 0
+ ;;
+ esac
+
+ # --name=value style option
+ if [[ "$cur" == *=* ]]; then
+ prev=${cur/=*/}
+ cur=${cur/*=/}
+ case "$prev" in
+ --@(with|builtin))
+ _modules
+ return 0
+ ;;
+ --@(fstab|dsdt))
+ _filedir
+ return 0
+ ;;
+ --tmpdir)
+ _filedir -d
+ return 0
+ ;;
+ esac
+ fi
+
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--version -v -f --preload \
+ --with= --omit-scsi-modules --omit-raid-modules \
+ --images-version --fstab= --nocompress --builtin= \
+ --nopivot --noudev --allow-missing --tmpdir= \
+ --initrdfs= --dsdt= --lvm-version= --froce-usb' \
+ -- $cur ) )
+ else
+ _count_args
+
+ case $args in
+ 1)
+ _filedir
+ ;;
+ 2)
+ COMPREPLY=( $( command ls /lib/modules | grep "^$cur" ) )
+ ;;
+ esac
+ fi
+
+} &&
+complete -F _mkinitrd mkinitrd
+
+# pkgconfig(1) completion
+#
+have pkg-config &&
+_pkg_config()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ # return list of available options
+ COMPREPLY=( $( compgen -W '-version --modversion \
+ --atleast-pkgconfig-version= --libs --libs-only-l \
+ --libs-only-other --libs-only-L --cflags \
+ --cflags-only-I --cflags-only-other --variable= \
+ --define-variable= --exists --uninstalled \
+ --atleast-version= --exact-version= --max-version= \
+ --list-all --debug --print-errors --silence-errors \
+ --errors-to-stdout -? --help --usage' -- $cur))
+ else
+ COMPREPLY=( $( pkg-config --list-all 2>/dev/null | \
+ awk '{print $1}' | grep "^$cur" ) )
+ fi
+} &&
+complete -F _pkg_config pkg-config
+
+
+# cpio(1) completion
+#
+have cpio && {
+_cpio_format()
+{
+ COMPREPLY=( $( compgen -W 'bin odc newc crc tar ustar hpbin hpodc' -- $cur ) )
+}
+
+_cpio()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # --name value style option
+ case $prev in
+ -H)
+ _cpio_format
+ return 0
+ ;;
+ -@(E|F|I))
+ _filedir
+ return 0
+ ;;
+ -R)
+ _usergroup
+ return 0
+ ;;
+ esac
+
+ # --name=value style option
+ if [[ "$cur" == *=* ]]; then
+ prev=${cur/=*/}
+ cur=${cur/*=/}
+ case $prev in
+ --format)
+ _cpio_format
+ return 0
+ ;;
+ --@(file|pattern-file))
+ _filedir
+ return 0
+ ;;
+ --owner)
+ _usergroup
+ return 0
+ ;;
+ --rsh-command)
+ COMPREPLY=( $( compgen -c -- $cur ) )
+ return 0
+ ;;
+ esac
+ fi
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $( compgen -W '-o --create -i --extract -p --pass-through' -- $cur) )
+ else
+ case ${COMP_WORDS[1]} in
+ -@(o|-create))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-0 -a -c -v -A -B\
+ -L -V -C -H -M -O -F --file= --format=\
+ --message= --null --reset-access-time\
+ --verbose --dot --append --block-size=\
+ --dereference --io-size= --quiet\
+ --force-local --rsh-command= --help\
+ --version' -- $cur ) )
+ fi
+ ;;
+ -@(i|-extract))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-b -c -d -f -m -n -r\
+ -t -s -u -v -B -S -V -C -E -H -M -R -I\
+ -F --file= --make-directories\
+ --nonmatching\
+ --preserve-modification-time\
+ --numeric-uid-gid --rename -t --list\
+ --swap-bytes --swap --dot\
+ --unconditional --verbose --block-size=\
+ --swap-halfwords --io-size=\
+ --pattern-file= --format= --owner=\
+ --no-preserve-owner --message=\
+ --force-local --no-absolute-filenames\
+ --sparse --only-verify-crc --quiet\
+ --rsh-command= --help\
+ --version' -- $cur ) )
+ fi
+ ;;
+ -@(p|-pass-through))
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-0 -a -d -l -m -u -v\
+ -L -V -R --null --reset-access-time\
+ --make-directories --link --quiet\
+ --preserve-modification-time\
+ --unconditional --verbose --dot\
+ --dereference --owner=\
+ --no-preserve-owner --sparse --help\
+ --version' -- $cur ) )
+ else
+ _filedir -d
+ fi
+ ;;
+ esac
+ fi
+}
+complete -F _cpio cpio
+}
+
+# id(1) completion
+#
+have id &&
+_id()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-a -g --group -G --groups -n --name\
+ -r --real -u --user --help --version' -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -u $cur ) )
+ fi
+} &&
+complete -F _id id
+
+# getent(1) completion
+#
+have getent &&
+_getent()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case $prev in
+ passwd)
+ COMPREPLY=( $( compgen -u $cur ) )
+ return 0
+ ;;
+ group)
+ COMPREPLY=( $( compgen -g $cur ) )
+ return 0
+ ;;
+ services)
+ COMPREPLY=( $( compgen -s $cur ) )
+ return 0
+ ;;
+ hosts)
+ COMPREPLY=( $( compgen -A hostname $cur ) )
+ return 0
+ ;;
+ protocols)
+ COMPREPLY=( $( getent protocols | awk '{print $1}' | grep "^$cur" ) )
+ return 0
+ ;;
+ networks)
+ COMPREPLY=( $( getent networks | awk '{print $1}' | grep "^$cur" ) )
+ return 0
+ ;;
+ esac
+
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $( compgen -W 'passwd group hosts services protocols networks' -- $cur ) )
+ fi
+} &&
+complete -F _getent getent
+
+# ntpdate(1) completion
+#
+have ntpdate &&
+_ntpdate()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case $prev in
+ -k)
+ _filedir
+ return 0
+ ;;
+ -U)
+ COMPREPLY=( $( compgen -u $cur ) )
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-4 -6 -b -B -d -Q -q -s -u -v -a\
+ -e -k -p -o -r -t' -- $cur ) )
+ else
+ _known_hosts
+ fi
+} &&
+complete -F _ntpdate ntpdate
+
+# smartctl(8) completion
+#
+have smartctl && {
+_smartctl_quietmode()
+{
+ COMPREPLY=( $( compgen -W 'errorsonly silent' -- $cur ) )
+}
+_smartctl_device()
+{
+ COMPREPLY=( $( compgen -W 'ata scsi 3ware' -- $cur ) )
+}
+_smartctl_tolerance()
+{
+ COMPREPLY=( $( compgen -W 'warn exit ignore' -- $cur ) )
+}
+_smartctl_badsum()
+{
+ COMPREPLY=( $( compgen -W 'normal conservative permissive verypermissive' -- $cur ) )
+}
+_smartctl_report()
+{
+ COMPREPLY=( $( compgen -W 'ioctl ataioctl scsiioctl' -- $cur ) )
+}
+_smartctl_feature()
+{
+ COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
+}
+_smartctl_log()
+{
+ COMPREPLY=( $( compgen -W 'error selftest selective directory' -- $cur ) )
+}
+_smartctl_vendorattribute()
+{
+ COMPREPLY=( $( compgen -W 'help 9,minutes 9,seconds 9,halfminutes \
+ 9,temp 192,emergencyretractcyclect 193,loadunload \
+ 194,10xCelsius 194,unknown 198,offlinescanuncsectorct \
+ 200,writeerrorcount 201,detectedtacount 220,temp' -- $cur ) )
+}
+_smartctl_firmwarebug()
+{
+ COMPREPLY=( $( compgen -W 'none samsung samsung2' -- $cur ) )
+}
+_smartctl_presets()
+{
+ COMPREPLY=( $( compgen -W 'use ignore show showall' -- $cur ) )
+}
+_smartctl_test()
+{
+ COMPREPLY=( $( compgen -W 'offline short long conveyance select afterselect,on afterselect,off pending' -- $cur ) )
+}
+
+_smartctl()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # --name value style option
+ case "$prev" in
+ -q)
+ _smartctl_quietmode
+ ;;
+ -d)
+ _smartctl_device
+ return 0
+ ;;
+ -t)
+ _smartctl_tolerance
+ return 0
+ ;;
+ -b)
+ _smartctl_badsum
+ return 0
+ ;;
+ -r)
+ _smartctl_report
+ return 0
+ ;;
+ -s)
+ _smartctl_feature
+ return 0
+ ;;
+ -o)
+ _smartctl_feature
+ return 0
+ ;;
+ -S)
+ _smartctl_feature
+ return 0
+ ;;
+ -l)
+ _smartctl_log
+ return 0
+ ;;
+ -v)
+ _smartctl_vendorattribute
+ return 0
+ ;;
+ -F)
+ _smartctl_firmwarebug
+ return 0
+ ;;
+ -P)
+ _smartctl_presets
+ return 0
+ ;;
+ -t)
+ _smartctl_test
+ return 0
+ ;;
+ esac
+
+ # --name=value style option
+ if [[ "$cur" == *=* ]]; then
+ prev=${cur/=*/}
+ cur=${cur/*=/}
+ case "$prev" in
+ --quietmode)
+ _smartctl_quietmode
+ return 0
+ ;;
+ --device)
+ _smartctl_device
+ return 0
+ ;;
+ --tolerance)
+ _smartctl_tolerance
+ return 0
+ ;;
+ --badsum)
+ _smartctl_badsum
+ return 0
+ ;;
+ --report)
+ _smartctl_report
+ return 0
+ ;;
+ --smart)
+ _smartctl_feature
+ return 0
+ ;;
+ --offlineauto)
+ _smartctl_feature
+ return 0
+ ;;
+ --saveauto)
+ _smartctl_feature
+ return 0
+ ;;
+ --log)
+ _smartctl_log
+ return 0
+ ;;
+ --vendorattribute)
+ _smartctl_vendorattribute
+ return 0
+ ;;
+ --firmwarebug)
+ _smartctl_firmwarebug
+ return 0
+ ;;
+ --presets)
+ _smartctl_presets
+ return 0
+ ;;
+ --test)
+ _smartctl_test
+ return 0
+ ;;
+ esac
+ fi
+
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-h --help --usage -V --version \
+ --copyright --license-i --info -a --all -q \
+ --quietmode= -d --device= -T --tolerance= -b --badsum= \
+ -r --report= -s --smart= -o --offlineauto= -S \
+ --saveauto= -H --health -c --capabilities -A \
+ --attributes -l --log= -v --vendorattribute= -F \
+ --firmwarebug= -P --presets= -t --test= -C \
+ --captive -X --abort' -- $cur ) )
+ else
+ cur=${cur:=/dev/}
+ _filedir
+ fi
+}
+complete -F _smartctl smartctl
+}
+
+# vncviewer(1) completion
+#
+have vncviewer &&
+_vncviewer()
+{
+ local cur prev
+ local -a config
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -via)
+ _known_hosts -a
+ ;;
+ *)
+ # ssh into the the server, find and ping the broadcast address, then
+ # sort and show the results.
+ COMPREPLY=( $( ssh -o 'Batchmode yes' $prev \
+ "ping -bnc 4 255.255.255.255" 2>/dev/null | \
+ awk -F ' ' '{print $4}' | \
+ sort -n | uniq | egrep '[0-9]+\.[0-9]+\.' 2>/dev/null ) )
+ esac
+
+ return 0
+} &&
+complete -F _vncviewer vncviewer
+
+# sysctl(8) completion
+#
+have sysctl &&
+_sysctl()
+{
+ local cur
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ COMPREPLY=( $( compgen -W "$(sysctl -N -a 2>/dev/null)" -- $cur ) )
+
+ return 0
+} &&
+complete -F _sysctl sysctl
+
+# update-rc.d(8) completion
+#
+# Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
+#
+have update-rc.d &&
+_update_rc_d()
+{
+ local cur prev sysvdir services options valid_options
+
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
+ || sysvdir=/etc/init.d
+
+ services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) )
+ services=( ${services[@]#$sysvdir/} )
+ options=( -f -n )
+
+ if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then
+ valid_options=( $( \
+ echo "${COMP_WORDS[@]} ${options[@]}" \
+ | tr " " "\n" \
+ | sed -ne "/$( echo "${options[@]}" | sed "s/ /\\|/g" )/p" \
+ | sort | uniq -u \
+ ) )
+ COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
+ -X '$( echo ${COMP_WORDS[@]} | tr " " "|" )' -- $cur ) )
+ elif [[ "$prev" == ?($( echo ${services[@]} | tr " " "|" )) ]]; then
+ COMPREPLY=( $( compgen -W 'remove defaults start stop' -- $cur ) )
+ elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then
+ COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
+ elif [[ "$prev" == defaults && "$cur" == [sk]?([0-9]) ]]; then
+ COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
+ elif [[ "$prev" == defaults && -z "$cur" ]]; then
+ COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 s k )
+ elif [[ "$prev" == ?(start|stop) ]]; then
+ if [[ "$cur" == [0-9] || -z "$cur" ]]; then
+ COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
+ elif [[ "$cur" == [0-9][0-9] ]]; then
+ COMPREPLY=( $cur )
+ else
+ COMPREPLY=()
+ fi
+ elif [[ "$prev" == ?([0-9][0-9]|[0-6S]) ]]; then
+ if [[ -z "$cur" ]]; then
+ if [[ $prev == [0-9][0-9] ]]; then
+ COMPREPLY=( 0 1 2 3 4 5 6 S )
+ else
+ COMPREPLY=( 0 1 2 3 4 5 6 S . )
+ fi
+ elif [[ "$cur" == [0-6S.] ]]; then
+ COMPREPLY=( $cur )
+ else
+ COMPREPLY=()
+ fi
+ elif [[ "$prev" == "." ]]; then
+ COMPREPLY=( $(compgen -W "start stop" -- $cur) )
+ else
+ COMPREPLY=()
+ fi
+
+ return 0
+} &&
+complete -F _update_rc_d update-rc.d
+
+# invoke-rc.d(8) completion
+#
+# Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
+#
+have invoke-rc.d &&
+_invoke_rc_d()
+{
+ local cur prev sysvdir services options valid_options
+
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
+ || sysvdir=/etc/init.d
+
+ services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) )
+ services=( ${services[@]#$sysvdir/} )
+ options=( --help --quiet --force --try-anyway --disclose-deny --query --no-fallback )
+
+ if [[ ($COMP_CWORD -eq 1) || ("$prev" == --* ) ]]; then
+ valid_options=( $( \
+ echo ${COMP_WORDS[@]} ${options[@]} \
+ | tr " " "\n" \
+ | sed -ne "/$( echo ${options[@]} | sed "s/ /\\\\|/g" )/p" \
+ | sort | uniq -u \
+ ) )
+ COMPREPLY=( $( compgen -W '${valid_options[@]} ${services[@]}' -- \
+ $cur ) )
+ elif [ -x $sysvdir/$prev ]; then
+ COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \
+ s/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}\"]*\).*$/\1/p" \
+ $sysvdir/$prev`' -- \
+ $cur ) )
+ else
+ COMPREPLY=()
+ fi
+
+ return 0
+} &&
+complete -F _invoke_rc_d invoke-rc.d
+
+# minicom(1) completion
+#
+have minicom &&
+_minicom()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case $prev in
+ -@(a|c))
+ COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
+ return 0
+ ;;
+ -@(S|C))
+ _filedir
+ return 0
+ ;;
+ -P)
+ COMPREPLY=( $( command ls /dev/tty* ) )
+ COMPREPLY=( $( compgen -W '${COMPREPLY[@]} ${COMPREPLY[@]#/dev/}' -- $cur ) )
+ return 0
+ ;;
+ esac
+
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-s -o -m -M -z -l -L -w -a -t \
+ -c -S -d -p -C -T -8' -- $cur ) )
+ else
+ COMPREPLY=( $( command ls /etc/minicom/minirc.* 2>/dev/null | sed -e 's|/etc/minicom/minirc.||' | grep "^$cur" ) )
+ fi
+} &&
+complete -F _minicom minicom
+
+# svn completion
+#
+have svn &&
+{
+_svn()
+{
+ local cur prev commands options command
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ commands='add blame praise annotate ann cat checkout co cleanup commit \
+ ci copy cp delete del remove rm diff di export help ? h import \
+ info list ls lock log merge mkdir move mv rename ren \
+ propdel pdel pd propedit pedit pe propget pget pg \
+ proplist plist pl propset pset ps resolved revert \
+ status stat st switch sw unlock update up'
+
+ if [[ $COMP_CWORD -eq 1 ]] ; then
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--version' -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
+ fi
+ else
+
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ case $prev in
+ --config-dir)
+ _filedir -d
+ return 0;
+ ;;
+ -@(F|-file|-targets))
+ _filedir
+ return 0;
+ ;;
+ --encoding)
+ COMPREPLY=( $( compgen -W \
+ '$( iconv --list | sed -e "s@//@@;" )' \
+ -- "$cur" ) )
+ return 0;
+ ;;
+ --@(editor|diff|diff3)-cmd)
+ COMP_WORDS=(COMP_WORDS[0] $cur)
+ COMP_CWORD=1
+ _command
+ return 0;
+ ;;
+ esac
+
+ command=${COMP_WORDS[1]}
+
+ if [[ "$cur" == -* ]]; then
+ # possible options for the command
+ case $command in
+ add)
+ options='--auto-props --no-auto-props \
+ --force --targets --no-ignore \
+ --non-recursive -N -q --quiet'
+ ;;
+ @(blame|annotate|ann|praise))
+ options='-r --revisions --username \
+ --password --no-auth-cache \
+ --non-interactive -v \
+ --verbose --incremental --xml'
+ ;;
+ cat)
+ options='-r --revision --username \
+ --password --no-auth-cache \
+ --non-interactive'
+ ;;
+ @(checkout|co))
+ options='-r --revision -q --quiet -N \
+ --non-recursive --username \
+ --password --no-auth-cache \
+ --non-interactive \
+ --ignore-externals'
+ ;;
+ cleanup)
+ options='--diff3-cmd'
+ ;;
+ @(commit|ci))
+ options='-m --message -F --file \
+ --encoding --force-log -q \
+ --quiet --non-recursive -N \
+ --targets --editor-cmd \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive --no-unlock'
+ ;;
+ @(copy|cp))
+ options='-m --message -F --file \
+ --encoding --force-log -r \
+ --revision -q --quiet \
+ --editor-cmd -username \
+ --password --no-auth-cache \
+ --non-interactive'
+ ;;
+ @(delete|del|remove|rm))
+ options='--force -m --message -F \
+ --file --encoding --force-log \
+ -q --quiet --targets \
+ --editor-cmd -username \
+ --password --no-auth-cache \
+ --non-interactive'
+ ;;
+ @(diff|di))
+ options='-r --revision -x --extensions \
+ --diff-cmd --no-diff-deleted \
+ -N --non-recursive --username \
+ --password --no-auth-cache \
+ --non-interactive --force \
+ --old --new --notice-ancestry'
+ ;;
+ export)
+ options='-r --revision -q --quiet \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive -N \
+ --non-recursive --force \
+ --native-eol --ignore-externals'
+ ;;
+ import)
+ options='--auto-props --no-auto-props \
+ -m --message -F --file \
+ --encoding --force-log -q \
+ --quiet --non-recursive \
+ --no-ignore --editor-cmd \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive'
+ ;;
+ info)
+ options='--username --password \
+ --no-auth-cache \
+ --non-interactive -r \
+ --revision --xml --targets \
+ -R --recursive --incremental'
+ ;;
+ @(list|ls))
+ options='-r --revision -v --verbose -R \
+ --recursive --username \
+ --password --no-auth-cache \
+ --non-interactive \
+ --incremental --xml'
+ ;;
+ lock)
+ options='-m --message -F --file \
+ --encoding --force-log \
+ --targets --force --username \
+ --password --no-auth-cache \
+ --non-interactive'
+ ;;
+ log)
+ options='-r --revision -v --verbose \
+ --targets --username \
+ --password --no-auth-cache \
+ --non-interactive \
+ --stop-on-copy --incremental \
+ --xml -q --quiet --limit'
+ ;;
+ merge)
+ options='-r --revision -N \
+ --non-recursive -q --quiet \
+ --force --dry-run --diff3-cmd \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive \
+ --ignore-ancestry'
+ ;;
+ mkdir)
+ options='-m --message -F --file \
+ --encoding --force-log -q \
+ --quiet --editor-cmd \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive'
+ ;;
+ @(move|mv|rename|ren))
+ options='-m --message -F --file \
+ --encoding --force-log -r \
+ --revision -q --quiet \
+ --force --editor-cmd \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive'
+ ;;
+ @(propdel|pdel|pd))
+ options='-q --quiet -R --recursive -r \
+ --revision --revprop \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive'
+ ;;
+ @(propedit|pedit|pe))
+ options='-r --revision --revprop \
+ --encoding --editor-cmd \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive --force'
+ ;;
+ @(propget|pget|pg))
+ options='-R --recursive -r --revision \
+ --revprop --strict --username \
+ --password --no-auth-cache \
+ --non-interactive'
+ ;;
+ @(proplist|plist|pl))
+ options='-v --verbose -R --recursive \
+ -r --revision --revprop -q \
+ --quiet --username --password \
+ --no-auth-cache \
+ --non-interactive'
+ ;;
+ @(propset|pset|ps))
+ options='-F --file -q --quiet \
+ --targets -R --recursive \
+ --revprop --encoding \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive -r \
+ --revision --force'
+ ;;
+ resolved)
+ options='--targets -R --recursive -q \
+ --quiet'
+ ;;
+ revert)
+ options='--targets -R --recursive -q \
+ --quiet'
+ ;;
+ @(status|stat|st))
+ options='-u --show-updates -v \
+ --verbose -N --non-recursive \
+ -q --quiet --username \
+ --password --no-auth-cache \
+ --non-interactive --no-ignore \
+ --ignore-externals \
+ --incremental --xml'
+ ;;
+ @(switch|sw))
+ options='--relocate -r --revision -N \
+ --non-recursive -q --quiet \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive --diff3-cmd'
+ ;;
+ unlock)
+ options='--targets --force --username \
+ --password --no-auth-cache \
+ --non-interactive'
+ ;;
+ @(update|up))
+ options='-r --revision -N \
+ --non-recursive -q --quiet \
+ --username --password \
+ --no-auth-cache \
+ --non-interactive \
+ --diff3-cmd --ignore-externals'
+ ;;
+ esac
+ options="$options --help -h --config-dir"
+
+ COMPREPLY=( $( compgen -W "$options" -- $cur ) )
+ else
+ if [[ "$command" == @(help|h|\?) ]]; then
+ COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
+ else
+ _filedir
+ fi
+ fi
+ fi
+
+ return 0
+}
+complete -F _svn $default svn
+
+_svnadmin()
+{
+ local cur prev commands options mode
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ commands='create deltify dump help ? hotcopy list-dblogs \
+ list-unused-dblogs load lslocks lstxns recover rmlocks \
+ rmtxns setlog verify'
+
+ if [[ $COMP_CWORD -eq 1 ]] ; then
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--version' -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
+ fi
+ else
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ case $prev in
+ --config-dir)
+ _filedir -d
+ return 0;
+ ;;
+ --fs-type)
+ COMPREPLY=( $( compgen -W 'fsfs bdb' -- $cur ) )
+ return 0;
+ ;;
+ esac
+
+ command=${COMP_WORDS[1]}
+
+ if [[ "$cur" == -* ]]; then
+ # possible options for the command
+ case $command in
+ create)
+ options='--bdb-txn-nosync \
+ --bdb-log-keep --config-dir \
+ --fs-type'
+ ;;
+ deltify)
+ options='-r --revision -q --quiet'
+ ;;
+ dump)
+ options='-r --revision --incremental \
+ -q --quiet --deltas'
+ ;;
+ hotcopy)
+ options='--clean-logs'
+ ;;
+ load)
+ options='--ignore-uuid --force-uuid \
+ --parent-dir -q --quiet \
+ --use-pre-commit-hook \
+ --use-post-commit-hook'
+ ;;
+ rmtxns)
+ options='-q --quiet'
+ ;;
+ setlog)
+ options='-r --revision --bypass-hooks'
+ ;;
+ esac
+
+ options="$options --help -h"
+ COMPREPLY=( $( compgen -W "$options" -- $cur ) )
+ else
+ if [[ "$command" == @(help|h|\?) ]]; then
+ COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
+ else
+ _filedir
+ fi
+ fi
+ fi
+
+ return 0
+}
+complete -F _svnadmin $default svnadmin
+
+_svnlook()
+{
+ local cur prev commands options mode
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ commands='author cat changed date diff dirs-changed help ? h history \
+ info lock log propget pget pg proplist plist pl tree uuid \
+ youngest'
+
+ if [[ $COMP_CWORD -eq 1 ]] ; then
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '--version' -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
+ fi
+ else
+ command=${COMP_WORDS[1]}
+
+ if [[ "$cur" == -* ]]; then
+ # possible options for the command
+ case $command in
+ @(author|cat|date|dirs-changed|info|log))
+ options='-r --revision -t \
+ --transaction'
+ ;;
+ changed)
+ options='-r --revision -t \
+ --transaction --copy-info'
+ ;;
+ diff)
+ options='-r --revision -t \
+ --transaction \
+ --no-diff-deleted \
+ --no-diff-added \
+ --diff-copy-from'
+ ;;
+ history)
+ options='-r --revision --show-ids'
+ ;;
+ prop@(get|list))
+ options='-r --revision -t \
+ --transaction --revprop'
+ ;;
+ tree)
+ options='-r --revision -t \
+ --transaction --show-ids \
+ --full-paths'
+ ;;
+ esac
+
+ options="$options --help -h"
+ COMPREPLY=( $( compgen -W "$options" -- $cur ) )
+ else
+ if [[ "$command" == @(help|h|\?) ]]; then
+ COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
+ else
+ _filedir
+ fi
+ fi
+ fi
+
+ return 0
+}
+complete -F _svnlook $default svnlook
+}
+
+_filedir_xspec()
+{
+ local IFS cur xspec
+
+ IFS=$'\t\n'
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ _expand || return 0
+
+ # get first exclusion compspec that matches this command
+ xspec=$( sed -ne $'/^complete .*[ \t]'${1##*/}$'\([ \t]\|$\)/{p;q;}' \
+ $BASH_COMPLETION )
+ # prune to leave nothing but the -X spec
+ xspec=${xspec#*-X }
+ xspec=${xspec%% *}
+
+ local toks=( ) tmp
+
+ while read -r tmp; do
+ [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp
+ done < <( compgen -d -- "$(quote_readline "$cur")" )
+
+ while read -r tmp; do
+ [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp
+ done < <( eval compgen -f -X $xspec -- "\$(quote_readline "\$cur")" )
+
+ COMPREPLY=( "${toks[@]}" )
+}
+list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' \
+ $BASH_COMPLETION | \
+ # read exclusion compspecs
+ (
+ while read line
+ do
+ # ignore compspecs that are commented out
+ if [ "${line#\#}" != "$line" ]; then continue; fi
+ line=${line%# START exclude*}
+ line=${line%# FINISH exclude*}
+ line=${line##*\'}
+ list=( "${list[@]}" $line )
+ done
+ echo "${list[@]}"
+ )
+ ) )
+# remove previous compspecs
+if [ ${#list[@]} -gt 0 ]; then
+ eval complete -r ${list[@]}
+ # install new compspecs
+ eval complete -F _filedir_xspec $filenames "${list[@]}"
+fi
+unset list
+
+# source completion directory definitions
+if [ -d $BASH_COMPLETION_DIR -a -r $BASH_COMPLETION_DIR -a \
+ -x $BASH_COMPLETION_DIR ]; then
+ for i in $BASH_COMPLETION_DIR/*; do
+ [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|.rpm*) ]] &&
+ [ \( -f $i -o -h $i \) -a -r $i ] && . $i
+ done
+fi
+unset i
+
+# source user completion file
+[ $BASH_COMPLETION != ~/.bash_completion -a -r ~/.bash_completion ] \
+ && . ~/.bash_completion
+unset -f have
+unset UNAME RELEASE default dirnames filenames have nospace bashdefault \
+ plusdirs
+
+set $BASH_COMPLETION_ORIGINAL_V_VALUE
+unset BASH_COMPLETION_ORIGINAL_V_VALUE
+
+### Local Variables:
+### mode: shell-script
+### End:
diff --git a/usr/src/cmd/nsadmin/bash/bash_completion.d/dladm b/usr/src/cmd/nsadmin/bash/bash_completion.d/dladm
new file mode 100644
index 0000000000..179227b2a2
--- /dev/null
+++ b/usr/src/cmd/nsadmin/bash/bash_completion.d/dladm
@@ -0,0 +1,34 @@
+_dladm()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ if [[ ${prev} == 'dladm' ]]; then
+ local cmds="rename-link show-link create-aggr delete-aggr add-aggr \
+ remove-aggr modify-aggr show-aggr scan-wifi connect-wifi \
+ disconnect-wifi show-wifi set-linkprop reset-linkprop \
+ show-linkprop show-ether create-secobj delete-secobj show-secobj \
+ create-vlan delete-vlan show-vlan create-iptun delete-iptun \
+ modify-iptun show-iptun delete-phys show-phys create-vnic \
+ delete-vnic show-vnic create-part delete-part show-part show-ib \
+ create-etherstub delete-etherstub show-etherstub create-bridge \
+ modify-bridge delete-bridge add-bridge remove-bridge show-bridge \
+ show-bridge show-usage"
+
+ COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
+ # The -z takes a zone option, ignore everything else
+ elif [[ ${prev} =~ -.*z$ ]]; then
+ local zones=$(zoneadm list -c | grep -v '^global$')
+ COMPREPLY=( $(compgen -W "${zones}" -- ${cur}) )
+ elif [[ ${prev} =~ 'delete-vnic' ]]; then
+ local vnics=$(dladm show-vnic -p -o link)
+ COMPREPLY=( $(compgen -W "${vnics}" -- ${cur}) )
+ elif [[ ${prev} =~ 'delete-etherstub' ]]; then
+ local stubs=$(dladm show-etherstub -p)
+ COMPREPLY=( $(compgen -W "${stubs}" -- ${cur}) )
+ fi
+}
+
+complete -F _dladm dladm
diff --git a/usr/src/cmd/nsadmin/bash/bash_completion.d/machines b/usr/src/cmd/nsadmin/bash/bash_completion.d/machines
new file mode 100644
index 0000000000..05de1b75a4
--- /dev/null
+++ b/usr/src/cmd/nsadmin/bash/bash_completion.d/machines
@@ -0,0 +1,19 @@
+_machine()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ if [[ ${prev} == 'machine-json' ]]; then
+ machines=$(zoneadm list -cp | grep -v ':global:' | cut -d':' -f2,5 | tr ':' '\n' | sort | uniq)
+ COMPREPLY=( $(compgen -W "${machines}" -- ${cur}) )
+ else
+ # Just expand files by default
+ COMPREPLY=( $(compgen -f -- ${cur}) )
+ fi
+
+ return 0
+}
+
+complete -F _machine machine-json
diff --git a/usr/src/cmd/nsadmin/bash/bash_completion.d/vms b/usr/src/cmd/nsadmin/bash/bash_completion.d/vms
new file mode 100644
index 0000000000..71bcac5994
--- /dev/null
+++ b/usr/src/cmd/nsadmin/bash/bash_completion.d/vms
@@ -0,0 +1,62 @@
+_vmadm()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ up_patterns=$(printf " running *\$\n halting *\$\n")
+
+ if [[ ${prev} == 'vmadm' ]]; then
+ COMPREPLY=( $(compgen -W "boot destroy dump kill halt list reboot reset info nmi" -- ${cur}) )
+ else
+ case ${prev} in
+ boot)
+ local not_running=$(vmadm list -v | grep -v "^UUID" | \
+ /usr/xpg4/bin/grep -v -e "${up_patterns}" | cut -d' ' -f1)
+ COMPREPLY=( $(compgen -W "${not_running}" -- ${cur}) )
+ ;;
+ info|kill)
+ local running=$(vmadm list -v | grep -v "^UUID" | \
+ /usr/xpg4/bin/grep -e "${up_patterns}" | cut -d ' ' -f1)
+ COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
+ ;;
+ halt|reboot|reset|nmi|screenshot)
+ local running=$(vmadm list -v | grep -v "^UUID" | \
+ grep " running *$" | cut -d ' ' -f1)
+ COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
+ ;;
+ dump|destroy)
+ local all=$(vmadm list)
+ COMPREPLY=( $(compgen -W "${all}" -- ${cur}) )
+ ;;
+ *)
+ # Just expand files by default
+ COMPREPLY=( $(compgen -f -- ${cur}) )
+ ;;
+ esac
+ fi
+
+ return 0
+}
+
+_vmcfg()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ if [[ ${prev} == 'vmcfg' ]]; then
+ vms=$(vmadm list)
+ COMPREPLY=( $(compgen -W "${vms}" -- ${cur}) )
+ else
+ # Just expand files by default
+ COMPREPLY=( $(compgen -f -- ${cur}) )
+ fi
+
+ return 0
+}
+
+complete -F _vmadm vmadm
+complete -F _vmcfg vmcfg
diff --git a/usr/src/cmd/nsadmin/bash/bash_completion.d/zones b/usr/src/cmd/nsadmin/bash/bash_completion.d/zones
new file mode 100644
index 0000000000..2c68ba366e
--- /dev/null
+++ b/usr/src/cmd/nsadmin/bash/bash_completion.d/zones
@@ -0,0 +1,41 @@
+_zlogin()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ # The -e and -l take non-zone arguments, otherwise complete zone
+ if [[ ${prev} != '-e' ]] && [[ ${prev} != '-l' ]]; then
+ local running=$(zoneadm list | grep -v '^global$')
+ COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
+ fi
+ return 0
+}
+
+_dash_z_zone()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ # The -z takes a zone option, ignore everything else
+ if [[ ${prev} =~ -.*z$ ]]; then
+ local zones=$(zoneadm list -c | grep -v '^global$')
+ COMPREPLY=( $(compgen -W "${zones}" -- ${cur}) )
+ fi
+ return 0
+}
+
+complete -F _zlogin zlogin
+complete -F _dash_z_zone zoneadm
+complete -F _dash_z_zone zonecfg
+complete -F _dash_z_zone svcs
+complete -F _dash_z_zone svcadm
+complete -F _dash_z_zone svcprop
+complete -F _dash_z_zone pgrep
+complete -F _dash_z_zone pkill
+complete -F _dash_z_zone ps
+complete -F _dash_z_zone ptree
+complete -F _dash_z_zone wall
diff --git a/usr/src/cmd/nsadmin/bashrc.sh b/usr/src/cmd/nsadmin/bashrc.sh
deleted file mode 100644
index 938b0da67e..0000000000
--- a/usr/src/cmd/nsadmin/bashrc.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#
-# Define default prompt to <username>@<hostname>:<path><"($|#) ">
-# and print '#' for user "root" and '$' for normal users.
-#
-typeset +x PS1="\u@\h:\w\\$ "
diff --git a/usr/src/cmd/nsadmin/dot-bash_profile.sh b/usr/src/cmd/nsadmin/dot-bash_profile.sh
new file mode 100644
index 0000000000..dc732f6814
--- /dev/null
+++ b/usr/src/cmd/nsadmin/dot-bash_profile.sh
@@ -0,0 +1,12 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+#
+# Copyright (c) 2014, Joyent, Inc.
+#
+
+[ -f /root/.profile ] && source /root/.profile
+[ -f /root/.bashrc ] && source /root/.bashrc
diff --git a/usr/src/cmd/nsadmin/dot-bashrc.sh b/usr/src/cmd/nsadmin/dot-bashrc.sh
new file mode 100644
index 0000000000..0f06d70ece
--- /dev/null
+++ b/usr/src/cmd/nsadmin/dot-bashrc.sh
@@ -0,0 +1,57 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+#
+# Copyright (c) 2014, Joyent, Inc.
+#
+
+if [ "$PS1" ]; then
+ mt_tty=$(/usr/bin/tty 2>/dev/null)
+ if [[ $mt_tty =~ ^/dev/term/[abcd] ]]; then
+ # If we're on the serial console, we generally won't know how
+ # big our terminal is. Attempt to ask it using control sequences
+ # and resize our pty accordingly.
+ mt_output=$(/usr/lib/measure_terminal 2>/dev/null)
+ if [[ $? -eq 0 ]]; then
+ eval "$mt_output"
+ else
+ # We could not read the size, but we should set a 'sane'
+ # default as the dimensions of the previous user's terminal
+ # persist on the tty device.
+ export LINES=25
+ export COLUMNS=80
+ fi
+ /usr/bin/stty rows ${LINES} columns ${COLUMNS} 2>/dev/null
+ fi
+ unset mt_output mt_tty
+ shopt -s checkwinsize
+ if [[ -f /.dcinfo ]]; then
+ . /.dcinfo
+ DC_NAME="${SDC_DATACENTER_NAME}"
+ fi
+ if [[ -n "${DC_NAME}" ]]; then
+ PS1="[\u@\h (${DC_NAME}) \w]\\$ "
+ else
+ PS1="[\u@\h \w]\\$ "
+ fi
+ alias ll='ls -lF'
+ alias ls='ls --color=auto'
+ [ -n "${SSH_CLIENT}" ] && export PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME} \007" && history -a'
+fi
+
+# Load bash completion
+[ -f /etc/bash/bash_completion ] && . /etc/bash/bash_completion
+
+svclog() {
+ if [[ -z "$PAGER" ]]; then
+ PAGER=less
+ fi
+ $PAGER `svcs -L $1`
+}
+
+svclogf() {
+ /usr/bin/tail -f `svcs -L $1`
+}
diff --git a/usr/src/cmd/nsadmin/dot-profile.sh b/usr/src/cmd/nsadmin/dot-profile.sh
index a45e47b58d..906d43bae5 100644
--- a/usr/src/cmd/nsadmin/dot-profile.sh
+++ b/usr/src/cmd/nsadmin/dot-profile.sh
@@ -1,14 +1,14 @@
#
-# Uncommenting PATH below will place /usr/gnu/bin at front,
-# adds /usr/sbin and /sbin to the end.
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
-# export PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin
+
#
-# Define default prompt to <username>@<hostname>:<path><"($|#) ">
-# and print '#' for user "root" and '$' for normal users.
+# Copyright (c) 2018, Joyent, Inc.
#
-# override default prompt for bash
-# case "$0" in
-# -bash)
-# export PS1="\u@\h:\w\\$ "
-# esac
+
+PATH=/usr/bin:/usr/sbin:/smartdc/bin:/opt/smartdc/bin:/opt/local/bin:/opt/local/sbin:/opt/tools/bin:/opt/tools/sbin:/opt/smartdc/agents/bin
+MANPATH=/usr/share/man:/smartdc/man:/opt/smartdc/man:/opt/local/man:/opt/tools/man
+PAGER=less
+export PATH MANPATH PAGER
diff --git a/usr/src/cmd/nsadmin/etc-profile.sh b/usr/src/cmd/nsadmin/etc-profile.sh
index 035e8a3025..b59a80791b 100644
--- a/usr/src/cmd/nsadmin/etc-profile.sh
+++ b/usr/src/cmd/nsadmin/etc-profile.sh
@@ -21,6 +21,7 @@
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
+#
# The profile that all logins get before using their own .profile.
@@ -37,29 +38,14 @@ then
export TERM
fi
-#
-# use less(1) as the default pager for the man(1) command.
-#
-PAGER="/usr/bin/less -ins"
-export PAGER
-
# Login and -su shells get /etc/profile services.
# -rsh is given its environment in its .profile.
case "$0" in
--bash)
- # set prompt for bash
- PS1="\u@\h:\w\\$ "
- export PS1
- ;;
-esac
-
-case "$0" in
-sh | -ksh | -ksh93 | -jsh | -bash | -zsh)
if [ ! -f .hushlogin ]
then
- /usr/sbin/quota
# Allow the user to break the Message-Of-The-Day only.
trap "trap '' 2" 2
/bin/cat -s /etc/motd
@@ -67,12 +53,12 @@ case "$0" in
/bin/mail -E
case $? in
- 0)
+ 0)
echo "You have new mail."
- ;;
- 2)
+ ;;
+ 2)
echo "You have mail."
- ;;
+ ;;
esac
fi
esac
diff --git a/usr/src/cmd/nsadmin/etc-skel-bashrc.sh b/usr/src/cmd/nsadmin/etc-skel-bashrc.sh
new file mode 100644
index 0000000000..128f6b79d7
--- /dev/null
+++ b/usr/src/cmd/nsadmin/etc-skel-bashrc.sh
@@ -0,0 +1,7 @@
+#
+# Define default prompt to <username>@<hostname>:<path><"($|#) ">
+# and print '#' for user "root" and '$' for normal users.
+#
+PS1='${LOGNAME}@$(/usr/bin/hostname):$(
+ [[ "${LOGNAME}" == "root" ]] && printf "%s" "${PWD/${HOME}/~}# " ||
+ printf "%s" "${PWD/${HOME}/~}\$ ")'
diff --git a/usr/src/cmd/nsadmin/system b/usr/src/cmd/nsadmin/system
index 29da0b787c..905594de8a 100644
--- a/usr/src/cmd/nsadmin/system
+++ b/usr/src/cmd/nsadmin/system
@@ -23,6 +23,7 @@
* SYSTEM SPECIFICATION FILE
*
+*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
* It is not recommended to edit this file directly but rather
@@ -34,6 +35,10 @@
* recommendations on naming fragment files.
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+*
+* As SmartOS ships with /etc/ off a ramdisk, we don't support using the
+* /etc/system.d mechanism.
+*
* moddir:
*
@@ -108,3 +113,66 @@
*
* set test_module:debug = 0x13
+set ibft_noprobe=1
+
+set noexec_user_stack=1
+set noexec_user_stack_log=1
+set rlim_fd_cur=65536
+
+* Ensure that c-states are disabled
+set idle_cpu_no_deep_c=1
+
+* 10 GbE Tuning
+set ip:ip_squeue_fanout=1
+
+*
+* Machines should take a crash dump and reboot when receiving an NMI
+*
+set pcplusmp:apic_panic_on_nmi=1
+set apix:apic_panic_on_nmi=1
+
+*
+* Don't use multi-threaded fast crash dump or a high compression level
+*
+set dump_plat_mincpu=0
+set dump_bzip2_level=1
+
+*
+* See OS-1361 for dealing with the timer woes.
+*
+set pcplusmp:apic_timer_preferred_mode=0
+set apix:apic_timer_preferred_mode=0
+
+*
+* Want additional crash dump metrics
+*
+set dump_metrics_on=1
+
+*
+* The traditional (and essentially entirely brain dead) cfgadm(1M)-centric
+* model of hotpluggin' appears to be basically unnecessary. This tunable
+* enables the system to create device nodes for newly inserted devices
+* automatically. See: usr/src/uts/common/io/sata/impl/sata.c:97
+*
+set sata:sata_auto_online=1
+
+*
+* We want to limit the time spent in any one I/O to 10 seconds for targets
+* that are not optical. This is still a very long time; our queue depth is
+* typically 10 or less, and disks will usually fail a command after 2-3s.
+* So we'd have to have multiple reads of bad sectors queued up to have any
+* chance of timing out. In practice, timeouts occur because of problems with
+* disk controllers or firmware, not media errors, and in those cases it will
+* not help at all to wait longer.
+*
+set sd:sd_io_time=10
+
+* Use hires tick to improve some scheduling latency issues
+set hires_tick=1
+
+*
+* The "buildstamp" module contains information about the git sources used to
+* build the operating system image. Once loaded, the driver will refuse to
+* detach. We load it early to ensure it is in a crash dump wherever possible.
+*
+forceload: drv/buildstamp
diff --git a/usr/src/cmd/nsadmin/zshrc b/usr/src/cmd/nsadmin/zshrc
new file mode 100644
index 0000000000..1e9c83e57f
--- /dev/null
+++ b/usr/src/cmd/nsadmin/zshrc
@@ -0,0 +1,31 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "@(#)zshrc 1.1 10/02/08 SMI"
+#
+
+# Turn on the "new" completion system. See zshcompsys(1).
+autoload -Uz compinit
+compinit -i
diff --git a/usr/src/cmd/svc/milestone/Makefile b/usr/src/cmd/svc/milestone/Makefile
index 901727dc9f..576576ba2e 100644
--- a/usr/src/cmd/svc/milestone/Makefile
+++ b/usr/src/cmd/svc/milestone/Makefile
@@ -21,6 +21,8 @@
#
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
#
+# Copyright 2019 Joyent, Inc.
+#
include ../../Makefile.cmd
@@ -30,6 +32,7 @@ BUILTXML= \
console-login.xml
FSSVCS= \
+ joyent-fs.xml \
local-fs.xml \
minimal-fs.xml \
root-fs.xml \
@@ -38,6 +41,7 @@ FSSVCS= \
FSMANIFESTS= $(FSSVCS:%=$(ROOTSVCSYSTEMFILESYSTEM)/%)
NETSVCS= \
+ network-early-admin.xml \
network-initial.xml \
network-install.xml \
network-iptun.xml \
@@ -75,8 +79,12 @@ SYSTEMSVCS= \
early-manifest-import.xml \
identity.xml \
manifest-import.xml \
+ mdata.xml \
process-security.xml \
rmtmpfiles.xml \
+ smartdc-config.xml \
+ smartdc-init.xml \
+ smartdc-ur.xml \
vtdaemon.xml
SYSTEMMANIFESTS = $(SYSTEMSVCS:%=$(ROOTSVCSYSTEM)/%)
@@ -103,6 +111,7 @@ SVCMETHOD=\
console-login \
devices-audio \
devices-local \
+ fs-joyent \
fs-local \
fs-minimal \
fs-root \
@@ -110,6 +119,9 @@ SVCMETHOD=\
identity-domain \
identity-node \
manifest-import \
+ mdata-execute \
+ mdata-fetch \
+ net-early-admin \
net-loc \
net-loopback \
net-init \
@@ -122,6 +134,11 @@ SVCMETHOD=\
net-routing-setup \
net-svc \
rmtmpfiles \
+ smartdc-config \
+ smartdc-init \
+ smartdc-ur \
+ sysidtool-net \
+ sysidtool-system \
vtdaemon
$(ROOTSVCMETHOD) := FILEMODE = 0555
@@ -161,4 +178,4 @@ $(ROOTSVCSYSTEM)/svc/%: %
$(ROOT)/lib/svc/share/%: %.share
$(INS.rename)
-clean lint _msg:
+clean _msg:
diff --git a/usr/src/cmd/svc/milestone/console-login b/usr/src/cmd/svc/milestone/console-login
index c7003b103b..8ddaaf29ac 100644
--- a/usr/src/cmd/svc/milestone/console-login
+++ b/usr/src/cmd/svc/milestone/console-login
@@ -23,6 +23,7 @@
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
+# Copyright 2015 Joyent, Inc.
#
# This method script manages all vt logins including system
# console login.
@@ -38,18 +39,29 @@
. /lib/svc/share/smf_include.sh
-if [ "$1" != "default" ]; then
- if smf_dont_configure_vt; then
- /usr/sbin/svcadm disable $SMF_FMRI
- exit $SMF_EXIT_OK
- fi
-fi
-
getproparg() {
val=`svcprop -p $2 $SMF_FMRI`
[ -n "$val" ] && [ "$val" != "\"\"" ] && echo $1 $val
}
+# The service configuration invokes this script with "%i", the name of the
+# instance, as the first argument.
+instance="$1"
+if [ -z "$instance" ]; then
+ exit $SMF_EXIT_ERR_CONFIG
+fi
+
+case "$instance" in
+vt*)
+ # This instance is for one of the virtual terminal devices. Check to
+ # see if the vt subsystem is initialised:
+ if smf_dont_configure_vt; then
+ /usr/sbin/svcadm disable "$SMF_FMRI"
+ exit $SMF_EXIT_OK
+ fi
+ ;;
+esac
+
args="-g"
val=`svcprop -p ttymon/device $SMF_FMRI`
@@ -61,6 +73,20 @@ if [ "$val" = "/dev/vt/1" ]; then
exit $SMF_EXIT_ERR_CONFIG
fi
+# In SmartOS we use ttyb for metadata so we set to a non-existent device here
+# to disable the service and exit.
+if [[ ${val} == "/dev/term/b" && \
+ $(sysinfo | json "Product") == "SmartDC HVM" ]]; then
+
+ val=/dev/do_not_use_ttyb_in_a_vm
+fi
+
+if [[ ! -e $val ]]; then
+ # This device doesn't exist, can't run a tty on it.
+ /usr/sbin/svcadm disable $SMF_FMRI
+ exit $SMF_EXIT_OK
+fi
+
args="$args -d $val"
args="$args `getproparg -l ttymon/label`"
diff --git a/usr/src/cmd/svc/milestone/fs-joyent b/usr/src/cmd/svc/milestone/fs-joyent
new file mode 100755
index 0000000000..9082f22e46
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/fs-joyent
@@ -0,0 +1,288 @@
+#!/bin/bash
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2018, Joyent, Inc.
+#
+
+set -o xtrace
+
+fatal()
+{
+ echo "Error: $1"
+ exit $SMF_EXIT_ERR_FATAL
+}
+
+. /lib/svc/share/smf_include.sh
+. /lib/svc/share/fs_include.sh
+. /lib/sdc/usb-key.sh
+
+# first of all, if we aren't the global zone this doesn't make any sense to run
+
+smf_is_globalzone || exit $SMF_EXIT_OK
+
+# We need the links to /dev/dsk. Rather than trying to play games with manually
+# invoking syseventd ask devfsadm to do some work.
+/usr/sbin/devfsadm -c disk
+
+function destroy_zpools
+{
+ for pool in $(zpool list -p -o name | grep -v NAME) ; do
+ zpool destroy -f ${pool}
+ done
+}
+
+function mount_zfs
+{
+ local dataset=$1
+ local mountpoint=$2
+ local output=
+
+ #
+ # Try to mount the ZFS dataset. If the mountpoint is busy, wait five
+ # seconds and try again. Fail if the mount attempt returns EBUSY three
+ # consecutive times.
+ #
+ for i in {1..3}; do
+ output=$(mount -F zfs ${dataset} ${mountpoint} 2>&1)
+ if [[ $? -eq 0 ]]; then
+ break
+ fi
+
+ if [ "${output}" == "mount failed: Device busy" ]; then
+ sleep 5
+ else
+ echo ${output} 1>&2
+ return
+ fi
+ done
+
+ # The mount attempt must have failed
+ echo ${output} 1>&2
+}
+
+/bin/bootparams | grep "^noimport=true" >/dev/null
+if [ $? -ne 0 ]; then
+ # If the zpool doesn't exist, then there's nothing to mount.
+
+ # Assume the system zpool is zones, but if a different system pool
+ # identifies itself (by virtue of the .system_pool file being present in the
+ # pool's root dataset), then use that system pool instead.
+ SYS_ZPOOL=zones
+
+ # Import specified zpools, or all zpools available
+ pools=$(/bin/bootparams | egrep "^zpools?=" | cut -d= -f2 | tr , ' ')
+ if [ -z ${pools} ]; then
+ pools=$(zpool import | grep "pool:" | awk '{print $2}')
+ fi
+
+ for pool in $pools; do
+ zpool import -f $pool
+ # Due to early, failed attempts to support the filesystem_limits
+ # feature we now need to ensure the dependent feature is enabled.
+ zpool set feature@extensible_dataset=enabled $pool
+ if [[ -f /$pool/.system_pool ]]; then
+ SYS_ZPOOL=$pool
+ fi
+ done
+
+ svccfg -s svc:/system/smartdc/init setprop \
+ config/zpool=${SYS_ZPOOL}
+ svccfg -s svc:/system/smartdc/init:default refresh
+
+ # If the destroy_zpools boot parameter is set, destroy all zpools
+ /bin/bootparams | grep "^destroy_zpools=true" >/dev/null
+ if [ $? -eq 0 ]; then
+ destroy_zpools
+ fi
+
+ # A machine is reset to its original unsetup state (i.e. a 'factory reset')
+ # when the smartdc:factoryreset ZFS user property is set on the var dataset.
+ reset=$(zfs get -H -o value smartdc:factoryreset ${SYS_ZPOOL}/var)
+ if [ "${reset}" == "yes" ]; then
+ destroy_zpools
+ fi
+
+ # Capture the zpool's status output in the method's log file for
+ # troubleshooting.
+ #
+ # Note: It is critical that we do not run 'status -v'. If there are errors
+ # in the zpool error log and the zpool is large (e.g. > 200TB), then the
+ # lookup for the error file names can take a very long time (several hours).
+ # This would block the system boot until it completed.
+ zpool status ${SYS_ZPOOL}
+ if [ $? -eq 0 ]; then
+
+ # Stash the SUNWdefault.xml file so we can update the
+ # persistent version after mounting zones/config.
+ cp /etc/zones/SUNWdefault.xml /tmp/
+
+ # Mount and configure all system datasets
+ mount_zfs ${SYS_ZPOOL}/var /var
+ mount_zfs ${SYS_ZPOOL}/config /etc/zones
+ mount_zfs ${SYS_ZPOOL}/opt /opt
+
+ # Update the the persistent SUNWdefault.xml file to match the
+ # contents on ramdisk now that zones/config is mounted.
+ cp /tmp/SUNWdefault.xml /etc/zones/
+ rm -f /tmp/SUNWdefault.xml
+
+ #
+ # We include a manifest of all files shipped in the platform image,
+ # along with an MD5 hash of their contents. This was originally
+ # shipped as "/var/log/manifest", but once a machine is set up, "/var"
+ # now comes from the pool. The upshot of this is that every SmartOS
+ # machine has the manifest from the platform at setup time stored in
+ # "/var/log/manifest". Now that the manifest has moved to an
+ # accessible location, we should remove this file and replace it with a
+ # symbolic link.
+ #
+ if [[ -f '/var/log/manifest' && ! -L '/var/log/manifest' &&
+ ! -e '/var/log/manifest.original' ]]; then
+ mv '/var/log/manifest' '/var/log/manifest.original'
+ ln -s '../../usr/share/smartos/manifest' '/var/log/manifest'
+ fi
+
+ if [[ -z $(/bin/bootparams | grep '^smartos=true') ]]; then
+ mkdir -p /opt/smartdc/agents/smf
+ mount -O -F lofs /var/svc/manifest/site /opt/smartdc/agents/smf
+ fi
+
+ if [[ -n $(/bin/bootparams | grep '^headnode=true') || \
+ -n $(/bin/bootparams | grep '^smartos=true') ]]; then
+ mkdir /usbkey
+ mount_zfs ${SYS_ZPOOL}/usbkey /usbkey
+ fi
+
+ if [[ -n $(/bin/bootparams | grep '^smartos=true') ]]; then
+ mount -F lofs /usbkey/shadow /etc/shadow
+ mount -F lofs /usbkey/ssh /etc/ssh
+ fi
+
+ swap -a /dev/zvol/dsk/${SYS_ZPOOL}/swap || \
+ fatal "failed to configure swap device"
+
+ #
+ # Configure the dump device on top of a ZFS volume. In addition to the
+ # usual dumpadm(1m) call, there are two prerequisites for using this
+ # volume as a dump device: (1) that zvol must be using the noparity
+ # checksum algorithem, and (2) the MULTI_VDEV_CRASH_DUMP ZFS feature
+ # must be enabled. Prerequisite (1) is necessary since the exact
+ # on-disk value for ZIO_CHECKSUM_NOPARITY has changed, so to avoid a
+ # flag day on all systems, this service just sets that property again
+ # every time.
+ #
+ zfs set checksum=noparity ${SYS_ZPOOL}/dump || \
+ fatal "failed to set checksum=noparity on dump zvol"
+ zpool set feature@multi_vdev_crash_dump=enabled ${SYS_ZPOOL} || \
+ fatal "failed to enable multi_vdev_crash_dump ZFS feature"
+ dumpadm -y -d /dev/zvol/dsk/${SYS_ZPOOL}/dump || \
+ fatal "failed to configure dump device"
+
+ zfs list -H -o name ${SYS_ZPOOL}/cores/global >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ # Booting for the first time on a CN whose cores dataset is setup
+ # in the 6.x style. Convert to the new style.
+ zfs destroy -r ${SYS_ZPOOL}/cores
+ zfs create -o compression=gzip -o mountpoint=none ${SYS_ZPOOL}/cores
+ zfs create -o quota=10g -o mountpoint=/${SYS_ZPOOL}/global/cores \
+ ${SYS_ZPOOL}/cores/global
+ fi
+
+ ln -s /${SYS_ZPOOL}/global/cores /cores
+
+ [[ -f /${SYS_ZPOOL}/currbooted ]] && \
+ mv /${SYS_ZPOOL}/currbooted /${SYS_ZPOOL}/lastbooted
+ uname -v >/${SYS_ZPOOL}/currbooted
+ fi
+fi
+
+
+# The rest only applies to the headnode
+/bin/bootparams | grep "^headnode=true" >/dev/null || exit $SMF_EXIT_OK
+
+# If we rebooted during an upgrade, we're in deep trouble.
+if [ -d /var/upgrade_in_progress ]; then
+ echo "ERROR: An upgrade was in progress when the system rebooted." \
+ >/dev/console
+ echo " The system is in an indeterminate state, unable to continue." \
+ >/dev/console
+ exit $SMF_EXIT_ERR_FATAL
+fi
+
+COPYINPOINT=`svcprop -p "joyentfs/usb_copy_path" ${SMF_FMRI}`
+DEBUG=`svcprop -p "joyentfs/debug" ${SMF_FMRI}`
+
+if [[ -d /mnt ]]; then
+ chown root:root /mnt
+ chmod 700 /mnt
+else
+ mkdir -m 700 /mnt
+fi
+
+function make_usb_copy_if_possible
+{
+ [[ -n "${SYS_ZPOOL}" ]] || fatal "don't know system zpool name"
+
+ zpool list -Ho name | grep "^${SYS_ZPOOL}\$"
+ if [[ $? != 0 ]]; then
+ echo "skipping USB copy setup: no ${SYS_ZPOOL} zpool" >/dev/console
+ # Still return OK, because this is the expected case for first headnode
+ # boot.
+ return 0
+ fi
+
+ USBDATASET=${SYS_ZPOOL}/usbkey
+ if ! zfs list -Ho name | grep "^${USBDATASET}\$" >/dev/null; then
+ echo "skipping USB copy setup: no zones/usbkey dataset" >/dev/console
+ # Still return OK, because as of HEAD-2343 a CN being converted to a HN
+ # will not yet have this dataset on its first boot as an HN.
+ return 0
+ fi
+
+ echo "" > /dev/console
+ echo "Moving files from USB boot device onto disk storage." > /dev/console
+ echo "This may take several minutes. Please note the time..." > /dev/console
+ echo "" > /dev/console
+ echo "" > /dev/console
+
+ mkdir ${COPYINPOINT}
+ mount_zfs ${USBDATASET} ${COPYINPOINT}
+
+ (cd ${USBMOUNTPOINT}; rsync -av --log-file=/dev/console --exclude private --exclude os * ${COPYINPOINT})
+ if [[ -d ${USBMOUNTPOINT}/os ]]; then
+ (cd ${USBMOUNTPOINT}/os ; \
+ for dir in $(ls -d *); do
+ # source comes from pcfs which we've got lowering the case
+ # of everything, but we normally use capital T and Z for
+ # buildstamp, so fix it here.
+ source_dir=${dir}
+ target_dir=$(echo ${dir} | tr "[:lower:]" "[:upper:]")
+ mkdir -p ${COPYINPOINT}/os
+ echo "Copying: ${source_dir}/ ${COPYINPOINT}/os/${target_dir}" > /dev/console
+ rsync -a ${source_dir}/ ${COPYINPOINT}/os/${target_dir}
+ done
+ )
+ fi
+
+ echo "" > /dev/console
+ echo "Done copying files from USB device" > /dev/console
+ return 0
+}
+
+USBMOUNTPOINT=$(mount_usb_key "")
+if [[ $? -ne 0 ]]; then
+ fatal "couldn't mount USB key"
+fi
+
+make_usb_copy_if_possible
+exit $?
diff --git a/usr/src/cmd/svc/milestone/fs-root b/usr/src/cmd/svc/milestone/fs-root
index 9652eaaf94..f9de44c831 100644
--- a/usr/src/cmd/svc/milestone/fs-root
+++ b/usr/src/cmd/svc/milestone/fs-root
@@ -22,6 +22,7 @@
#
# Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
+# Copyright 2016 Joyent, Inc.
#
# Make sure that the libraries essential to this stage of booting can be found.
@@ -64,92 +65,27 @@ if smf_is_nonglobalzone; then
exit $SMF_EXIT_OK
fi
-#
-# Root is already mounted (by the kernel), but still needs to be
-# checked, possibly remounted and entered into mnttab. First
-# mount /usr if it is a separate file system. If the file system
-# type is something other than zfs, mount it read-only. This must
-# be done first to allow utilities such as fsck and setmnt to
-# reside on /usr minimizing the space required by the root file
-# system.
-#
-readvfstab "/usr" < $vfstab
-if [ -n "$mountp" ]; then
- if [ "$fstype" = zfs ]; then
- mountfs - /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
- else
- #
- # Must use -o largefiles here to ensure the
- # read-only mount does not fail as a result of
- # having a large file present on /usr. This gives
- # fsck a chance to fix up the largefiles flag
- # before we remount /usr read-write.
- #
- if [ "x$mntopts" = x- ]; then
- mntopts='ro,largefiles'
- else
- checkopt largefiles $mntopts
- if [ "x$option" != xlargefiles ]; then
- mntopts="largefiles,$mntopts"
- fi
-
- checkopt ro $mntopts
- if [ "x$option" != xro ]; then
- mntopts="ro,$mntopts"
- fi
-
- #
- # Requesting logging on a read-only mount
- # causes errors to be displayed, so remove
- # "logging" from the list of options for now.
- # The read-write mount performed later will
- # specify the logging option if appropriate.
- #
-
- checkopt logging $mntopts
- if [ "x$option" = xlogging ]; then
- mntopts="$otherops"
- fi
- fi
-
- mountfs -O /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
- fi
-fi
+/sbin/mount -F ufs -o remount,rw,nologging /devices/ramdisk:a /
+/usr/sbin/lofiadm -X -a /usr.lgz
#
-# if we are booted from zfs, the /usr mount probably won't be a
-# legacy mount. Use the standard zfs mount command instead.
-
-readmnttab "/" < /etc/mnttab
-if [ "$fstype" = zfs ]; then
- mountp=`/sbin/zfs get -H -o value mountpoint $special/usr 2>/dev/null`
- #
- # if mountp = /usr, there is a non-legacy mount of /usr
- # in the boot environment being booted.
- #
- if [ "x$mountp" = "x/usr" ] ; then
- /sbin/zfs mount $special/usr
- if [ $? != 0 ] ; then
- msg='zfs-mount failed'
- echo $msg
- echo "$SMF_FMRI:" $msg >/dev/msglog
- exit $SMF_EXIT_ERR_FATAL
- fi
+# Prior to mounting /usr, devfsadm is not yet available. As such, we must
+# locate the lofi block device node in /devices rather than in /dev. This
+# path has changed over time so we try both the old (pre-partition support)
+# and new paths.
+#
+lofi_devices_path='/devices/pseudo/lofi@1:disk'
+if [ ! -b "$lofi_devices_path" ]; then
+ lofi_devices_path='/devices/pseudo/lofi@0:1'
+ if [ ! -b "$lofi_devices_path" ]; then
+ echo 'could not locate lofi block device in /devices' >&2
+ exit $SMF_EXIT_ERR_FATAL
fi
fi
-#
-# Also mount /boot now so that things like keymap.sh can access
-# boot properties through eeprom. Readonly isn't required because
-# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.
-# Also, we don't account for caching /boot as it must be on a local
-# disk. So what's in vfstab is fine as it stands; just look to see
-# if it's there and avoid the mount if not.
-#
-readvfstab "/boot" < $vfstab
-
-if [ -n "$mountp" ]; then
- mountfs - /boot $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
+if ! /sbin/mount -F ufs -o ro "$lofi_devices_path" /usr; then
+ echo "could not mount /usr from $lofi_devices_path" >&2
+ exit $SMF_EXIT_ERR_FATAL
fi
#
diff --git a/usr/src/cmd/svc/milestone/fs-usr b/usr/src/cmd/svc/milestone/fs-usr
index b80e95c1f7..3caac452a3 100644
--- a/usr/src/cmd/svc/milestone/fs-usr
+++ b/usr/src/cmd/svc/milestone/fs-usr
@@ -19,163 +19,22 @@
#
# CDDL HEADER END
#
-
#
# Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
# All rights reserved.
# Copyright 2016 Nexenta Systems, Inc.
+# Copyright 2012, Joyent, Inc. All rights reserved.
#
-
. /lib/svc/share/smf_include.sh
-. /lib/svc/share/fs_include.sh
-
-UPDATEFILE=/etc/svc/volatile/boot_archive_needs_update
-
-#
-# Once root is read/write we can enable the dedicated dumpdevice if it exists
-# locally. This is an optimization as svc-dumpadm will attempt do this later.
-#
-dump_setup()
-{
- [ -r /etc/dumpadm.conf ] && . /etc/dumpadm.conf
-
- readswapdev $DUMPADM_DEVICE < $vfstab
-
- #
- # Make sure that the dump save area has been configured before
- # proceeding. If the variable has not been defined or does not exist
- # then bail out early. This will prevent us from configuring a
- # dump save area before a hostname has been configured (i.e after
- # sys-unconfig has been invoked).
- #
- [ -z "$DUMPADM_SAVDIR" ] && return
-
- #
- # If we have a dedicated dump device, then go ahead and configure it.
- #
- if [ "x$special" != "x$DUMPADM_DEVICE" ]; then
- if [ -x /usr/sbin/dumpadm -a -b $DUMPADM_DEVICE ]; then
- /usr/sbin/dumpadm -u || exit $SMF_EXIT_ERR_CONFIG
- fi
- fi
-}
-
-#
-# Write a unique id into this kernel image; this will be included
-# in the dump header and panicbuf of any crashdump of this image.
-#
-if [ -x /usr/sbin/dumpadm ]; then
- /usr/sbin/dumpadm -i
-fi
-
-rootiszfs=0
-# get the fstype of root
-readmnttab / </etc/mnttab
-if [ "$fstype" = zfs ] ; then
- rootiszfs=1
- dump_setup
-fi
-
-#
-# Add physical swap.
-#
-/sbin/swapadd -1
-#
-# Check and remount the / (root) file system.
-# For NFS mounts, force the llock option on.
-#
-if smf_is_globalzone && [ $rootiszfs = 0 ]; then
- readvfstab / < $vfstab
- checkfs $fsckdev $fstype $mountp || exit $SMF_EXIT_ERR_FATAL
- checkopt "llock" $mntopts
- mntopts='remount'
-
- [ -n "$otherops" ] && mntopts="${mntopts},${otherops}"
- [ "$fstype" = nfs ] && mntopts="${mntopts},llock"
-
- mountfs -m $mountp $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
-fi
-
-#
-# Check and remount the /usr file system (formerly mounted read-only).
-# Unless root is zfs, in which case we've already mounted /usr read-write
-#
-if [ "$rootiszfs" = 0 ] ; then
- readvfstab /usr < $vfstab
- if [ "$mountp" ]; then
- checkopt ro $mntopts
- if [ "x$option" != xro ]; then
- checkfs $fsckdev $fstype $mountp ||
- exit $SMF_EXIT_ERR_FATAL
- if [ "x$mntopts" != x- ]; then
- mntopts="remount,$mntopts"
- else
- mntopts="remount"
- fi
-
- mountfs - /usr $fstype $mntopts - ||
- exit $SMF_EXIT_ERR_FATAL
- fi
- fi
-fi
-
-#
-# Check and mount the /usr/platform file system. This should only be
-# present when a SunOS 5.5 (Solaris 2.5) or greater client is being
-# administered by a SunOS 5.4 or less host.
-#
-readvfstab /usr/platform < $vfstab
-if [ "$mountp" ]; then
- checkfs $fsckdev $fstype $mountp || exit $SMF_EXIT_ERR_FATAL
- mountfs - $mountp $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
-fi
-
-#
-# Mount the fd file systems if mount point exists.
-#
-readvfstab /dev/fd < $vfstab
-if [ "$mountp" -a -d /dev/fd ]; then
- mountfs - /dev/fd - - - || exit $SMF_EXIT_ERR_FATAL
-fi
+mount /dev/fd
-if [ -f "${UPDATEFILE}" ]; then
- /usr/sbin/bootadm update-archive
- if [ $? != 0 ]; then
- cecho ""
- cecho "WARNING: Automatic update of the boot archive failed."
- cecho "Update the archives using 'bootadm update-archive'"
- cecho "command and then reboot the system from the same device that"
- cecho "was previously booted."
- cecho ""
- exit $SMF_EXIT_ERR_FATAL
- fi
- rm -f $UPDATEFILE
- bootcmd=`/usr/sbin/eeprom bootcmd | /usr/bin/sed -e 's#bootcmd=##g'`
- if [ `uname -p` = "i386" ]; then
- /usr/sbin/reboot -f dryrun
- if [ $? = 0 ]; then
- /usr/sbin/reboot -f -- "$bootcmd"
- exit $SMF_EXIT_OK
- fi
- boot_prop=`/usr/sbin/svccfg -s svc:/system/boot-config:default listprop config/auto-reboot-safe | \
- /usr/bin/nawk '{ print $3}'`
- if [ "$boot_prop" != "true" ]; then
- cecho ""
- cecho "WARNING: Reboot required."
- cecho "The system has updated the cache of files (boot archive) that is used"
- cecho "during the early boot sequence. To avoid booting and running the system"
- cecho "with the previously out-of-sync version of these files, reboot the"
- cecho "system from the same device that was previously booted."
- cecho ""
- exit $SMF_EXIT_ERR_FATAL
- else
- /usr/sbin/reboot -p
- exit $SMF_EXIT_OK
- fi
- fi
- /usr/sbin/reboot -- "$bootcmd"
+if smf_is_globalzone; then
+ # svc.startd makes a backup of the repo on boot. Since this is a
+ # live-image, the backup takes up an unnecessary 4MB in memory, so remove
+ # it now.
+ rm -f /etc/svc/repository-*
fi
exit $SMF_EXIT_OK
diff --git a/usr/src/cmd/svc/milestone/identity-node b/usr/src/cmd/svc/milestone/identity-node
index c9b20ba669..6b740f3dd1 100644
--- a/usr/src/cmd/svc/milestone/identity-node
+++ b/usr/src/cmd/svc/milestone/identity-node
@@ -27,18 +27,30 @@
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# ident "%Z%%M% %I% %E% SMI"
+# Copyright 2019 Joyent, Inc.
+#
. /lib/svc/share/smf_include.sh
. /lib/svc/share/net_include.sh
+set -o xtrace
+
# Make sure that the libraries essential to this stage of booting can be found.
LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
#
-# If DHCP was used on a primary interface then set the hostname
-# that was returned. If no hostname was returned, set the name
-# to be "unknown". The hostname must be set to something, because
+# For the GZ, use one of the following values for hostname, in order:
+# * DHCP hostname (if set on a primary interface)
+# * hostname value from config file
+# * hostname bootparam
+# * if not a headnode:
+# * admin MAC address
+# * any other MAC address
+#
+# If none of the above could be found, default to "headnode" for headnodes, and
+# "unknown" for non-headnodes.
+#
+# The hostname must be set to something, because
# tooltalk will hang unless the name can be locally resolved.
# Sendmail also requires the name to be resolvable locally.
# Later, in inetsvc, we create a name "unknown" and create a entry
@@ -51,44 +63,124 @@ LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
# kernel if /etc/nodename does not exist, as is expected on an initial boot.
#
+set_gz_hostname() {
+ hostname=${CONFIG_hostname}
+ if [ -z "$hostname" ] || [ "$hostname" == "unknown" ]; then
+ hostname=$SYSINFO_Bootparam_hostname
+ fi
+
+ if [ -n "$hostname" ] && [ "$hostname" != "unknown" ]; then
+ return
+ fi
+
+ # $headnode is set by load_sdc_config()
+ if [ "$headnode" == "true" ]; then
+ hostname="headnode"
+ return
+ fi
+
+ if [[ -n ${SYSINFO_NIC_admin} ]]; then
+ eval "admin_mac=\${SYSINFO_Network_Interface_${SYSINFO_NIC_admin}_MAC_Address}"
+ if [[ -n ${admin_mac} ]]; then
+ hostname=$(echo "${admin_mac}" | tr ':' '-')
+ return
+ fi
+ fi
+
+ fallback_mac=$(set | grep "^SYSINFO_Network_Interface_.*_MAC_Address" | head -n1 | cut -d'=' -f2)
+ if [[ -n ${fallback_mac} ]]; then
+ hostname=$(echo "${fallback_mac}" | tr ':' '-')
+ return
+ fi
+
+ hostname="unknown"
+}
+
+
smf_netstrategy
case "$_INIT_NET_STRATEGY" in
- "dhcp") hostname=`/sbin/dhcpinfo Hostname` ;;
- "rarp") hostname=`/sbin/hostconfig -h -p bootparams`
- trap 'intr=1' 2 3
- while [ -z "$hostname" -a ! -f /etc/.UNCONFIGURED -a \
- -z "$intr" ]; do
- echo "re-trying host configuration..."
- # Restrict this to IPv4 interfaces.
- /sbin/ifconfig -adD4 auto-revarp up
- hostname=`/sbin/hostconfig -h -p bootparams`
- done
- trap 2 3 ;;
- "none") hostname="`shcat /etc/nodename 2>/dev/null`"
- if [ -z "$hostname" ]; then
- if smf_is_globalzone; then
- hostname=`/sbin/hostconfig -h -p bootparams`
- else
- hostname=`/sbin/uname -n`
- fi
- fi ;;
+ "dhcp") hostname=`/sbin/dhcpinfo Hostname` ;;
+ "rarp") hostname=`/sbin/hostconfig -h -p bootparams`
+ trap 'intr=1' 2 3
+ while [ -z "$hostname" -a ! -f /etc/.UNCONFIGURED -a \
+ -z "$intr" ]; do
+ echo "re-trying host configuration..."
+ # Restrict this to IPv4 interfaces.
+ /sbin/ifconfig -adD4 auto-revarp up
+ hostname=`/sbin/hostconfig -h -p bootparams`
+ done
+ trap 2 3 ;;
+ # /etc/nodename defaults to "unknown" on SmartOS
+ "none") hostname="`shcat /etc/nodename 2>/dev/null`"
+ if [ -z "$hostname" ]; then
+ if smf_is_globalzone; then
+ hostname=`/sbin/hostconfig -h -p bootparams`
+ else
+ hostname=`/sbin/uname -n`
+ fi
+ fi ;;
esac
+# Load sysinfo variables with SYSINFO_ prefix and config variables with
+# CONFIG_ prefix.
+# Note: since we're still starting up, "soft" values like network IP and such could
+# not be set yet.
+
+if smf_is_globalzone; then
+ . /lib/sdc/config.sh
+
+ load_sdc_sysinfo
+
+ if boot_file_config_enabled; then
+ load_boot_file_config
+ else
+ load_sdc_config
+ fi
+fi
+
#
# If the netstrategy was unsuccessful and we haven't got a locally configured
# name, default to "unknown"
#
-if [ -z "$hostname" ]; then
- hostname="`shcat /etc/nodename 2>/dev/null`"
- if [ -z "$hostname" ]; then
- hostname="unknown"
- fi
+if [ -z "$hostname" ] || [ "$hostname" == "unknown" ]; then
+ hostname="`shcat /etc/nodename 2>/dev/null`"
+ if [ -z "$hostname" ] || [ "$hostname" == "unknown" ]; then
+ if smf_is_globalzone; then
+ set_gz_hostname
+ else
+ hostname="unknown"
+ fi
+ fi
+fi
+
+if smf_is_globalzone; then
+ echo "$hostname" > /etc/nodename
fi
/sbin/uname -S $hostname
-echo "Hostname: `/sbin/uname -n`" > /dev/msglog
+# Reloading sysinfo here serves two purposes:
+# - getting the IP info (which should exist now)
+# - updating the host info (which we just set)
+eval $(/usr/bin/sysinfo -f -p | sed -e "s/^/SYSINFO_/")
+
+# Try to add the /etc/hosts entry if we can find an IP
+if [[ -n ${SYSINFO_NIC_admin} ]]; then
+ eval "ipaddr=\${SYSINFO_Network_Interface_${SYSINFO_NIC_admin}_IPv4_Address}"
+fi
+if [[ -z ${ipaddr} ]]; then
+ ipaddr=$(set | grep "^SYSINFO_Network_Interface_.*_IPv4_Address" | head -n1 | cut -d'=' -f2)
+fi
+if [[ -n ${ipaddr} ]]; then
+ fullname=""
+
+ if [ -n "$CONFIG_dns_domain" ]; then
+ fullname=" ${hostname}.${CONFIG_dns_domain}"
+ fi
+
+ printf "${ipaddr}\t${hostname}${fullname}\n" >> /etc/hosts
+fi
# Reset the library path now that we are past the critical stage
unset LD_LIBRARY_PATH
diff --git a/usr/src/cmd/svc/milestone/joyent-fs.xml b/usr/src/cmd/svc/milestone/joyent-fs.xml
new file mode 100644
index 0000000000..3d004e8d33
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/joyent-fs.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0"?>
+<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
+<!--
+ Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ Use is subject to license terms.
+
+ CDDL HEADER START
+
+ The contents of this file are subject to the terms of the
+ Common Development and Distribution License, Version 1.0 only
+ (the "License"). You may not use this file except in compliance
+ with the License.
+
+ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ or http://www.opensolaris.org/os/licensing.
+ See the License for the specific language governing permissions
+ and limitations under the License.
+
+ When distributing Covered Code, include this CDDL HEADER in each
+ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ If applicable, add the following below this CDDL HEADER, with the
+ fields enclosed by brackets "[]" replaced with your own identifying
+ information: Portions Copyright [yyyy] [name of copyright owner]
+
+ CDDL HEADER END
+-->
+
+<service_bundle type='manifest' name='SUNWcsr:filesystem-joyent'>
+
+<service
+ name='system/filesystem/smartdc'
+ type='service'
+ version='1'>
+
+ <create_default_instance enabled='true' />
+
+ <single_instance/>
+
+ <dependency
+ name='usr'
+ grouping='require_all'
+ restart_on='none'
+ type='service'>
+ <service_fmri value='svc:/system/filesystem/usr' />
+ </dependency>
+
+ <!--
+ Start method timeout is infinite to handle potentially unbounded
+ fsck times.
+ -->
+ <exec_method
+ type='method'
+ name='start'
+ exec='/lib/svc/method/fs-joyent'
+ timeout_seconds='0' />
+
+ <exec_method
+ type='method'
+ name='stop'
+ exec=':true'
+ timeout_seconds='0' />
+
+ <property_group name='startd' type='framework'>
+ <propval name='duration' type='astring' value='transient' />
+ </property_group>
+ <property_group name='joyentfs' type='application'>
+ <stability value='Evolving'/>
+ <propval name='debug' type='boolean' value='false'/>
+ <propval name='usb_copy_path' type='astring' value='/usbkey'/>
+ <propval name='usb_mountpoint' type='astring' value='usbkey'/>
+ </property_group>
+
+
+ <stability value='Unstable' />
+
+ <template>
+ <common_name>
+ <loctext xml:lang='C'>
+ Joyent file system mounts
+ </loctext>
+ </common_name>
+ </template>
+</service>
+
+</service_bundle>
diff --git a/usr/src/cmd/svc/milestone/make-console-login-xml b/usr/src/cmd/svc/milestone/make-console-login-xml
index a8e516fe9f..2b78164e78 100644
--- a/usr/src/cmd/svc/milestone/make-console-login-xml
+++ b/usr/src/cmd/svc/milestone/make-console-login-xml
@@ -24,6 +24,8 @@
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
+# Copyright 2019 Joyent, Inc.
+#
cat >console-login.xml <<EOF
<?xml version="1.0"?>
@@ -31,6 +33,8 @@ cat >console-login.xml <<EOF
Copyright 2008 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
+ Copyright 2015 Joyent, Inc.
+
NOTE: This service manifest is not editable; its contents will
be overwritten by package or patch operations, including
operating system upgrade. Make customizations in a different
@@ -125,14 +129,14 @@ cat >console-login.xml <<EOF
<property_group name='ttymon' type='application'>
<propval name='value_authorization' type='astring'
value='solaris.smf.value.vt' />
- <propval name='device' type='astring' value='/dev/console' />
+ <propval name='device' type='astring' value='/dev/wscons' />
<propval name='label' type='astring' value='console' />
<propval name='timeout' type='count' value='0' />
<propval name='nohangup' type='boolean' value='true' />
<propval name='modules' type='astring'
value='ldterm,ttcompat' />
<propval name='prompt' type='astring'
- value='\`uname -n\` console login:' />
+ value='\`uname -n\` wscons login:' />
<propval name='terminal_type' type='astring'
value='' />
</property_group>
@@ -140,8 +144,39 @@ cat >console-login.xml <<EOF
<instance name='default' enabled='true'>
</instance>
+EOF
+
+for tty in a b c d; do
+ cat >>console-login.xml <<EOF
+<instance name='tty$tty' enabled='true'>
+
+ <dependency
+ name='system-console'
+ grouping='require_all'
+ restart_on='none'
+ type='service'>
+ <service_fmri value='svc:/system/console-login:default' />
+ </dependency>
+
+ <!-- these are passed to ttymon in the method script -->
+ <property_group name='ttymon' type='application'>
+ <propval name='value_authorization' type='astring'
+ value='solaris.smf.value.vt' />
+ <propval name='device' type='astring' value='/dev/term/$tty' />
+ <propval name='label' type='astring' value='115200' />
+ <propval name='timeout' type='count' value='0' />
+ <propval name='nohangup' type='boolean' value='true' />
+ <propval name='modules' type='astring'
+ value='ldterm,ttcompat' />
+ <propval name='prompt' type='astring'
+ value='\`uname -n\` tty$tty login:' />
+ <propval name='terminal_type' type='astring'
+ value='xterm' />
+ </property_group>
+</instance>
EOF
+done
# Note that this script file is normally parsed during build by sh(1).
# When the parser encounters an EOF token (like the one above), it
@@ -328,7 +363,7 @@ Sets the initial value of the TERM environment variable
<visibility value='readwrite'/>
<cardinality min='1' max='1'/>
</prop_pattern>
- </pg_pattern>
+ </pg_pattern>
</template>
</service>
diff --git a/usr/src/cmd/svc/milestone/manifest-import b/usr/src/cmd/svc/milestone/manifest-import
index 81cd780583..43fb677b92 100644
--- a/usr/src/cmd/svc/milestone/manifest-import
+++ b/usr/src/cmd/svc/milestone/manifest-import
@@ -74,13 +74,17 @@ function svccfg_apply {
}
#
-# If the smf repository has file entries that are missing
+# If the smf/manifest table has file entries that are missing
# then there is work to be done by the cleanup process.
#
function cleanup_needwork {
- smfmfiles=`svcprop -p manifestfiles '*' 2>/dev/null |
- nawk -v early="$early" '$2 == "astring" &&
- (early != "true" || $3 ~ "^/lib/") { print $3 }'`
+ if [ "$early" == true ]; then
+ smfmfiles=`/usr/bin/svcprop smf/manifest | \
+ awk '(/^lib_/ && /\/manifestfile /) {print $3}'`
+ else
+ smfmfiles=`/usr/bin/svcprop smf/manifest | \
+ awk '/\/manifestfile / {print $3}'`
+ fi
nw=`/lib/svc/bin/mfstscan $smfmfiles 2>&1 1>/dev/null`
[ "$nw" ] && return 1
@@ -201,8 +205,13 @@ function import_manifests {
rm -f $logf
- nonsite_dirs=`/usr/bin/find $basedir/* -name site \
- -prune -o -type d -print -prune`
+ if [ "${basedir}" == "/opt/custom/smf" ]; then
+ # Special case where we will just import from the root, not subdirs
+ nonsite_dirs=${basedir}
+ else
+ nonsite_dirs=`/usr/bin/find $basedir/* -name site \
+ -prune -o -type d -print -prune`
+ fi
if [ -n "$_MFST_DEBUG" ]; then
nonsite_manifests=`/lib/svc/bin/mfstscan $nonsite_dirs`
@@ -454,6 +463,10 @@ else
import_manifests "/lib/svc/manifest" true
import_manifests "/var/svc/manifest" true
+ if [ -d "/opt/custom/smf" ]; then
+ import_manifests "/opt/custom/smf" true
+ fi
+
#
# Apply profiles
#
@@ -472,9 +485,9 @@ fi
# 6. Final actions.
#
-if $activity; then
- /usr/sbin/svcadm _smf_backup "manifest_import" || true
-fi
+#if $activity; then
+# /usr/sbin/svcadm _smf_backup "manifest_import" || true
+#fi
#
# If the filesystem is NOT read only then move the repo back to perm
diff --git a/usr/src/cmd/svc/milestone/mdata-execute b/usr/src/cmd/svc/milestone/mdata-execute
new file mode 100755
index 0000000000..fca08ffbc7
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/mdata-execute
@@ -0,0 +1,53 @@
+#!/usr/bin/bash
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at http://smartos.org/CDDL
+#
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file.
+#
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright (c) 2012, Joyent, Inc. All rights reserved.
+#
+
+set -o xtrace
+
+. /lib/svc/share/smf_include.sh
+smf_is_globalzone && exit ${SMF_EXIT_OK}
+
+# If we got as far as running the user-script the 'provision' was a success
+# from here out a failure will leave the zone running.
+if [ -f /var/svc/provisioning ]; then
+ mv /var/svc/provision{ing,_success}
+fi
+
+if [[ -x /var/svc/mdata-operator-script ]]; then
+ /var/svc/mdata-operator-script
+ operator_script_exit=$?
+ if [[ ${operator_script_exit} -gt 0 ]]; then
+ echo "WARNING: operator-script failed: exited ${operator_script_exit}" \
+ >&2
+ fi
+fi
+
+user_script_exit=${SMF_EXIT_OK}
+if [ -x /var/svc/mdata-user-script ]; then
+ /var/svc/mdata-user-script
+ [ $? -gt 0 ] && user_script_exit=${SMF_EXIT_ERR_FATAL}
+fi
+
+exit ${user_script_exit}
diff --git a/usr/src/cmd/svc/milestone/mdata-fetch b/usr/src/cmd/svc/milestone/mdata-fetch
new file mode 100755
index 0000000000..cb7222f445
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/mdata-fetch
@@ -0,0 +1,477 @@
+#!/usr/bin/bash
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at http://smartos.org/CDDL
+#
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file.
+#
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright (c) 2017, Joyent, Inc. All rights reserved.
+#
+
+export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
+export PATH=/usr/bin:/usr/sbin:$PATH
+
+set -o xtrace
+
+. /lib/svc/share/smf_include.sh
+smf_is_globalzone && exit ${SMF_EXIT_OK}
+
+if [ ! -x /usr/sbin/mdata-get ]; then
+ echo "Metadata mdata-get tool not found."
+ exit ${SMF_EXIT_ERR_FATAL}
+fi
+
+function fatal() {
+ if [[ -n $1 ]]; then
+ echo "FATAL: $*" >&2
+ fi
+ exit ${SMF_EXIT_ERR_FATAL}
+}
+
+# Test if an address looks like an IPv4 address.
+function isIPv4() {
+ [[ "$1" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]
+}
+
+# Test if an address looks like an IPv4 address + CIDR.
+function isIPv4AndCIDR() {
+ [[ "$1" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}$ ]]
+}
+
+# Test if an address looks like an IPv6 address.
+function isIPv6() {
+ [[ "$1" =~ ^[0-9a-f]*:[0-9a-f]*:[:0-9a-f]*$ ]]
+}
+
+# Test if an address looks like an IPv6 address + CIDR.
+function isIPv6AndCIDR() {
+ [[ "$1" =~ ^[0-9a-f]*:[0-9a-f]*:[:0-9a-f]*/[0-9]{1,3}$ ]]
+}
+
+# For old zones that were created prior to OS-2253 and bumping the mdata:fetch
+# start timeout, we need to fix this otherwise we could timeout waiting for the
+# socket.
+cur_timeout=$(svcprop -p start/timeout_seconds svc:/smartdc/mdata:fetch)
+if [[ -z ${cur_timeout} || ${cur_timeout} -lt 1800 ]]; then
+ # The current manifest has an old timeout value, fix in case we timeout
+ # here. XXX we can still hit OS-2296 here where smf will forget that we
+ # set this.
+ svccfg -s svc:/smartdc/mdata:fetch 'setprop start/timeout_seconds = 1800'
+ svcadm refresh svc:/smartdc/mdata:fetch
+fi
+
+# This waits until /.zonecontrol/metadata.sock exists then exits 0
+/usr/vm/sbin/filewait /.zonecontrol/metadata.sock
+
+if [[ ! -e /.zonecontrol/metadata.sock ]]; then
+ # this is a bug since filewait should not have returned until file existed.
+ fatal "missing /.zonecontrol/metadata.sock, Unable to start mdata:fetch"
+fi
+
+# Update sysinfo to ensure values that come from metadata are populated.
+/usr/bin/sysinfo -fu
+
+echo "Retrieving metadata user-data"
+/usr/sbin/mdata-get user-data >/var/db/mdata-user-data.new
+case $? in
+ 0)
+ echo "Metadata user-data successfuly retrieved."
+ mv /var/db/mdata-user-data{.new,}
+ ;;
+ 1)
+ echo "Metadata user-data not defined."
+ rm -f /var/db/mdata-user-data{,.new}
+ ;;
+ *)
+ echo "Metadata couldn't be retrieved."
+ exit ${SMF_EXIT_ERR_FATAL}
+ ;;
+esac
+
+echo "Retrieving metadata user-script..."
+/usr/sbin/mdata-get user-script >/var/svc/mdata-user-script.new
+case $? in
+ 0)
+ echo "Metadata user-script successfuly retrieved."
+ mv /var/svc/mdata-user-script{.new,}
+ chmod +x /var/svc/mdata-user-script
+ ;;
+ 1)
+ echo "Metadata user-script not defined."
+ rm -f /var/svc/mdata-user-script{,.new}
+ ;;
+ *)
+ echo "Metadata couldn't be retrieved."
+ exit ${SMF_EXIT_ERR_FATAL}
+ ;;
+esac
+
+echo "Retrieving metadata operator-script..."
+/usr/sbin/mdata-get sdc:operator-script >/var/svc/mdata-operator-script.new
+case $? in
+ 0)
+ echo "Metadata operator-script successfuly retrieved."
+ mv /var/svc/mdata-operator-script{.new,}
+ chmod +x /var/svc/mdata-operator-script
+ ;;
+ 1)
+ echo "Metadata operator-script not defined."
+ rm -f /var/svc/mdata-operator-script{,.new}
+ ;;
+ *)
+ echo "Metadata couldn't be retrieved."
+ exit ${SMF_EXIT_ERR_FATAL}
+ ;;
+esac
+
+echo "Retrieving tmpfs value..."
+tmpfs=$(/usr/sbin/mdata-get sdc:tmpfs)
+if [[ $? == 0 && -n ${tmpfs} && -f /etc/vfstab ]]; then
+ check="swap - /tmp tmpfs";
+
+ if [[ ${tmpfs} == "0" ]]; then
+ # When tmpfs is set 0, we remove any entry from /etc/vfstab but cannot
+ # adjust the "live" value as current /tmp will be in-use. On reboot the
+ # new value will take effect.
+
+ grep -v "^${check}" /etc/vfstab > /etc/vfstab.new \
+ && mv /etc/vfstab.new /etc/vfstab
+ else
+ new="swap - /tmp tmpfs - yes size=${tmpfs}m";
+ if ! /usr/bin/grep "^${new}" /etc/vfstab; then
+ if ! /usr/bin/grep "^${check}" /etc/vfstab; then
+ # no tmpfs line. add it.
+ echo "${new}" >> /etc/vfstab
+ else
+ # existing tmpfs line, but wrong value. fix it.
+ /usr/bin/sed -i "" -e "s|^swap.*/tmp.*tmpfs.*$|${new}|" /etc/vfstab
+ echo $?
+ fi
+
+ if mount | grep "^/tmp"; then
+ # Also fix current size, since /etc/vfstab didn't have our correct line
+ # but only if we have /tmp mounted at all. If not, we'll have to wait
+ # until the next reboot since /tmp will be in-use.
+ /usr/sbin/mount -F tmpfs -o remount,size=${tmpfs}m /tmp
+ fi
+
+ fi
+ fi
+fi
+
+#
+# If we have NFS volumes, we'll add them to vfstab, and enable the nfs/client
+# service so that will mount the volumes for us.
+#
+echo "Retrieving volume metadata..."
+
+volumes_added=0
+while IFS="|" read -r nfsvolume mountpoint name mode type; do
+
+ cat >&2 <<EOF
+*** VOLUME ***
+NFSVOLUME: ${nfsvolume}
+MOUNTPOINT: ${mountpoint}
+MODE: ${mode}
+NAME: ${name}
+TYPE: ${type}
+EOF
+
+ if [[ -n ${type} && ${type} != "tritonnfs" ]]; then
+ fatal "unsupported volume type: ${type}"
+ fi
+
+ # if we don't have volume and mountpoint, we can't add vfstab lines
+ if [[ -z ${nfsvolume} || -z ${mountpoint} ]]; then
+ fatal "invalid volume specification (need both volume & mountpoint)"
+ fi
+
+ if ! grep "^${nfsvolume}[ ]" /etc/vfstab; then
+ if [[ -z ${mode} ]]; then
+ mode="rw"
+ fi
+
+ if [[ ${mode} != "rw" && ${mode} != "ro" ]]; then
+ fatal "invalid volume mode: '${mode}'"
+ fi
+
+ line=$(printf "%s - %s nfs - yes %s\n" "${nfsvolume}" "${mountpoint}" "${mode}")
+ volumes_added=$((${volumes_added}+1))
+
+ mkdir -p ${mountpoint}
+ echo "${line}" >> /etc/vfstab
+ fi
+done < <(/usr/sbin/mdata-get sdc:volumes \
+ | /usr/bin/json \
+ -d '|' \
+ -a nfsvolume mountpoint name mode type)
+
+if [[ ${volumes_added} -gt 0 ]]; then
+ for svc in \
+ svc:/network/nfs/nlockmgr:default \
+ svc:/network/nfs/status:default \
+ svc:/network/rpc/bind:default \
+ svc:/network/nfs/client:default \
+ ; do
+
+ svcadm enable ${svc} || fatal "Unable to enable ${svc}"
+ done
+fi
+
+# We use the special sdc:nics value here though this is not an interface for
+# use elsewhere. If this is changed please also update agent.js in the metadata
+# agent.
+#
+# We run this every startup in case nics have changed since last boot. As
+# network/physical has an optional_all dependency on this service, we'll have
+# had our chance to write these files out before networking comes up. This
+# might eventually be replaced by network/physical grabbing data directly.
+echo "Retrieving nics data..."
+while IFS="|" read -r iface ip ips netmask primary gateway gateways; do
+
+ # if we don't have interface name, we don't know what files to write out.
+ if [[ -z ${iface} ]]; then
+ continue;
+ fi
+
+ # A VM created on an older platform may not have the "ips" or "gateways"
+ # properties, so we will need to grab the older "ip" and "gateway" versions
+ # instead.
+ [[ -z $ips ]] && ips=$ip
+ [[ -z $gateways ]] && gateways=$gateway
+
+ # We remove the hostname.netX file first, so we can append to a clean file
+ rm -f /etc/hostname.${iface}
+
+ # remove any existing DHCP or addrconf configuration, since we'll create one
+ # if it belongs later
+ rm -f /etc/dhcp.${iface}
+ rm -f /etc/addrconf.${iface}
+
+ OLDIFS=$IFS
+ IFS=$','
+ for ip in $ips; do
+ # so it shows up in the logs
+ echo "iface[${iface}] ip[${ip}] netmask[${netmask}]" \
+ "primary[${primary}] gateway[${gateway}]"
+
+ [[ -z ${ip} ]] && continue;
+
+ if [[ ${ip} == "dhcp" ]]; then
+ touch /etc/dhcp.${iface}
+ if hostname=`mdata-get sdc:hostname`; then
+ echo "inet ${hostname}" >> /etc/hostname.${iface}
+ fi
+ elif [[ ${ip} == "addrconf" ]]; then
+ touch /etc/addrconf.${iface}
+ elif isIPv4 ${ip} && [[ -n ${netmask} ]]; then
+ # We're using an older configuration where the routing prefix is
+ # specified using a mask instead of CIDR notation. We'll need to
+ # invoke ifconfig differently.
+ echo "${ip} netmask ${netmask} up" >> /etc/hostname.${iface}
+ elif isIPv4AndCIDR ${ip} \
+ || isIPv6AndCIDR ${ip} \
+ || isIPv6 ${ip}; then
+ # Either a routing prefix was specified, or, in the case of IPv6, we
+ # won't specify one and fall back on NDP to find it when we configure
+ # our interfaces.
+ echo "${ip} up" >> /etc/hostname.${iface}
+ fi
+ done
+
+ if [[ ${primary} == "true" ]]; then
+ rm -f /etc/defaultrouter
+ for gateway in $gateways; do
+ if [[ -n ${gateway} ]] && isIPv4 ${gateway}; then
+ echo "${gateway}" >> /etc/defaultrouter
+ fi
+ done
+ fi
+ IFS=$OLDIFS
+
+ # XXX we leave old hostname.netX files around and just replace when we have
+ # one next.
+done < <(/usr/sbin/mdata-get sdc:nics \
+ | /usr/bin/json \
+ -d '|' \
+ -e 'this.ips = this.ips ? this.ips.join(",") : ""' \
+ -e 'this.gateways = this.gateways ? this.gateways.join(",") : ""' \
+ -a interface ip ips netmask primary gateway gateways)
+
+# rebuild resolv.conf
+resolvers=$(mdata-get sdc:resolvers)
+resolvers_result=$?
+
+# Determine if resolv.conf is managed for us
+maintain_resolvers=$(mdata-get sdc:maintain_resolvers)
+maintain_result=$?
+if [[ ${maintain_result} != 0 ]]; then
+ echo "Error getting maintain_resolvers, code: ${maintain_result}"
+ maintain_resolvers="false"
+fi
+
+# If this is our first boot, write an initial set of resolvers
+if [[ -f /var/svc/provisioning ]]; then
+ echo "First boot: writing resolvers"
+ maintain_resolvers="true"
+fi
+
+if [[ ${resolvers_result} == 0 && ${maintain_resolvers} == "true" ]]; then
+
+ # if dns_domain is missing or broken, we still write out, just w/o search
+ search="search $(mdata-get sdc:dns_domain)"
+ if [[ $? != 0 ]]; then
+ search=
+ fi
+
+ if [[ ${resolvers} == "[]" ]]; then
+ nameservers=
+ else
+ nameservers=$(echo ${resolvers} | json -a | sed -e "s/^/nameserver /")
+ fi
+
+ rm -f /etc/.resolv.conf.tmp
+ if [[ -n ${search} ]]; then
+ echo "${search}" > /etc/.resolv.conf.tmp
+ fi
+ if [[ -n ${nameservers} ]]; then
+ echo "${nameservers}" >> /etc/.resolv.conf.tmp
+ fi
+
+ cp /etc/.resolv.conf.tmp /etc/resolv.conf \
+ && cat /etc/.resolv.conf.tmp >&2 \
+ && rm -f /etc/.resolv.conf.tmp
+else
+ if [[ ${resolvers_result} == 0 ]]; then
+ echo "Error getting resolvers, code: ${resolvers_result}"
+ fi
+
+ if [[ ${maintain_resolvers} == "true" ]]; then
+ echo "Not setting resolvers, maintain_resolvers=${maintain_resolvers}"
+ fi
+fi
+
+
+# Fetch routes
+
+# It is possible to specify the same route in several different ways using
+# route(1m). We therefore use route(1m) itself to manage adding, deleting
+# and determining duplicates.
+zone_routes_file=/etc/inet/static_routes
+vmadm_routes_file=/etc/inet/static_routes.vmadm
+tmpdir=$(mktemp -d /tmp/mdata.XXXXXX)
+
+if [ -z $tmpdir ]; then
+ echo "Error creating temporary directory."
+ exit ${SMF_EXIT_ERR_FATAL}
+fi
+
+# directory structure for the new copy of static_routes.vmadm (the one that
+# will replace the current static_routes.vmadm once all of the adds and
+# deletes have been applied):
+new_root=${tmpdir}/new-routes
+new_inet=${new_root}/etc/inet
+# directory structure for the previous copy of static_routes.vmadm (used to
+# determine routes that have been removed since the last time mdata-fetch
+# was run):
+old_root=${tmpdir}/old-routes
+old_inet=${old_root}/etc/inet
+# directory structure for the zone's persistent routes - those not created
+# by vmadm (used to determine if vmadm routes are duplicates):
+zone_root=${tmpdir}/zone-routes
+zone_inet=${zone_root}/etc/inet
+
+mkdir -p $new_inet
+mkdir -p ${old_root}/etc/inet
+mkdir -p ${zone_root}/etc/inet
+
+if [[ -f ${vmadm_routes_file} ]]; then
+ cp $vmadm_routes_file ${old_inet}/static_routes
+fi
+
+function route_in_per_zone_file()
+{
+ cp $zone_routes_file $zone_inet
+ output=$(route -pR $zone_root add $* 2>&1)
+ [[ $output =~ "entry exists" ]]
+}
+
+# If re-running this script after initial boot, network/physical and
+# network/routing-setup are already enabled, so apply routing adds and
+# deletes manually
+if [[ $(/usr/bin/svcs -H -o state network/routing-setup) == "online" ]]; then
+ routing_up="true"
+fi
+
+while IFS="|" read -r gateway dst linklocal; do
+ echo "route: gateway[${gateway}] dst[${dst}] linklocal[${linklocal}]"
+ route_type=""
+ if [[ ${linklocal} == "true" ]]; then
+ route_type="-interface "
+ fi
+ route_str="${route_type}${dst} ${gateway}"
+
+ if route_in_per_zone_file $route_str; then
+ echo "not adding duplicate route: ${route_str}"
+ # the zone has also defined this route; do nothing
+ else
+ echo "adding route to file: ${route_str}"
+ route -pR $new_root add $route_str
+ if [[ -n "${routing_up}" ]]; then
+ route add $route_str
+ fi
+ fi
+
+ route -pR $old_root delete $route_str
+done < <(/usr/sbin/mdata-get sdc:routes \
+ | /usr/bin/json -d '|' -a gateway dst linklocal)
+
+
+# Anything left in the old static_routes file is a delete. Don't delete the
+# route from the routing tables if there's a duplicate route in the zone's
+# static_routes file
+if [[ -f ${old_inet}/static_routes ]]; then
+ egrep -v "^(#|$)" ${old_inet}/static_routes | while read -r route_str; do
+ if [[ "${route_str}" == "" ]]; then
+ continue
+ fi
+
+ if route_in_per_zone_file "$route_str"; then
+ echo "not deleting duplicate route: ${route_str}"
+ else
+ if [[ -n "${routing_up}" ]]; then
+ route delete $route_str
+ fi
+ fi
+ done
+fi
+
+if [[ -f ${new_inet}/static_routes ]]; then
+ cp ${new_inet}/static_routes ${vmadm_routes_file}
+else
+ rm ${vmadm_routes_file}
+fi
+rm -rf $tmpdir
+
+
+# Unconditionally enable mdata:execute, so that the last provisioning step
+# is always taken (regardless of whether user-script exists or not)
+svcadm enable smartdc/mdata:execute
+
+exit ${SMF_EXIT_OK}
diff --git a/usr/src/cmd/svc/milestone/mdata.xml b/usr/src/cmd/svc/milestone/mdata.xml
new file mode 100644
index 0000000000..152a7cb485
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/mdata.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
+<service_bundle type="manifest" name="mdata">
+ <service name="smartdc/mdata" type="service" version="1">
+ <dependency name="filesystem" grouping="require_all" restart_on="error" type="service">
+ <service_fmri value="svc:/system/filesystem/minimal" />
+ </dependency>
+ <property_group name="startd" type="framework">
+ <propval name="duration" type="astring" value="transient" />
+ <propval name="ignore_error" type="astring" value="core,signal" />
+ </property_group>
+ <instance name="fetch" enabled="true">
+ <dependency name="boot-file" grouping="exclude_all" restart_on="refresh" type="path">
+ <service_fmri value="file://localhost/tmp/.FIRST_REBOOT_NOT_YET_COMPLETE"/>
+ </dependency>
+ <dependency name="rmtmpfiles" grouping="optional_all" restart_on="error" type="service">
+ <service_fmri value="svc:/system/rmtmpfiles" />
+ </dependency>
+ <exec_method type="method" name="start" exec="/lib/svc/method/mdata-fetch" timeout_seconds="1800" />
+ <exec_method type="method" name="stop" exec=":true" timeout_seconds="60" />
+ </instance>
+ <instance name="execute" enabled="false">
+ <dependency name="network" grouping="require_all" restart_on="error" type="service">
+ <service_fmri value="svc:/milestone/multi-user:default" />
+ </dependency>
+ <dependency name="mdata" grouping="require_all" restart_on="error" type="service">
+ <service_fmri value="svc:/smartdc/mdata:fetch" />
+ </dependency>
+ <exec_method type="method" name="start" exec="/lib/svc/method/mdata-execute" timeout_seconds="300" />
+ <exec_method type="method" name="stop" exec=":true" timeout_seconds="60" />
+ </instance>
+ <stability value="Evolving" />
+ <template>
+ <common_name>
+ <loctext xml:lang="C">Joyent SDC metadata handler</loctext>
+ </common_name>
+ </template>
+ </service>
+</service_bundle>
diff --git a/usr/src/cmd/svc/milestone/minimal-fs.xml b/usr/src/cmd/svc/milestone/minimal-fs.xml
index b7af22bfcd..844760baa1 100644
--- a/usr/src/cmd/svc/milestone/minimal-fs.xml
+++ b/usr/src/cmd/svc/milestone/minimal-fs.xml
@@ -44,11 +44,11 @@
<single_instance/>
<dependency
- name='usr'
+ name='joyent'
grouping='require_all'
restart_on='none'
type='service'>
- <service_fmri value='svc:/system/filesystem/usr' />
+ <service_fmri value='svc:/system/filesystem/smartdc' />
</dependency>
<dependency
diff --git a/usr/src/cmd/svc/milestone/net-early-admin b/usr/src/cmd/svc/milestone/net-early-admin
new file mode 100644
index 0000000000..abfd5fbdd7
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/net-early-admin
@@ -0,0 +1,214 @@
+#!/bin/ksh93
+#
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2019 Joyent, Inc.
+#
+
+# Traditionally, when a Triton compute node boots, the network is not
+# configured until after the local filesystems are mounted (in fact
+# network/physical:default depends upon /system/filesystem/smartdc). Most
+# obviously, in the case of a head node or a standalone SmartOS install, the
+# network configuration is stored on the local zpool, so the network cannot
+# be configured until this happens.
+#
+# For Triton compute nodes with encrypted zpools, we must enable the admin
+# network before the local zpool filesytems are online -- we have to be able
+# to communicate to the head node services to obtain the pin to unlock the
+# local zpool. For PXE booted Triton compute nodes, we therefore configure
+# the admin network sooner via the network/early-admin:default service. When
+# network/physical:default runs, it will skip the configuration of the admin
+# network and configuring the remaining interfaces.
+#
+# If we are not a Triton compute node, we exit successfully almost immediately
+# without configuring the admin network. When the network/physical:default
+# service runs, it will configure all the network interfaces as it traditionally
+# has
+
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+. /lib/svc/share/smf_include.sh
+. /lib/sdc/config.sh
+. /lib/sdc/network.sh
+
+PS4='+ [$LINENO] '
+
+set -o xtrace
+
+if ! smf_is_globalzone; then
+ echo "Non-global zone; no action required; exiting"
+ exit $SMT_EXIT_OK
+fi
+
+if ! boot_file_config_enabled; then
+ echo "Boot-time networking files not present; exiting"
+ exit $SMF_EXIT_OK
+fi
+
+function fatal
+{
+ # XXX: For SMF methods, does it matter/better to redirect to stderr?
+ echo "Error: $*" >&2
+ exit $SMF_EXIT_ERR_FATAL
+}
+
+if ! boot_file_config_valid; then
+ echo "ERROR: boot-time network config file incorrect" >&2
+ exit $SMF_EXIT_ERR_CONFIG
+fi
+
+unset aggrs
+unset tags
+typeset -A tagv
+typeset -A aggr_links aggr_mode
+typeset -A ip ip6 netmask gateway gateway6 mtu mac
+/usr/lib/sdc/net-boot-config | while IFS="=" read var value; do
+ if [[ "$var" =~ _nic$ ]]; then
+ name=${var%_nic}
+ tags+=("${name}")
+ tagv[$name]="$value"
+ elif [[ "$var" =~ _aggr$ ]]; then
+ name=${var%_aggr}
+ aggrs+=(${name})
+ aggr_links[$name]="${value//,/ }"
+ elif [[ "$var" =~ _lacp_mode$ ]]; then
+ name=${var%_lacp_mode}
+ aggr_mode[$name]="$value"
+ elif [[ "$var" =~ _mtu$ ]]; then
+ (( value < 1500 || value > 9000 )) &&
+ fatal "ERROR: $var MTU value \'$value\' is not in" \
+ "range [1500, 9000]"
+
+ name=${var%_mtu}
+ mtu[$name]="$value"
+ elif [[ "$var" =~ _ip$ ]]; then
+ name=${var%_ip}
+ ip[$name]="$value"
+ elif [[ "$var" =~ _ip6$ ]]; then
+ name=${var%_ip6}
+ ip6[$name]="$value"
+ elif [[ "$var" =~ _netmask$ ]]; then
+ name=${var%_netmask}
+ netmask[$name]="$value"
+ elif [[ "$var" =~ _gateway$ ]]; then
+ name=${var%_gateway}
+ gateway[$name]="$value"
+ elif [[ "$var" =~ _gateway6$ ]]; then
+ name=${var%_gateway6}
+ gateway6[$name]="$value"
+ elif [[ "$var" =~ _mac$ ]]; then
+ name=${var%_mac}
+ mac[$name]="$value"
+ elif [[ "$var" == "dns_resolvers" ]]; then
+ dns_resolvers=(${value//,/ })
+ fi
+
+ eval "CONFIG_$var"="$value"
+done
+
+# This must happen befor any other dladm commands (which includes log_if_state)
+# or else dladm commands can fail
+dladm init-phys
+
+log_if_state before
+
+typeset -A mac_to_link
+out=$(dladm show-phys -mpo link,address)
+(( $? == 0 )) || fatal "dladm show-phys failed"
+while IFS=: read link addr; do
+ mac=$(normalize_mac $addr)
+ mac_to_link["$mac"]="$link"
+done <<< "$out"
+
+ADMIN_NIC_TAG=${CONFIG_admin_tag:-"admin"}
+[[ -n "${tagv[$ADMIN_NIC_TAG]}" ]] || \
+ fatal "ERROR: admin nic tag '$ADMIN_NIC_TAG' not present"
+
+nic="${tagv[$ADMIN_NIC_TAG]}"
+
+if [[ -n "${aggr_links[$nic]}" ]]; then
+ mode=${aggr_mode[$nic]:-"off"}
+
+ for l in ${aggr_links[$nic]}; do
+ [[ -n "${mac_to_link[$l]}" ]] || fatal "MAC '$l' not present"
+ links+="${mac_to_link[$l]} "
+ done
+ links="${links% }"
+
+ echo "Creating aggr: $nic (mode=$mode, links=${links})"
+ dladm create-aggr -l ${links// / -l } -L $mode $nic
+
+ if [[ -n "${mtu[$nic]}" ]]; then
+ dladm set-linkprop -p mtu=${mtu[$nic]} $nic || \
+ fatal "ERROR: Failed to set mtu on aggr $nic to ${mtu[$nic]}"
+ fi
+elif valid_mac "$nic"; then
+ [[ -n "${mac_to_link[$nic]}" ]] || \
+ fatal "ERROR: admin mac address $nic not found on system"
+ nic=${mac_to_link[$nic]}
+else
+ fatal "ERROR: Invalid value of ${ADMIN_NIC_TAG}_nic ($nic)"
+fi
+
+driver=${nic%%[0-9]*}
+get_link_state $nic
+if [[ "$link_state" == "down" ]]; then
+ echo "admin nic '${nic}' is down: unplumbing"
+ /sbin/ifconfig $nic down unplumb
+ wait_for_nic_state $nic "unknown"
+fi
+
+# There's some sort of race condition in the bnx driver: if the plumb
+# command comes too soon after the unplumb, the interface can come up
+# in a state where it never fires interrupts for link state changes.
+if [[ "$driver" == "bnx" ]]; then
+ sleep 5
+fi
+
+/sbin/ifconfig $nic plumb mtu ${mtu[$ADMIN_NIC_TAG]}
+wait_for_nic_state $nic "up"
+
+if [[ -n "${ip[$ADMIN_NIC_TAG]}" ]]; then
+ /sbin/ifconfig $nic inet ${ip[$ADMIN_NIC_TAG]} \
+ netmask ${netmask[$ADMIN_NIC_TAG]:-"+"} up
+ [[ -n "${gateway[$ADMIN_NIC_TAG]}" ]] && \
+ /usr/sbin/route add default ${gateway[$ADMIN_NIC_TAG]}
+fi
+
+if [[ -n "${ip6[$ADMIN_NIC_TAG]}" ]]; then
+ /sbin/ifconfig $nic inet6 plumb mtu ${mtu[$ADMIN_NIC_TAG]}
+ [[ "${ip6[$ADMIN_NIC_TAG]}" != "addrconf" ]] && \
+ /sbin/ifconfig $nic inet6 addif ${ip6[$ADMIN_NIC_TAG]} preferred up
+ [[ -n "${gateway6[$ADMIN_NIC_TAG]}" ]] && \
+ /usr/sbin/route add -inet6 default ${gateway6[$ADMIN_NIC_TAG]}
+fi
+
+# Add just the routes reachable through the admin network -- usually these are
+# only present with rack aware networking (RAN)
+/usr/lib/sdc/net-boot-config --routes | while read dst gw; do
+ if ! ip_in_net $gw ${ip[$ADMIN_NIC_TAG]} ${netmask[$ADMIN_NIC_TAG]}; then
+ continue
+ fi
+ route add "$dst" "$gw"
+done
+
+if [[ -n "${CONFIG_dns_domain}" && -n ${dns_resolvers[0]} ]]; then
+ echo "search ${CONFIG_dns_domain}" > /etc/resolv.conf
+ for serv in ${dns_resolvers[@]}; do
+ echo "nameserver $serv" >> /etc/resolv.conf
+ done
+fi
+
+touch /etc/svc/volatile/.early_admin_setup
+
+log_if_state after
diff --git a/usr/src/cmd/svc/milestone/net-physical b/usr/src/cmd/svc/milestone/net-physical
index 89784dcbbc..90f6f7aff5 100644
--- a/usr/src/cmd/svc/milestone/net-physical
+++ b/usr/src/cmd/svc/milestone/net-physical
@@ -1,4 +1,4 @@
-#!/sbin/sh
+#!/usr/bin/ksh93
#
# CDDL HEADER START
#
@@ -19,527 +19,839 @@
#
# CDDL HEADER END
#
-#
# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2012 Milan Jurik. All rights reserved.
+# Copyright 2019 Joyent, Inc.
#
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
# All rights reserved.
#
. /lib/svc/share/smf_include.sh
-. /lib/svc/share/net_include.sh
+. /lib/sdc/config.sh
+. /lib/sdc/network.sh
+
+set -o errexit
+set -o xtrace
#
# In a shared-IP zone we need this service to be up, but all of the work
-# it tries to do is irrelevant (and will actually lead to the service
-# failing if we try to do it), so just bail out.
+# it tries to do is irrelevant (and will actually lead to the service
+# failing if we try to do it), so just bail out.
# In the global zone and exclusive-IP zones we proceed.
#
-smf_configure_ip || exit $SMF_EXIT_OK
-
+smf_configure_ip || exit ${SMF_EXIT_OK}
# Make sure that the libraries essential to this stage of booting can be found.
LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
+# Time (in seconds) to wait for admin NIC to get DHCP address before continuing.
+ADMIN_DHCP_TIMEOUT=300
+ActiveAggrLinks=
+typeset -A ActiveAggrLinks
+
smf_netstrategy
-if smf_is_globalzone; then
- net_reconfigure || exit $SMF_EXIT_ERR_CONFIG
-
- # Update PVID on interfaces configured with VLAN 1
- update_pvid
-
- #
- # Upgrade handling. The upgrade file consists of a series of dladm(1M)
- # commands. Note that after we are done, we cannot rename the upgrade
- # script file as the file system is still read-only at this point.
- # Defer this to the manifest-import service.
- #
- upgrade_script=/var/svc/profile/upgrade_datalink
- if [ -f "${upgrade_script}" ]; then
- . "${upgrade_script}"
- fi
-
- #
- # Upgrade handling for ibd:
- # After we are done with the upgrade handling, we can not set the
- # ibd/ibd_upgraded property to "true" as the file system is
- # read-only at this point. It will be done later by ibd-post-upgrade
- # service.
- #
- if [ -x /sbin/ibd_upgrade ]; then
- ibd_upgraded=`/bin/svcprop -c -p ibd/ibd_upgraded \
- $SMF_FMRI 2> /dev/null`
- if [ "$ibd_upgraded" != "true" ]; then
- /sbin/ibd_upgrade -v
- fi
- fi
-
- #
- # Bring up simnets, link aggregations and initialize security objects.
- # Note that link property initialization is deferred until after
- # IP interfaces are plumbed to ensure that the links will not
- # be unloaded (and the property settings lost). We should bring
- # up simnets prior to VLANs/Aggrs to enable creation of VLANs/Aggrs
- # over simnets.
- #
- /sbin/dladm up-simnet
- /sbin/dladm up-aggr
- /sbin/dladm up-vlan
- /sbin/dladm up-part
- /sbin/dladm init-secobj
- #
- # Bring up VNICs
- #
- /sbin/dladm up-vnic
- #
- # Create flows via flowadm.
- #
- /sbin/flowadm init-flow
-fi
+function add_active_aggr_links
+{
+ set -o xtrace
+ typeset alink
-#
-# If the system was net booted by DHCP, hand DHCP management off to the
-# DHCP agent (ifconfig communicates to the DHCP agent through the
-# loopback interface).
-#
-if [ -n "$_INIT_NET_IF" -a "$_INIT_NET_STRATEGY" = "dhcp" ]; then
- /sbin/dhcpagent -a
-fi
+ for alink in ${2//,/ }; do
+ ActiveAggrLinks[$alink]=$1
+ done
+}
-#
-# The network initialization is done early to support diskless and
-# dataless configurations. For IPv4 interfaces that were configured by
-# the kernel (e.g. those on diskless machines) and not configured by
-# DHCP, reset the netmask using the local "/etc/netmasks" file if one
-# exists, and then reset the broadcast address based on the netmask.
-#
-/sbin/ifconfig -auD4 netmask + broadcast +
+# Waits for up to 10 seconds for the link state to change to the given value
+function wait_for_admin_nic_state
+{
+ wait_for_nic_state "${SYSINFO_NIC_admin}" "$1"
+}
-is_iptun ()
+# Plumbs the admin interface, and attempts to work around poorly-behaved
+# drivers that can't handle plumb commands too quickly after one another
+function plumb_admin
{
- intf=$1
- # Is this a persistent IP tunnel link?
- /sbin/dladm show-iptun -P $intf > /dev/null 2>&1
- if [ $? -eq 0 ]; then
- return 0
- fi
- # Is this an implicit IP tunnel (i.e., ip.tun0)
- ORIGIFS="$IFS"
- IFS="$IFS."
- set -- $intf
- IFS="$ORIGIFS"
- if [ $# -eq 2 -a \( "$1" = "ip" -o "$1" = "ip6" \) ]; then
- #
- # It looks like one, but another type of link might be
- # using a name that looks like an implicit IP tunnel.
- # If dladm show-link -P finds it, then it's not an IP
- # tunnel.
- #
- /sbin/dladm show-link -Pp $intf > /dev/null 2>&1
- if [ $? -eq 0 ]; then
- return 1
- else
- return 0
- fi
- fi
- return 1
+ set -o xtrace
+ driver=${SYSINFO_NIC_admin%%[0-9]*}
+ get_link_state ${SYSINFO_NIC_admin}
+ if [[ "$link_state" == "down" ]]; then
+ echo "admin nic '${SYSINFO_NIC_admin}' is down: unplumbing"
+ /sbin/ifconfig ${SYSINFO_NIC_admin} down unplumb
+ wait_for_admin_nic_state "unknown"
+ fi
+
+ # There's some sort of race condition in the bnx driver: if the plumb
+ # command comes too soon after the unplumb, the interface can come up
+ # in a state where it never fires interrupts for link state changes.
+ if [[ "$driver" == "bnx" ]]; then
+ sleep 5
+ fi
+ /sbin/ifconfig ${SYSINFO_NIC_admin} plumb mtu ${CONFIG_admin_mtu:-1500}
+ wait_for_admin_nic_state "up"
}
-#
-# All the IPv4 and IPv6 interfaces are plumbed before doing any
-# interface configuration. This prevents errors from plumb failures
-# getting mixed in with the configured interface lists that the script
-# outputs.
-#
+# Creates, plumbs and brings up a vnic with the specified inet parameters
+function vnic_up
+{
+ set -o xtrace
+
+ typeset link="$1"
+ typeset iface="$2"
+ typeset ip="$3"
+ typeset netmask="$4"
+ typeset vlan_id="$5"
+ typeset mac_addr="$6"
+ typeset dhcp_primary="$7"
+ typeset mtu="$8"
+ typeset details=
+ typeset vlan_opt=
+ typeset mac_addr_opt=
+ typeset prop_opt=
+
+ details="link='${link}', iface='${iface}', ip='${ip}'"
+ details="${details}, netmask='${netmask}, vlan_id='${vlan_id}'"
+
+ if [[ -z ${link} ]] || [[ -z ${iface} ]] || \
+ [[ -z ${ip} ]] || ([[ ${ip} != "dhcp" ]] && [[ -z ${netmask} ]]); then
+ echo "WARNING: not bringing up nic (insufficient configuration): " \
+ "$details"
+ return
+ fi
+
+ eval "vnic_already_up=\${vnic_${iface}_up}"
+ if [[ -n "${vnic_already_up}" ]]; then
+ echo "vnic already up: $details"
+ return
+ fi
+
+ if [[ -n ${mac_addr} ]] && [[ -n ${ActiveAggrLinks[${mac_addr}]} ]]; then
+ echo "WARNING: trying to assign MAC address \"${mac_addr}\" to vnic," \
+ " but it already belongs to link aggr " \
+ "\"${ActiveAggrLinks[${mac_addr}]}\""
+ return
+ fi
+
+ echo "Bringing up nic: $details"
+
+ if [[ -n ${vlan_id} ]] && [[ ${vlan_id} != 0 ]]; then
+ vlan_opt="-v ${vlan_id}"
+ fi
+
+ if [[ -n ${mac_addr} ]]; then
+ mac_addr_opt="-m ${mac_addr}"
+ fi
+
+ if [[ -n ${mtu} ]]; then
+ valid_mtu ${iface} ${mtu}
+ prop_opt="-p mtu=${mtu}"
+ fi
+
+ /usr/sbin/dladm create-vnic -t -l ${link} ${prop_opt} ${vlan_opt} \
+ ${mac_addr_opt} ${iface}
+ if [[ $? -ne 0 ]]; then
+ echo "Failed to create VNIC ${iface}"
+ exit $SMF_EXIT_ERR_FATAL
+ fi
+
+ /sbin/ifconfig ${iface} plumb
+ if [[ $? -ne 0 ]]; then
+ echo "Failed to plumb ${iface}"
+ exit $SMF_EXIT_ERR_FATAL
+ fi
+
+ if [[ ${ip} == "dhcp" ]]; then
+ # We ignore errors here because the most common one is that DHCP
+ # is already running.
+
+ if [[ -n ${dhcp_primary} ]]; then
+ /sbin/ifconfig ${iface} dhcp primary || /bin/true
+ else
+ /sbin/ifconfig ${iface} dhcp || /bin/true
+ fi
+ else
+ /sbin/ifconfig ${iface} inet ${ip} netmask ${netmask} up
+ fi
+ eval "vnic_${iface}_up=true"
+}
-#
-# First deal with /etc/hostname
-#
-# Get the list of IPv4 interfaces to configure by breaking
-# /etc/hostname.* into separate args by using "." as a shell separator
-# character.
-#
-interface_names="`echo /etc/hostname.*[0-9] 2>/dev/null`"
-if [ "$interface_names" != "/etc/hostname.*[0-9]" ]; then
- ORIGIFS="$IFS"
- IFS="$IFS."
- set -- $interface_names
- IFS="$ORIGIFS"
- while [ $# -ge 2 ]; do
- shift
- intf_name=$1
- while [ $# -gt 1 -a "$2" != "/etc/hostname" ]; do
- intf_name="$intf_name.$2"
- shift
- done
- shift
-
- # skip IP tunnel interfaces plumbed by net-iptun.
- if is_iptun $intf_name; then
- continue
- fi
-
- read one rest < /etc/hostname.$intf_name
- if [ "$one" = ipmp ]; then
- ipmp_list="$ipmp_list $intf_name"
- else
- inet_list="$inet_list $intf_name"
- fi
- done
-fi
+# Creates, plumbs and brings up a vnic with the specified inet6 parameters
+function vnic_up6
+{
+ set -o xtrace
+
+ typeset link="$1"
+ typeset iface="$2"
+ typeset ip="$3"
+ typeset vlan_id="$4"
+ typeset mac_addr="$5"
+ typeset mtu="$6"
+ typeset details=
+ typeset vlan_opt=
+ typeset mac_addr_opt=
+ typeset prop_opt=
+
+ details="link='${link}', iface='${iface}', ip6='${ip}'"
+ details="${details}, vlan_id='${vlan_id}'"
+
+ if [[ -z ${link} ]] || [[ -z ${iface} ]] || [[ -z ${ip} ]]; then
+ echo "WARNING: not bringing up nic (insufficient configuration): " \
+ "$details"
+ return
+ fi
+
+ if [[ -n ${mac_addr} ]] && [[ -n ${ActiveAggrLinks[${mac_addr}]} ]]; then
+ echo "WARNING: trying to assign MAC address \"${mac_addr}\" to vnic," \
+ " but it already belongs to link aggr " \
+ "\"${ActiveAggrLinks[${mac_addr}]}\""
+ return
+ fi
+
+ # only bring up nic if not already up
+ eval "vnic_already_up=\${vnic_${iface}_up}"
+ if [[ -z "${vnic_already_up}" ]]; then
+ echo "Bringing up nic: $details"
+
+ if [[ -n ${vlan_id} ]] && [[ ${vlan_id} != 0 ]]; then
+ vlan_opt="-v ${vlan_id}"
+ fi
+
+ if [[ -n ${mac_addr} ]]; then
+ mac_addr_opt="-m ${mac_addr}"
+ fi
+
+ if [[ -n ${mtu} ]]; then
+ valid_mtu ${iface} ${mtu}
+ prop_opt="-p mtu=${mtu}"
+ fi
+
+ /usr/sbin/dladm create-vnic -t -l ${link} ${prop_opt} ${vlan_opt} \
+ ${mac_addr_opt} ${iface}
+ if [[ $? -ne 0 ]]; then
+ echo "Failed to create VNIC ${iface}"
+ exit $SMF_EXIT_ERR_FATAL
+ fi
+ fi
+
+ /sbin/ifconfig ${iface} inet6 plumb
+ if [[ $? -ne 0 ]]; then
+ echo "Failed to plumb ${iface}"
+ exit $SMF_EXIT_ERR_FATAL
+ fi
+
+ if [[ -n ${ip} ]]; then
+ /sbin/ifconfig ${iface} inet6 up
+ fi
+ if [[ ${ip} != "addrconf" ]]; then
+ /sbin/ifconfig ${iface} inet6 \
+ addif ${ip} preferred up
+ fi
+ eval "vnic_${iface}_up=true"
+}
-#
-# Get the list of IPv6 interfaces to configure by breaking
-# /etc/hostname6.* into separate args by using "." as a shell separator
-# character.
-#
-interface_names="`echo /etc/hostname6.*[0-9] 2>/dev/null`"
-if [ "$interface_names" != "/etc/hostname6.*[0-9]" ]; then
- ORIGIFS="$IFS"
- IFS="$IFS."
- set -- $interface_names
- IFS="$ORIGIFS"
- while [ $# -ge 2 ]; do
- shift
- intf_name=$1
- while [ $# -gt 1 -a "$2" != "/etc/hostname6" ]; do
- intf_name="$intf_name.$2"
- shift
- done
- shift
-
- # skip IP tunnel interfaces plumbed by net-iptun.
- if is_iptun $intf_name; then
- continue
- fi
-
- read one rest < /etc/hostname6.$intf_name
- if [ "$one" = ipmp ]; then
- ipmp6_list="$ipmp6_list $intf_name"
- else
- inet6_list="$inet6_list $intf_name"
- fi
- done
-fi
+# If there are aggregations in sysinfo, set them up.
+function create_aggrs
+{
+ set -o xtrace
+ typeset links macs mode mtu
+ if [[ -z "${SYSINFO_Aggregations}" ]]; then
+ return 0
+ fi
+
+ aggrs=(${SYSINFO_Aggregations//,/ })
+ for aggr in "${aggrs[@]}"; do
+ eval "links=\${SYSINFO_Aggregation_${aggr}_Interfaces}"
+ eval "macs=\${SYSINFO_Aggregation_${aggr}_MACs}"
+ eval "mode=\${SYSINFO_Aggregation_${aggr}_LACP_mode}"
+ eval "mtu=\${CONFIG_${aggr}_mtu}"
+ [[ -z "$mode" ]] && mode="off"
+
+ echo "Creating aggr: ${aggr} (mode=${mode}, links=${links})"
+ dladm create-aggr -l ${links//,/ -l } -L ${mode} ${aggr}
+ if [[ $? -eq 0 ]]; then
+ add_active_aggr_links ${aggr} ${macs}
+ fi
+
+ if [[ -n "$mtu" ]]; then
+ dladm set-linkprop -p mtu=${mtu} ${aggr}
+ if [[ $? -ne 0 ]]; then
+ echo "Failed to set mtu on aggr ${aggr} to ${mtu}"
+ exit $SMF_EXIT_ERR_FATAL
+ fi
+ fi
+ done
+
+ # Creating the aggregations may affect the nic tags in sysinfo, so update:
+ /usr/bin/sysinfo -u
+ load_sdc_sysinfo
+}
#
-# Create all of the IPv4 IPMP interfaces.
+# Try various config parameters to set the default route
#
-if [ -n "$ipmp_list" ]; then
- set -- $ipmp_list
- while [ $# -gt 0 ]; do
- if /sbin/ifconfig $1 ipmp; then
- ipmp_created="$ipmp_created $1"
- else
- ipmp_failed="$ipmp_failed $1"
- fi
- shift
- done
- [ -n "$ipmp_failed" ] && warn_failed_ifs "create IPv4 IPMP" \
- "$ipmp_failed"
-fi
+function set_default_route
+{
+ set -o xtrace
+ typeset default_gw
-#
-# Step through the IPv4 interface list and try to plumb every interface.
-# Generate list of plumbed and failed IPv4 interfaces.
-#
-if [ -n "$inet_list" ]; then
- set -- $inet_list
- while [ $# -gt 0 ]; do
- /sbin/ifconfig $1 plumb
- if /sbin/ifconfig $1 inet >/dev/null 2>&1; then
- inet_plumbed="$inet_plumbed $1"
- else
- inet_failed="$inet_failed $1"
- fi
- shift
- done
- [ -n "$inet_failed" ] && warn_failed_ifs "plumb IPv4" "$inet_failed"
-fi
+ if [[ -n "${CONFIG_headnode_default_gateway}" ]]; then
+ default_gw="${CONFIG_headnode_default_gateway}"
-# Run autoconf to connect to a WLAN if the interface is a wireless one
-if [ -x /sbin/wificonfig -a -n "$inet_plumbed" ]; then
- set -- $inet_plumbed
- while [ $# -gt 0 ]; do
- if [ -r /dev/wifi/$1 ]; then
- /sbin/wificonfig -i $1 startconf >/dev/null
- fi
- shift
- done
-fi
+ elif [[ -n ${CONFIG_admin_gateway} ]]; then
+ default_gw="${CONFIG_admin_gateway}"
-#
-# Step through the IPv6 interface list and plumb every interface.
-# Generate list of plumbed and failed IPv6 interfaces. Each plumbed
-# interface will be brought up later, after processing any contents of
-# the /etc/hostname6.* file.
-#
-if [ -n "$inet6_list" ]; then
- set -- $inet6_list
- while [ $# -gt 0 ]; do
- /sbin/ifconfig $1 inet6 plumb
- if /sbin/ifconfig $1 inet6 >/dev/null 2>&1; then
- inet6_plumbed="$inet6_plumbed $1"
- else
- inet6_failed="$inet6_failed $1"
- fi
- shift
- done
- [ -n "$inet6_failed" ] && warn_failed_ifs "plumb IPv6" "$inet6_failed"
-fi
+ elif [[ -n ${BOOT_admin_gateway} ]]; then
+ default_gw=${BOOT_admin_gateway}
-#
-# Create all of the IPv6 IPMP interfaces.
-#
-if [ -n "$ipmp6_list" ]; then
- set -- $ipmp6_list
- while [ $# -gt 0 ]; do
- if /sbin/ifconfig $1 inet6 ipmp; then
- ipmp6_created="$ipmp6_created $1"
- else
- ipmp6_failed="$ipmp6_failed $1"
- fi
- shift
- done
- [ -n "$ipmp6_failed" ] && warn_failed_ifs "create IPv6 IPMP" \
- "$ipmp6_failed"
-fi
+ elif [[ -n ${CONFIG_external_gateway} ]]; then
+ default_gw=${CONFIG_external_gateway}
+ fi
-#
-# Finally configure interfaces set up with ipadm. Any /etc/hostname*.intf
-# files take precedence over ipadm defined configurations except when
-# we are in a non-global zone and Layer-3 protection of IP addresses is
-# enforced on the interface by the global zone.
-#
-for showif_output in `/sbin/ipadm show-if -p -o ifname,state,current`; do
- intf=`echo $showif_output | /usr/bin/cut -f1 -d:`
- state=`echo $showif_output | /usr/bin/cut -f2 -d:`
- current=`echo $showif_output | /usr/bin/cut -f3 -d:`
- if [[ "$state" != "disabled" && $current != *Z* ]]; then
- #
- # skip if not a persistent interface, or if it should get IP
- # configuration from the global zone ('Z' flag is set)
- #
- continue;
- elif is_iptun $intf; then
- # skip IP tunnel interfaces plumbed by net-iptun
- continue;
- elif [ -f /etc/hostname.$intf ] || [ -f /etc/hostname6.$intf ]; then
- if [[ $current != *Z* ]]; then
- echo "found /etc/hostname.$intf "\
- "or /etc/hostname6.$intf, "\
- "ignoring ipadm configuration" > /dev/msglog
- continue;
- else
- echo "Ignoring /etc/hostname*.$intf" > /dev/msglog
- /sbin/ifconfig $intf unplumb > /dev/null 2>&1
- /sbin/ifconfig $intf inet6 unplumb > /dev/null 2>&1
- fi
- fi
-
- # Enable the interface managed by ipadm
- /sbin/ipadm enable-if -t $intf
-done
+ if [[ -n ${default_gw} ]]; then
+ echo "${default_gw}" > /etc/defaultrouter
+ fi
-#
-# Process the /etc/hostname[6].* files for IPMP interfaces. Processing these
-# before non-IPMP interfaces avoids accidental implicit IPMP group creation.
-#
-[ -n "$ipmp_created" ] && if_configure inet "IPMP" $ipmp_created
-[ -n "$ipmp6_created" ] && if_configure inet6 "IPMP" $ipmp6_created
+ if [[ -n ${CONFIG_admin_gateway6} ]]; then
+ default_gw6="${CONFIG_admin_gateway6}"
-#
-# Process the /etc/hostname[6].* files for non-IPMP interfaces.
-#
-[ -n "$inet_plumbed" ] && if_configure inet "" $inet_plumbed
-[ -n "$inet6_plumbed" ] && if_configure inet6 "" $inet6_plumbed
+ elif [[ -n ${BOOT_admin_gateway6} ]]; then
+ default_gw6=${BOOT_admin_gateway6}
+
+ elif [[ -n ${CONFIG_external_gateway6} ]]; then
+ default_gw6=${CONFIG_external_gateway6}
+ fi
+
+ if [[ -n ${default_gw6} ]]; then
+ # add static route
+ /usr/sbin/route add -inet6 default ${default_gw6}
+ fi
+}
#
-# For the IPv4 and IPv6 interfaces that failed to plumb, find (or create)
-# IPMP meta-interfaces to host their data addresses.
+# Go through and set up the MTU for all of the various nic tags
#
-[ -n "$inet_failed" ] && move_addresses inet
-[ -n "$inet6_failed" ] && move_addresses inet6
-
-# Run DHCP if requested. Skip boot-configured interface.
-interface_names="`echo /etc/dhcp.*[0-9] 2>/dev/null`"
-if [ "$interface_names" != '/etc/dhcp.*[0-9]' ]; then
- #
- # First find the primary interface. Default to the first
- # interface if not specified. First primary interface found
- # "wins". Use care not to "reconfigure" a net-booted interface
- # configured using DHCP. Run through the list of interfaces
- # again, this time trying DHCP.
- #
- i4d_fail=
- firstif=
- primary=
- ORIGIFS="$IFS"
- IFS="${IFS}."
- set -- $interface_names
-
- while [ $# -ge 2 ]; do
- shift
- [ -z "$firstif" ] && firstif=$1
-
- for i in `shcat /etc/dhcp\.$1`; do
- if [ "$i" = primary ]; then
- primary=$1
- break
- fi
- done
-
- [ -n "$primary" ] && break
- shift
- done
-
- [ -z "$primary" ] && primary="$firstif"
- cmdline=`shcat /etc/dhcp\.${primary}`
-
- if [ "$_INIT_NET_IF" != "$primary" ]; then
- echo "starting DHCP on primary interface $primary"
- /sbin/ifconfig $primary auto-dhcp primary $cmdline
- # Exit code 4 means ifconfig timed out waiting for dhcpagent
- [ $? != 0 ] && [ $? != 4 ] && i4d_fail="$i4d_fail $primary"
- fi
-
- set -- $interface_names
-
- while [ $# -ge 2 ]; do
- shift
- cmdline=`shcat /etc/dhcp\.$1`
- if [ "$1" != "$primary" -a \
- "$1" != "$_INIT_NET_IF" ]; then
- echo "starting DHCP on interface $1"
- /sbin/ifconfig $1 dhcp start wait 0 $cmdline
- # Exit code can't be timeout when wait is 0
- [ $? != 0 ] && i4d_fail="$i4d_fail $1"
- fi
- shift
- done
- IFS="$ORIGIFS"
- unset ORIGIFS
- [ -n "$i4d_fail" ] && warn_failed_ifs "configure IPv4 DHCP" "$i4d_fail"
-fi
+function setup_mtu
+{
+ set -o xtrace
+ typeset tag oldifs val mac link curmtu
+ typeset -A mtus
+ typeset -A tagmap
+
+ set -o xtrace
+ oldifs=$IFS
+ IFS=,
+ for tag in ${SYSINFO_Nic_Tags}; do
+ eval "val=\${CONFIG_${tag}_mtu}"
+ eval "mac=\${CONFIG_${tag}_nic}"
+ [[ -z "$val" ]] && continue
+
+ valid_mtu ${tag} $val
+
+ #
+ # Note, it doesn't matter what tag we use for a given mac
+ # address, because we'll always get the same link name later on.
+ #
+ if [[ -z "${tagmap[$mac]}" ]]; then
+ tagmap[$mac]=$tag
+ fi
+
+ if [[ -z "${mtus[$mac]}" ]]; then
+ mtus[$mac]=$val
+ elif [[ "${mtus[$mac]}" -lt $val ]]; then
+ mtus[$mac]=$val
+ fi
+ done
+ IFS=$oldifs
+
+ for mac in ${!mtus[@]}; do
+ tag=${tagmap[$mac]}
+ eval "link=\${SYSINFO_NIC_${tag}}"
+ if [[ -z "${link}" ]]; then
+ echo "/usbkey/config error: Missing link name for ${tag}"
+ exit $SMF_EXIT_ERR_FATAL
+ fi
+
+ #
+ # Check the current MTU of the device. To help out devices which
+ # don't support the setting of the MTU (here's looking at you
+ # bnx), if the MTU is identical to its default, don't do
+ # anything and save the poor folks stuck with bnx some grief.
+ #
+ curmtu=$(/usr/sbin/dladm show-linkprop -c -o value -p mtu ${link})
+ [[ $? -eq 0 ]] && [[ "$curmtu" -eq "${mtus[$mac]}" ]] && continue
+
+ if ! /usr/sbin/dladm set-linkprop -p mtu=${mtus[$mac]} ${link}; then
+ echo "Failed to set mtu to ${mtus[$mac]} for link ${link}"
+ exit $SMF_EXIT_ERR_FATAL
+ fi
+ done
+}
-# In order to avoid bringing up the interfaces that have
-# intentionally been left down, perform RARP only if the system
-# has no configured hostname in /etc/nodename
-hostname="`shcat /etc/nodename 2>/dev/null`"
-if [ "$_INIT_NET_STRATEGY" = "rarp" -o -z "$hostname" ]; then
- /sbin/ifconfig -adD4 auto-revarp netmask + broadcast + up
+
+# Helper function for plumbing an interface for an address family once
+typeset -A plumbedifs
+function plumbif
+{
+ iface=$1
+ inet=$2
+ addrtype=$3
+ if [[ -z ${plumbedifs[${iface},${inet}]} ]]; then
+ plumbedifs[${iface},${inet}]="true"
+ /sbin/ifconfig ${iface} ${inet} plumb
+ if [[ ! ${addrtype} =~ "^vrrp" ]]; then
+ /sbin/ifconfig ${iface} ${inet} up
+ fi
+ fi
+}
+
+if smf_is_globalzone; then
+ EARLY_ADMIN=
+ [[ -f /etc/svc/volatile/.early_admin_setup ]] && EARLY_ADMIN=1
+ [[ -n "$EARLY_ADMIN" ]] || /usr/sbin/dladm init-phys
+
+ # The next command is for logging purposes only
+ log_if_state before
+
+ # Load sysinfo variables with SYSINFO_ prefix: we primarily care about
+ # the NIC_variables, which contain the actual interface name for a nic
+ # tag (it has mapped the foo_nic=<MAC address> variables to interface
+ # names for us).
+ load_sdc_sysinfo
+
+ if boot_file_config_enabled; then
+ # We have a boot-time networking file present - use its values rather
+ # than ones from the config file or bootparams
+ if ! boot_file_config_valid; then
+ echo "ERROR: boot-time network config file incorrect"
+ exit ${SMF_EXIT_ERR_CONFIG}
+ fi
+
+ load_boot_file_config
+
+ # NOTE: some of the routes boot_file_config_init tries to add may
+ # fail if they are admin network routes added by the
+ # network/early-admin service. This is expected and not a problem.
+ boot_file_config_init
+ else
+ # Load config variables with CONFIG_ prefix,
+ # and sets the headnode variable
+ load_sdc_config
+ # Load boot params with BOOT_ prefix
+ load_sdc_bootparams
+ fi
+
+ # Set up etherstubs
+ for stub in $(echo "${CONFIG_etherstub}" | sed -e "s/,/ /g"); do
+ /usr/sbin/dladm create-etherstub -t $stub || echo "ERROR: could not create etherstub ${stub}."
+ done
+
+ # Create aggregations
+ create_aggrs
+
+ # Make any mtu adjustments that may be necessary
+ setup_mtu
+
+ # Setup admin NIC
+ ADMIN_NIC_TAG=${CONFIG_admin_tag:-"admin"}
+
+ # If there is no NIC with the admin tag, and the config has
+ # admin_nic_autoselect=true, designate the first NIC reported
+ # by dladm for admin use. This is useful in environments where
+ # the NICs are known to change beneath us.
+ if [[ "${BOOT_smartos}" == "true" ]] && \
+ [[ "${CONFIG_admin_nic_autoselect}" == "true" ]] && \
+ ! nictagadm exists $ADMIN_NIC_TAG ; then
+ autoselected_admin_nic=$(dladm show-phys -m -p -o address | head -n1)
+ if [[ -z ${autoselected_admin_nic} ]] ; then
+ echo "ERROR: no NICs found, unable to autoselect admin NIC."
+ exit ${SMF_EXIT_ERR_CONFIG}
+ fi
+
+ nictagadm add $ADMIN_NIC_TAG "${autoselected_admin_nic}"
+ if [[ $? -ne 0 ]] ; then
+ echo "ERROR: unable to add admin tag to NIC ${autoselected_admin_nic}"
+ exit ${SMF_EXIT_ERR_FATAL}
+ fi
+
+ SYSINFO_NIC_admin=$(dladm show-phys -m -p -o link | head -n1)
+ if [[ -n ${SYSINFO_NIC_admin} ]] ; then
+ echo "Autoselected ${SYSINFO_NIC_admin} for use as admin NIC."
+ fi
+
+ nictagadm list
+ elif [[ -v CONFIG_admin_tag ]]; then
+ #
+ # This handles the case when the 'admin_tag' property is set to
+ # override the default admin nic tag.
+ #
+ eval SYSINFO_NIC_admin='$'SYSINFO_NIC_${CONFIG_admin_tag}
+
+ eval CONFIG_admin_ip='$'CONFIG_${CONFIG_admin_tag}_ip
+ eval CONFIG_admin_ip6='$'CONFIG_${CONFIG_admin_tag}_ip6
+ eval CONFIG_admin_netmask='$'CONFIG_${CONFIG_admin_tag}_netmask
+ eval CONFIG_admin_mtu='$'CONFIG_${CONFIG_admin_tag}_mtu
+ eval CONFIG_admin_gateway='$'CONFIG_${CONFIG_admin_tag}_gateway
+ eval CONFIG_admin_gateway6='$'CONFIG_${CONFIG_admin_tag}_gateway6
+ fi
+
+ if [[ -z "${SYSINFO_NIC_admin}" ]]; then
+ echo "ERROR: admin NIC not found, unable to bring up admin network."
+ exit ${SMF_EXIT_ERR_CONFIG}
+ fi
+
+ [[ -n "$EARLY_ADMIN" ]] || plumb_admin
+
+ # If we performed early configuration of the admin network and
+ # the admin interface is on a link aggregation, the aggregation
+ # has already been configured. Add it to the list of active aggrs
+ # so the checks in vnic_up[6] are aware of it.
+ if [[ -n "$EARLY_ADMIN" && "${SYSINFO_NIC_admin}" =~ aggr[0-9]+$ ]]; then
+ eval "macs=\${SYSINFO_Aggregation_${SYSINFO_NIC_admin}_MACs}"
+
+ add_active_aggr_links ${SYSINFO_NIC_admin} $macs
+ fi
+
+ # Prefer the config file for admin nic values, but use
+ # bootparams if present
+ admin_ip=${CONFIG_admin_ip}
+ if [[ -z "$admin_ip" ]]; then
+ admin_ip=${BOOT_admin_ip}
+ fi
+
+ admin_netmask=${CONFIG_admin_netmask}
+ if [[ -z "$admin_netmask" ]]; then
+ admin_netmask=${BOOT_admin_netmask}
+ fi
+
+ admin_ip6=${CONFIG_admin_ip6}
+ if [[ -z "$admin_ip6" ]]; then
+ admin_ip6=${BOOT_admin_ip6}
+ fi
+
+ if [[ $admin_ip == 'none' ]]; then
+ echo 'INFO: not configuring IP on admin interface (admin_ip=none)'
+ elif [[ -n "$EARLY_ADMIN" ]]; then
+ echo 'INFO: admin interface already configured (early setup)'
+ ADMIN_NIC_UP=true
+ elif [[ -n $admin_ip ]] && [[ -n $admin_netmask ]]; then
+ /sbin/ifconfig ${SYSINFO_NIC_admin} inet ${admin_ip} \
+ netmask ${admin_netmask} up
+ ADMIN_NIC_UP=true
+
+ # also setup resolv.conf if we can
+ if [[ -n ${CONFIG_dns_domain} ]] && [[ -n ${CONFIG_dns_resolvers} ]]; then
+ echo "search ${CONFIG_dns_domain}" > /etc/resolv.conf
+ if [[ -n ${CONFIG_binder_admin_ips} ]]; then
+ for serv in $(echo "${CONFIG_binder_admin_ips}" | sed -e "s/,/ /g"); do
+ echo "nameserver ${serv}" >> /etc/resolv.conf
+ done
+ fi
+ for serv in $(echo "${CONFIG_dns_resolvers}" | sed -e "s/,/ /g"); do
+ echo "nameserver ${serv}" >> /etc/resolv.conf
+ done
+ fi
+ else
+ if [[ ${headnode} == "true" ]]; then
+ echo "ERROR: headnode but no admin_{ip,netmask} in config, not bringing up admin network."
+ # Set a flag, but try to plumb the other interfaces anyway
+ ADMIN_NIC_MISCONFIGURED=true
+ else
+ # We ignore errors here because the most common one is that DHCP is
+ # already running.
+ /sbin/ifconfig ${SYSINFO_NIC_admin} dhcp || /bin/true
+
+ # Wait for DHCP
+ timeout=${ADMIN_DHCP_TIMEOUT}
+ dhcp_admin_ip=$(/sbin/ifconfig ${SYSINFO_NIC_admin} | grep inet | awk '{ print $2 }')
+ while [[ (-z ${dhcp_admin_ip} || ${dhcp_admin_ip} == "0.0.0.0") && ${timeout} -gt 0 ]]; do
+ dhcp_admin_ip=$(/sbin/ifconfig ${SYSINFO_NIC_admin} | grep inet | awk '{ print $2 }')
+ timeout=$((${timeout} - 1))
+ sleep 1
+ done
+
+ ADMIN_NIC_UP=true
+ fi
+ fi
+
+ if [[ -n ${admin_ip6} && -z "$EARLY_ADMIN" ]]; then
+ # Plumb interface for inet6
+ ifconfig ${SYSINFO_NIC_admin} inet6 \
+ plumb mtu ${CONFIG_admin_mtu:-1500} up
+
+ # Autodiscovery IPv6 using SLAAC
+ # NOTE: in.ndpd will be started later, due to plumbing the interface.
+ # this means autodiscovery also happens when configuring a
+ # static address.
+ #
+ # in.ndpd also sets a default route and this can't be disabled.
+
+ # Configure static IPv6
+ if [[ ${admin_ip6} != "addrconf" ]]; then
+ /sbin/ifconfig ${SYSINFO_NIC_admin} inet6 \
+ addif ${admin_ip6} preferred up
+ fi
+
+ ADMIN_NIC_UP=true
+
+ # don't setup resolv.conf, IPv6 addresses already work
+ fi
+
+ # If on Parallels or VirtualBox, create a bridge which
+ # allows traffic to flow correctly to the host-only network
+ if [[ "${ADMIN_NIC_UP}" == "true" ]] \
+ && [[ ${SYSINFO_Product} == "Parallels Virtual Platform" \
+ || ${SYSINFO_Product} == "VirtualBox" ]] \
+ && [[ -z $(/usr/sbin/dladm show-bridge -p vmwarebr) ]]; then
+ /usr/sbin/dladm create-bridge -l ${SYSINFO_NIC_admin} vmwarebr
+ fi
+
+ # Setup the external NIC. The installer may have already set up external0,
+ # so, if it exists, we're not going to try and set up the vnic again.
+ if [[ -n ${SYSINFO_NIC_external} ]] \
+ && ! dladm show-vnic external0 > /dev/null; then
+
+ if [[ -n "${CONFIG_external_ip}" ]]; then
+ vnic_up "${SYSINFO_NIC_external}" "external0" \
+ "${CONFIG_external_ip}" "${CONFIG_external_netmask}" \
+ "${CONFIG_external_vlan_id}" "${CONFIG_external_mac}" \
+ "primary" "${CONFIG_external_mtu}"
+ fi
+
+ if [[ -n "${CONFIG_external_ip6}" ]]; then
+ vnic_up6 "${SYSINFO_NIC_external}" "external0" \
+ "${CONFIG_external_ip6}" \
+ "${CONFIG_external_vlan_id}" "${CONFIG_external_mac}" \
+ "${CONFIG_external_mtu}"
+ fi
+ fi
+
+ set_default_route
+
+ # Setup extra nics, if specified in the config file
+ nic_tags="${SYSINFO_Nic_Tags}"
+ if [[ -n "${nic_tags}" ]]; then
+ tags=(${nic_tags//,/ })
+
+ if boot_file_config_enabled; then
+ bootparam_ip_keys=""
+ bootparam_ip6_keys=""
+ config_ip_keys=${CONFIG_bootfile_ip_keys//,/ }
+ config_ip6_keys=${CONFIG_bootfile_ip6_keys//,/ }
+ else
+ bootparam_ip_keys=$(sdc_bootparams_keys | grep -- "-ip$" || true)
+ bootparam_ip6_keys=$(sdc_bootparams_keys | grep -- "-ip6$" || true)
+ config_ip_keys=$(sdc_config_keys | grep "_ip$" || true)
+ config_ip6_keys=$(sdc_config_keys | grep "_ip6$" || true)
+ fi
+
+ for tag in "${tags[@]}"; do
+
+ eval "link=\${SYSINFO_NIC_${tag}}"
+ if [[ -z "${link}" ]]; then
+ echo "WARNING: No link found with tag '${tag}'"
+ continue
+ fi
+
+ for key in ${config_ip_keys}; do
+ if [[ ${key} == ${tag}[0-9]_ip ]] || [[ ${key} == ${tag}[0-9][0-9]_ip ]]; then
+ iface=${key//_ip/}
+ #echo " iface=$iface"
+ eval "ip=\${CONFIG_${iface}_ip}"
+ eval "netmask=\${CONFIG_${iface}_netmask}"
+ eval "vlan=\${CONFIG_${iface}_vlan_id}"
+ eval "macaddr=\${CONFIG_${iface}_mac}"
+ eval "mtu=\${CONFIG_${iface}_mtu}"
+
+ echo vnic_up "${link}" "${iface}" "${ip}" "${netmask}" "${vlan}" "${macaddr}" "${mtu}"
+ vnic_up "${link}" "${iface}" "${ip}" "${netmask}" \
+ "${vlan}" "${macaddr}" "" "${mtu}"
+ fi
+ done
+
+ for key in ${bootparam_ip_keys}; do
+ if [[ ${key} == ${tag}[0-9]-ip ]] || [[ ${key} == ${tag}[0-9][0-9]-ip ]]; then
+ iface=${key//-ip/}
+ eval "ip=\${BOOT_${iface}_ip}"
+ eval "netmask=\${BOOT_${iface}_netmask}"
+ eval "vlan=\${BOOT_${iface}_vlan_id}"
+ eval "macaddr=\${BOOT_${iface}_mac}"
+ eval "mtu=\${CONFIG_${iface}_mtu}"
+ echo vnic_up "${link}" "${iface}" "${ip}" "${netmask}" "${vlan}" "${macaddr}" "${mtu}"
+ vnic_up "${link}" "${iface}" "${ip}" "${netmask}" \
+ "${vlan}" "${macaddr}" "" "${mtu}"
+ fi
+ done
+
+ for key in ${config_ip6_keys}; do
+ if [[ ${key} == ${tag}[0-9]_ip6 ]] || [[ ${key} == ${tag}[0-9][0-9]_ip6 ]]; then
+ iface=${key//_ip6/}
+ #echo " iface=$iface"
+ eval "ip=\${CONFIG_${iface}_ip6}"
+ eval "vlan=\${CONFIG_${iface}_vlan_id}"
+ eval "macaddr=\${CONFIG_${iface}_mac}"
+ eval "mtu=\${CONFIG_${iface}_mtu}"
+
+ echo vnic_up6 "${link}" "${iface}" "${ip}" "${vlan}" "${macaddr}" "${mtu}"
+ vnic_up6 "${link}" "${iface}" "${ip}" \
+ "${vlan}" "${macaddr}" "${mtu}"
+ fi
+ done
+
+ for key in ${bootparam_ip6_keys}; do
+ if [[ ${key} == ${tag}[0-9]-ip6 ]] || [[ ${key} == ${tag}[0-9][0-9]-ip6 ]]; then
+ iface=${key//-ip6/}
+ eval "ip=\${BOOT_${iface}_ip6}"
+ eval "vlan=\${BOOT_${iface}_vlan_id}"
+ eval "macaddr=\${BOOT_${iface}_mac}"
+ eval "mtu=\${CONFIG_${iface}_mtu}"
+ echo vnic_up6 "${link}" "${iface}" "${ip}" "${vlan}" "${macaddr}" "${mtu}"
+ vnic_up6 "${link}" "${iface}" "${ip}" \
+ "${vlan}" "${macaddr}" "${mtu}"
+ fi
+ done
+
+ done
+ fi
+else
+ # Non-global zones
+
+ # Bring up statically assigned interfaces, and find the primary DHCP
+ # interface, if it exists
+ while IFS=: read -r iface addrtype; do
+ # Keep track of whether or not we've configured our first IPv4
+ # address on this interface
+ first_ipv4_configured=""
+ iface_configured=""
+
+ if [[ -f /etc/dhcp.${iface} ]]; then
+ plumbif ${iface} inet ${addrtype}
+ if [[ -z "${primary}" ]]; then
+ /sbin/ifconfig ${iface} auto-dhcp primary
+ primary=${iface}
+ else
+ /sbin/ifconfig ${iface} auto-dhcp
+ fi
+ first_ipv4_configured="true"
+ iface_configured="true"
+ fi
+
+ if [[ -f /etc/hostname.${iface} ]]; then
+ while read ifparams; do
+ # For IPv4, we need to set the address on the first logical
+ # interface. For IPv6, the address on the first interface is
+ # the link-local address, and can't be changed.
+ #
+ # Lines starting with inet indicate the hostname for that
+ # interface, and are used by dhcpagent. Skip over them.
+ if [[ -f /etc/dhcp.${iface} && "${ifparams}" == inet* ]]; then
+ continue
+ elif [[ "${ifparams}" == {3}({1,3}(\d).){1,3}(\d)* ]]; then
+ plumbif ${iface} inet ${addrtype}
+ if [[ -z "${first_ipv4_configured}" ]]; then
+ first_ipv4_configured="true"
+ ifcommand="inet"
+ else
+ ifcommand="inet addif"
+ fi
+ else
+ plumbif ${iface} inet6 ${addrtype}
+ ifcommand="inet6 addif"
+ fi
+
+ # vrrp interfaces can't be brought up with ifconfig: vrrpadm
+ # handles that instead
+ if [[ "${addrtype}" =~ "^vrrp" ]]; then
+ /sbin/ifconfig ${iface} ${ifcommand} \
+ `printf "%s" "${ifparams}" | sed -e 's/ up//'`
+ else
+ /sbin/ifconfig ${iface} ${ifcommand} ${ifparams} up
+ fi
+
+ iface_configured="true"
+ done < /etc/hostname.${iface}
+ fi
+
+ if [[ -f /etc/addrconf.${iface} ]]; then
+ # Enable the NDP daemon, so that once this script finishes, we'll
+ # be able to pick up router advertisments and finish configuring
+ # the network interface. We then just need to plumb the interface,
+ # and let in.ndpd take care of configuring addresses.
+ svcadm enable svc:/network/routing/ndp:default
+ plumbif ${iface} inet6 ${addrtype}
+ iface_configured="true"
+ fi
+
+ # If we didn't configure the device at all, mark it for DHCP if we
+ # don't do DHCP on anyone else.
+ if [[ -z ${iface_configured} && -z "${first_iface}" ]]; then
+ first_iface=${iface}
+ fi
+ done < <(/usr/sbin/dladm show-vnic -p -o link,macaddrtype 2>/dev/null)
+
+ if [[ -z "${primary}" && -n "${first_iface}" ]]; then
+ first_iface_type=$(dladm show-vnic ${first_iface} -p -o macaddrtype)
+ plumbif ${first_iface} inet ${first_iface_type}
+ /sbin/ifconfig ${first_iface} auto-dhcp
+ primary=${first_iface}
+ fi
+
+ while IFS=: read -r iface addrtype; do
+ if [[ "${iface}" == "${primary}"
+ || -f /etc/hostname.${iface}
+ || -f /etc/dhcp.${iface}
+ || -f /etc/addrconf.${iface}
+ || "${addrtype}" =~ "^vrrp" ]]; then
+ continue
+ fi
+
+ plumbif ${iface} inet ${addrtype}
+ /sbin/ifconfig ${iface} auto-dhcp start wait 0
+ done < <(/usr/sbin/dladm show-vnic -p -o link,macaddrtype 2>/dev/null)
fi
-#
-# If the /etc/defaultrouter file exists, process it now so that the next
-# stage of booting will have access to NFS.
-#
-if [ -f /etc/defaultrouter ]; then
- while read router rubbish; do
- case "$router" in
- '#'* | '') ;; # Ignore comments, empty lines
- *) /sbin/route -n add default -gateway $router ;;
- esac
- done </etc/defaultrouter
+log_if_state after
+
+# Since we hopefully made networking changes here, update the sysinfo cache
+if smf_is_globalzone; then
+ /usr/bin/sysinfo -u
fi
-#
-# If we get here and were not asked to plumb any IPv4 interfaces, look
-# for boot properties that direct us.
-#
-# - The "network-interface" property is required and indicates the
-# interface name.
-# - The "xpv-hcp" property, if present, is used by the hypervisor
-# tools to indicate how the specified interface should be configured.
-# Permitted values are "dhcp" and "off", where "off" indicates static
-# IP configuration.
-#
-# In the case where "xpv-hcp" is set to "dhcp", no further properties
-# are required or examined.
-#
-# In the case where "xpv-hcp" is not present or set to "off", the
-# "host-ip" and "subnet-mask" properties are used to configure
-# the specified interface. The "router-ip" property, if present,
-# is used to add a default route.
-#
-nic="`/sbin/devprop network-interface`"
-if smf_is_globalzone && [ -z "$inet_list" ] && [ -n "$nic" ]; then
- hcp="`/sbin/devprop xpv-hcp`"
- case "$hcp" in
- "dhcp")
- /sbin/ifconfig $nic plumb 2>/dev/null
- [ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
- # The interface is successfully plumbed, so
- # modify "inet_list" to force the exit code
- # checks to work.
- inet_list=$nic;
- # Given that this is the only IPv4 interface,
- # we assert that it is primary.
- echo "starting DHCP on primary interface $primary";
- /sbin/ifconfig $nic auto-dhcp primary;
- # Exit code 4 means ifconfig timed out waiting
- # for dhcpagent
- [ $? != 0 ] && [ $? != 4 ] && \
- i4d_fail="$i4d_fail $nic";
- )
- ;;
-
- "off"|"")
- /sbin/devprop host-ip subnet-mask router-ip | (
- read ip;
- read mask;
- read router;
- [ -n "$ip" ] && [ -n "$mask" ] && \
- /sbin/ifconfig $nic plumb 2>/dev/null
- [ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
- # The interface is successfully
- # plumbed, so modify "inet_list" to
- # force the exit code checks to work.
- inet_list=$nic;
- /sbin/ifconfig $nic inet $ip \
- netmask $mask broadcast + up 2>/dev/null;
- [ -n "$router" ] && route add \
- default $router 2>/dev/null;
- )
- )
- ;;
- esac
+# Enable symmetric routing: when there are multiple nics configured, always
+# take into account the interface a packet is being sent over when
+# selecting a route. This prevents packets being sent with another nic's
+# source IP.
+/usr/sbin/ndd -set /dev/ip ip_strict_src_multihoming 1
+
+# If the admin nic was missing config options, exit with a config error
+if [[ -n "${ADMIN_NIC_MISCONFIGURED}" ]]; then
+ exit ${SMF_EXIT_ERR_CONFIG}
fi
-#
-# We tell smf this service is online if any of the following is true:
-# - no interfaces were configured for plumbing and no DHCP failures
-# - any non-loopback IPv4 interfaces are up and have a non-zero address
-# - there are any DHCP interfaces started
-# - any non-loopback IPv6 interfaces are up
-#
-# If we weren't asked to configure any interfaces, exit
-if [ -z "$inet_list" ] && [ -z "$inet6_list" ]; then
- # Config error if DHCP was attempted without plumbed interfaces
- [ -n "$i4d_fail" ] && exit $SMF_EXIT_ERR_CONFIG
- exit $SMF_EXIT_OK
+if [[ $admin_ip == 'none' ]]; then
+ #
+ # We're done, even if there are not any usable IP addresses.
+ #
+ exit $SMF_EXIT_OK
fi
# Any non-loopback IPv4 interfaces with usable addresses up?
-if [ -n "`/sbin/ifconfig -a4u`" ]; then
- /sbin/ifconfig -a4u | while read intf addr rest; do
- [ $intf = inet ] && [ $addr != 127.0.0.1 ] &&
- [ $addr != 0.0.0.0 ] && exit $SMF_EXIT_OK
- done && exit $SMF_EXIT_OK
+if [[ -n "`/sbin/ifconfig -a4u`" ]]; then
+ /sbin/ifconfig -a4u | while read intf addr rest; do
+ [[ ${intf} == "inet" ]] && [[ ${addr} != "127.0.0.1" ]] &&
+ [[ ${addr} != "0.0.0.0" ]] && exit ${SMF_EXIT_OK}
+ done && exit ${SMF_EXIT_OK}
fi
# Any DHCP interfaces started?
-[ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ] && exit $SMF_EXIT_OK
+[[ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ]] && exit ${SMF_EXIT_OK}
# Any non-loopback IPv6 interfaces up?
-if [ -n "`/sbin/ifconfig -au6`" ]; then
- /sbin/ifconfig -au6 | while read intf addr rest; do
- [ $intf = inet6 ] && [ $addr != ::1/128 ] && exit $SMF_EXIT_OK
- done && exit $SMF_EXIT_OK
+if [[ -n "`/sbin/ifconfig -au6`" ]]; then
+ /sbin/ifconfig -au6 | while read intf addr rest; do
+ [[ ${intf} = "inet6" ]] && [[ ${addr} != "::1/128" ]] && exit ${SMF_EXIT_OK}
+ done && exit ${SMF_EXIT_OK}
fi
# This service was supposed to configure something yet didn't. Exit
# with config error.
-exit $SMF_EXIT_ERR_CONFIG
+exit ${SMF_EXIT_ERR_CONFIG}
diff --git a/usr/src/cmd/svc/milestone/network-early-admin.xml b/usr/src/cmd/svc/milestone/network-early-admin.xml
new file mode 100644
index 0000000000..6566f31bff
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/network-early-admin.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0"?>
+<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
+<!--
+ Copyright 2019, Joyent, Inc.
+
+ This file and its contents are supplied under the terms of the
+ Common Development and Distribution License ("CDDL"), version 1.0.
+ You may only use this file in accordance with the terms of version
+ 1.0 of the CDDL.
+
+ A full copy of the text of the CDDL should have accompanied this
+ source. A copy of the CDDL is also available via the Internet at
+ http://www.illumos.org/license/CDDL.
+
+-->
+
+<service_bundle type='manifest' name='network-early-admin'>
+
+<service
+ name='network/early-admin'
+ type='service'
+ version='1'>
+
+ <!-- ifconfig needs loopback for IPC with dhcpagent -->
+ <dependency
+ name='network'
+ grouping='require_all'
+ restart_on='none'
+ type='service'>
+ <service_fmri value='svc:/network/loopback' />
+ <service_fmri value='svc:/network/datalink-management' />
+ <service_fmri value='svc:/network/ip-interface-management' />
+ </dependency>
+
+ <instance name='default' enabled='true'>
+
+ <exec_method
+ type='method'
+ name='start'
+ exec='/lib/svc/method/net-early-admin'
+ timeout_seconds='600' />
+
+ <exec_method
+ type='method'
+ name='stop'
+ exec=':true'
+ timeout_seconds='3' />
+
+ <property_group name='startd' type='framework'>
+ <propval name='duration' type='astring' value='transient' />
+ </property_group>
+
+ <template>
+ <common_name>
+ <loctext xml:lang='C'>
+ Triton admin network on compute nodes
+ </loctext>
+ </common_name>
+ <documentation>
+ <manpage title='ifconfig' section='1M'
+ manpath='/usr/share/man' />
+ <manpage title='dladm' section='1M'
+ manpath='/usr/share/man' />
+ </documentation>
+ </template>
+
+ </instance>
+
+ <stability value='Unstable' />
+
+</service>
+
+</service_bundle>
diff --git a/usr/src/cmd/svc/milestone/network-location.xml b/usr/src/cmd/svc/milestone/network-location.xml
index 709e9df8f3..5e23d92481 100644
--- a/usr/src/cmd/svc/milestone/network-location.xml
+++ b/usr/src/cmd/svc/milestone/network-location.xml
@@ -81,14 +81,6 @@
</dependency>
<dependency
- name='location_netcfg'
- grouping='require_all'
- restart_on='none'
- type='service'>
- <service_fmri value='svc:/network/netcfg:default' />
- </dependency>
-
- <dependency
name='filesystem'
grouping='require_all'
restart_on='none'
@@ -106,7 +98,7 @@
-->
<dependency
name='manifest-import'
- grouping='optional_all'
+ grouping='require_all'
restart_on='none'
type='service'>
<service_fmri value='svc:/system/manifest-import:default' />
diff --git a/usr/src/cmd/svc/milestone/network-physical.xml b/usr/src/cmd/svc/milestone/network-physical.xml
index d43bed06ec..62b89bbccc 100644
--- a/usr/src/cmd/svc/milestone/network-physical.xml
+++ b/usr/src/cmd/svc/milestone/network-physical.xml
@@ -4,6 +4,8 @@
Copyright 2010 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
+ Copyright 2019 Joyent, Inc.
+
CDDL HEADER START
The contents of this file are subject to the terms of the
@@ -45,22 +47,34 @@
<service_fmri value='svc:/network/loopback' />
</dependency>
- <instance name='default' enabled='true'>
+ <dependency
+ name='joyent'
+ grouping='require_all'
+ restart_on='none'
+ type='service'>
+ <service_fmri value='svc:/system/filesystem/smartdc' />
+ </dependency>
- <!--
- physical:default and physical:nwam are mutually exclusive.
- Use a one-way dependency for now since two-way exclude_all
- does not work; enforcement of single_instance in the future
- will fix this.
- -->
<dependency
- name='physical_nwam'
- grouping='exclude_all'
+ name='mdata-fetch'
+ grouping='optional_all'
restart_on='none'
type='service'>
- <service_fmri value='svc:/network/physical:nwam' />
+ <service_fmri value='svc:/smartdc/mdata:fetch' />
</dependency>
+ <!-- Prevent this and network/early-admin from trying to configure the
+ admin interface at the same time -->
+ <dependency
+ name='early-admin'
+ grouping='optional_all'
+ restart_on='none'
+ type='service'>
+ <service_fmri value='svc:/network/early-admin:default' />
+ </dependency>
+
+ <instance name='default' enabled='true'>
+
<exec_method
type='method'
name='start'
@@ -91,82 +105,6 @@
</instance>
- <instance name='nwam' enabled='false'>
-
- <exec_method
- type='method'
- name='start'
- exec='/lib/svc/method/net-nwam start'
- timeout_seconds='120' >
- <method_context>
- <method_credential user='root' group='root'
- supp_groups='netadm' privileges='zone' />
- </method_context>
- </exec_method>
-
- <exec_method
- type='method'
- name='stop'
- exec='/lib/svc/method/net-nwam stop'
- timeout_seconds='60' >
- <method_context>
- <method_credential user='root' group='root'
- supp_groups='netadm' privileges='zone' />
- </method_context>
- </exec_method>
-
- <exec_method
- type='method'
- name='refresh'
- exec='/lib/svc/method/net-nwam refresh'
- timeout_seconds='60' >
- <method_context>
- <method_credential user='root' group='root'
- supp_groups='netadm' privileges='zone' />
- </method_context>
- </exec_method>
-
- <property_group name='general' type='framework'>
- <!-- to start/stop NWAM services -->
- <propval name='action_authorization' type='astring'
- value='solaris.smf.manage.nwam' />
- <propval name='value_authorization' type='astring'
- value='solaris.smf.manage.nwam' />
- </property_group>
-
- <property_group name='nwamd' type='application'>
- <stability value='Unstable' />
- <propval name='debug' type='boolean' value='false' />
- <propval name='autoconf' type='boolean' value='false' />
- <propval name='ncu_wait_time' type='count' value='60' />
- <propval name='condition_check_interval' type='count'
- value='120' />
- <propval name='scan_interval' type='count' value='120' />
- <propval name='scan_level' type='astring' value='weak' />
- <propval name='strict_bssid' type='boolean' value='false' />
- <propval name='active_ncp' type='astring' value='Automatic' />
- <propval name='value_authorization' type='astring'
- value='solaris.smf.value.nwam' />
- </property_group>
-
- <template>
- <common_name>
- <loctext xml:lang='C'>
- physical network interface autoconfiguration
- </loctext>
- </common_name>
- <documentation>
- <manpage title='nwamd' section='1M'
- manpath='/usr/share/man' />
- <doc_link
- name='Network Auto-Magic OpenSolaris Project Page'
- uri='http://hub.opensolaris.org/bin/view/Project+nwam/'
- />
- </documentation>
- </template>
-
- </instance>
-
<stability value='Unstable' />
</service>
diff --git a/usr/src/cmd/svc/milestone/smartdc-config b/usr/src/cmd/svc/milestone/smartdc-config
new file mode 100755
index 0000000000..510c93add6
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/smartdc-config
@@ -0,0 +1,211 @@
+#!/bin/bash
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2019 Joyent, Inc.
+#
+
+#
+# Despite its "smartdc/config" name, this service is used both for SmartOS and
+# Triton. It has two jobs:
+#
+# During an initial setup, this runs through the initial (possibly interactive)
+# configuration.
+#
+# During normal operation, it does some miscellaneous configuration based on
+# /usbkey/config (which, under Triton, will have already been updated from the
+# USB key by svc:/system/filesystem/smartdc:default).
+#
+
+set -o errexit
+set -o xtrace
+
+. /lib/svc/share/smf_include.sh
+. /lib/sdc/config.sh
+
+export PATH="/usr/sbin:/sbin:/usr/bin"
+
+set_root_password() {
+ enc_password=$1
+
+ sed -e "s|^root:[^\:]*:|root:${enc_password}:|" /etc/shadow > /etc/shadow.new \
+ && chmod 400 /etc/shadow.new \
+ && mv /etc/shadow.new /etc/shadow
+}
+
+case "$1" in
+'start')
+
+ # If we're a headnode, see if we have to do interactive configuration.
+ if /bin/bootparams | grep "^headnode=true" > /dev/null 2>&1; then
+ USB_PATH=/mnt/`svcprop -p "joyentfs/usb_mountpoint" svc:/system/filesystem/smartdc:default`
+
+ # Check for config and run interactive if it doesn't exist.
+ if [[ ! -f ${USB_PATH}/config ]]; then
+ if /bin/bootparams | grep "^noimport=true" >/dev/null 2>&1; then
+ # Skipping interactive config, bypass rest of script.
+ exit $SMF_EXIT_OK
+ fi
+
+ /smartdc/lib/sdc-on-tty -d /dev/console \
+ ${USB_PATH}/scripts/prompt-config.sh "${USB_PATH}"
+
+ # If user quit from interactive configuration then we're done.
+ [[ ! -f ${USB_PATH}/config ]] && exit $SMF_EXIT_OK
+ fi
+ elif /bin/bootparams | grep "^smartos=true" > /dev/null 2>&1; then
+ USB_PATH=/`svcprop -p "joyentfs/usb_copy_path" svc:/system/filesystem/smartdc:default`
+
+ # Check for config and run interactive if it doesn't exist.
+ if [[ ! -f ${USB_PATH}/config ]]; then
+ if /bin/bootparams | grep "^noimport=true" >/dev/null 2>&1; then
+ # Skipping interactive config, bypass rest of script.
+ exit $SMF_EXIT_OK
+ fi
+
+ /smartdc/lib/sdc-on-tty -d /dev/console \
+ /smartdc/lib/smartos_prompt_config.sh "${USB_PATH}"
+
+ # If user quit from interactive configuration then we're done.
+ [[ ! -f ${USB_PATH}/config ]] && exit $SMF_EXIT_OK
+ fi
+ fi
+
+ # This puts config vars in CONFIG_
+ load_sdc_config
+ load_sdc_sysinfo
+
+ # Write the info about this datacenter to /.dcinfo so we can use in the GZ
+ echo "SDC_DATACENTER_NAME='${CONFIG_datacenter_name}'" > /.dcinfo
+
+ if [[ -n "${SYSINFO_Bootparam_smartos}" && -f /usbkey/shadow ]]; then
+ echo "setting root password from /usbkey/shadow"
+ # Boot parameter takes precidence over config
+ elif [[ -n "${SYSINFO_Bootparam_root_shadow}" ]]; then
+ set_root_password "${SYSINFO_Bootparam_root_shadow}"
+ echo "Set root password boot parameters."
+ elif [[ -n "${CONFIG_root_shadow}" ]]; then
+ set_root_password "${CONFIG_root_shadow}"
+ echo "Set root password from config."
+ else
+ echo "No root shadow entry in the config, cannot set."
+ fi
+
+ # Set authorized_keys for root
+ if [[ -n "${CONFIG_root_authorized_keys_file}" ]] \
+ && [[ -n "${CONFIG_config_inc_dir}" ]] \
+ && [[ -d "${CONFIG_config_inc_dir}" ]] \
+ && [[ -f "${CONFIG_config_inc_dir}/${CONFIG_root_authorized_keys_file}" ]]; then
+
+ mkdir -p /root/.ssh
+ cp "${CONFIG_config_inc_dir}/${CONFIG_root_authorized_keys_file}" /root/.ssh/authorized_keys
+ chmod 0600 /root/.ssh/authorized_keys
+ chmod 0700 /root/.ssh
+ fi
+
+ if [[ -n "${CONFIG_ntp_conf_file}" ]] \
+ && [[ -n "${CONFIG_config_inc_dir}" ]] \
+ && [[ -d "${CONFIG_config_inc_dir}" ]] \
+ && [[ -f "${CONFIG_config_inc_dir}/${CONFIG_ntp_conf_file}" ]]; then
+ #
+ # We were given a valid NTP configuration file, so use it without
+ # modification:
+ #
+ cp "${CONFIG_config_inc_dir}/${CONFIG_ntp_conf_file}" \
+ /etc/inet/ntp.conf
+ echo "Copied NTP configuration."
+ else
+ #
+ # If we have an admin network defined, allow time service from this
+ # network:
+ #
+ ntp_aflag=
+ if [[ -n ${CONFIG_admin_network} && -n ${CONFIG_admin_netmask} ]]; then
+ if [[ "${CONFIG_admin_network}" != "..." ]]; then
+ ntp_aflag="-a ${CONFIG_admin_network}/${CONFIG_admin_netmask}"
+ fi
+ fi
+
+ #
+ # If we were given a list of servers, use it:
+ #
+ ntp_hosts="${CONFIG_ntp_hosts}"
+ if [[ -z "${ntp_hosts}" ]]; then
+ #
+ # Otherwise, use the default SmartOS vendor pool from the NTP
+ # Pool Project:
+ #
+ ntp_hosts='0.smartos.pool.ntp.org'
+ fi
+
+ #
+ # Generate NTP configuration:
+ #
+ if ! /smartdc/lib/ntp_config -f /etc/inet/ntp.conf \
+ -s "${ntp_hosts}" ${ntp_aflag}; then
+ echo "FATAL: could not configure NTP" >&2
+ exit ${SMF_EXIT_ERR_CONFIG}
+ fi
+ echo "Generated NTP configuration."
+ fi
+
+ # set the keymap. For dvorak for instance
+ if [[ -n ${CONFIG_default_keymap} ]]; then
+ /usr/bin/loadkeys ${CONFIG_default_keymap}
+ fi
+
+ #
+ # In SmartOS, disabling SMT via the boot option is a pain, so we support a
+ # config option in /usbkey/config, the official mechanism for permanent
+ # configuration. We'd like to do this earlier but we have to wait for
+ # /usbkey to be mounted first. This does imply we've potentially handed out
+ # "too many" interrupts for the set of CPUs remaining online.
+ #
+ if [[ -n $(/bin/bootparams | grep '^smartos=true') ]]; then
+ if [[ "$CONFIG_smt_enabled" = "false" ]]; then
+ psradm -aS || exit $SMF_EXIT_ERR_FATAL
+ fi
+ fi
+
+ # Enable virtual terminals to support interactive installation
+ vtdaemon="svc:/system/vtdaemon"
+ svccfg -s ${vtdaemon} setprop options/hotkeys=true
+ svcadm refresh ${vtdaemon}
+ svcadm enable ${vtdaemon}
+ svcadm enable svc:/system/console-login:vt2
+ svcadm enable svc:/system/console-login:vt3
+ svcadm enable svc:/system/console-login:vt4
+ svcadm enable svc:/system/console-login:vt5
+ svcadm enable svc:/system/console-login:vt6
+
+ # force update of sysinfo (and dump to stdout so we have in the log)
+ sysinfo -f
+
+ ;;
+
+'stop')
+ ;;
+
+*)
+ echo "Usage: $0 { start | stop }"
+ exit $SMF_EXIT_ERR_FATAL
+ ;;
+esac
+exit $SMF_EXIT_OK
diff --git a/usr/src/cmd/svc/milestone/smartdc-config.xml b/usr/src/cmd/svc/milestone/smartdc-config.xml
new file mode 100644
index 0000000000..bf84d1991b
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/smartdc-config.xml
@@ -0,0 +1,145 @@
+<?xml version="1.0"?>
+<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
+<!--
+ Copyright 2011 Joyent, Inc. All rights reserved.
+ Use is subject to license terms.
+
+ CDDL HEADER START
+
+ The contents of this file are subject to the terms of the
+ Common Development and Distribution License (the "License").
+ You may not use this file except in compliance with the License.
+
+ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ or http://www.opensolaris.org/os/licensing.
+ See the License for the specific language governing permissions
+ and limitations under the License.
+
+ When distributing Covered Code, include this CDDL HEADER in each
+ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ If applicable, add the following below this CDDL HEADER, with the
+ fields enclosed by brackets "[]" replaced with your own identifying
+ information: Portions Copyright [yyyy] [name of copyright owner]
+
+ CDDL HEADER END
+
+ NOTE: This service manifest is not editable; its contents will
+ be overwritten by package or patch operations, including
+ operating system upgrade. Make customizations in a different
+ file.
+-->
+
+<service_bundle type='manifest' name='smartdc:config'>
+
+<!--
+ This service applies inital configuration for the GZ in smartdc.
+-->
+<service
+ name='system/smartdc/config'
+ type='service'
+ version='1'>
+
+ <create_default_instance enabled='true' />
+
+ <single_instance />
+
+ <!--
+ dependency/dependent info
+ We need to wait for fs-joyent to be done so we can access the USB key
+ We need to run before sysconfig so interactive configuration can talk
+ on the console
+ (sysconfig)
+ We don't want anything else running which spews on console
+ (system/identy)
+ We don't want manifest import scribbling on the console while running
+ (manifest-import)
+ network/physical can't run without a config file
+ (network/physical)
+ -->
+ <dependency
+ name='filesystem-joyent'
+ type='service'
+ grouping='require_all'
+ restart_on='none'>
+ <service_fmri value='svc:/system/filesystem/smartdc' />
+ </dependency>
+
+ <!--
+ We don't want ssh starting if we haven't updated the passwords/keys
+ -->
+ <dependent
+ name='ssh_multi-user-server'
+ grouping='require_all'
+ restart_on='none'>
+ <service_fmri value='svc:/network/ssh' />
+ </dependent>
+
+ <!-- Make ntp wait so we can setup the config. -->
+ <dependent
+ name='ntp'
+ grouping='require_all'
+ restart_on='none'>
+ <service_fmri value='svc:/network/ntp' />
+ </dependent>
+
+ <dependent
+ name='headnode_config'
+ grouping='optional_all'
+ restart_on='none'>
+ <service_fmri value='svc:/milestone/sysconfig' />
+ </dependent>
+
+ <dependent
+ name='identity'
+ grouping='optional_all'
+ restart_on='none'>
+ <service_fmri value='svc:/system/identity:node' />
+ </dependent>
+
+ <dependent
+ name='headnode_no_output'
+ grouping='optional_all'
+ restart_on='none'>
+ <service_fmri value='svc:/system/manifest-import' />
+ </dependent>
+
+ <dependent
+ name='network-physical'
+ grouping='optional_all'
+ restart_on='none'>
+ <service_fmri value='svc:/network/physical:default' />
+ </dependent>
+
+ <exec_method
+ type='method'
+ name='start'
+ exec='/lib/svc/method/smartdc-config %m'
+ timeout_seconds='0'>
+ </exec_method>
+
+ <exec_method
+ type='method'
+ name='stop'
+ exec='/lib/svc/method/smartdc-config %m'
+ timeout_seconds='60'>
+ </exec_method>
+
+ <property_group name='startd' type='framework'>
+ <propval name='duration' type='astring' value='transient' />
+ </property_group>
+
+ <stability value='Unstable' />
+
+ <template>
+ <common_name>
+ <loctext xml:lang='C'>
+ SmartDC live-image config management service
+ </loctext>
+ </common_name>
+ <documentation>
+ <manpage title='smartdc' section='5' manpath='/usr/share/man' />
+ </documentation>
+ </template>
+</service>
+
+</service_bundle>
diff --git a/usr/src/cmd/svc/milestone/smartdc-init b/usr/src/cmd/svc/milestone/smartdc-init
new file mode 100755
index 0000000000..1b2a550095
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/smartdc-init
@@ -0,0 +1,246 @@
+#!/bin/bash
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2018, Joyent, Inc.
+#
+
+export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
+set -o xtrace
+
+. /lib/svc/share/smf_include.sh
+. /lib/sdc/config.sh
+
+# Make sure working directory is / to prevent unmounting problems.
+cd /
+PATH=/usr/sbin:/usr/bin; export PATH
+
+wait_and_clear()
+{
+ while [ true ]; do
+ # It seems like jobs -p can miscount if we don't run jobs first
+ jobs >/dev/null
+ local cnt=`jobs -p | wc -l`
+ [ $cnt -eq 0 ] && break
+ for s in `svcs -x | nawk '{
+ if ($1 ~ /^svc:/) nm=$1
+ if ($1 == "State:" && $2 == "maintenance") print nm
+ }'`
+ do
+ svcadm clear $s
+ done
+ sleep 1
+ done
+}
+
+# Sets the default firewall rules for a node (unless they're already set)
+set_default_fw_rules() {
+ local fw_default_v
+ if [[ -f /var/fw/.default_rules_setup ]]; then
+ read fw_default_v < /var/fw/.default_rules_setup
+ else
+ fw_default_v=0
+ fi
+
+ # Handle empty files from before we started versioning default rules
+ if [[ -z $fw_default_v ]]; then
+ fw_default_v=1
+ fi
+
+ if [[ $fw_default_v -lt 1 ]]; then
+ /usr/sbin/fwadm add -f - <<RULES
+{
+ "rules": [
+ {
+ "description": "allow all ICMPv4 types",
+ "rule": "FROM any TO all vms ALLOW icmp type all",
+ "enabled": true,
+ "global": true
+ }
+ ]
+}
+RULES
+ [[ $? -ne 0 ]] && return 1
+ echo 1 > /var/fw/.default_rules_setup
+ fi
+
+ if [[ $fw_default_v -lt 2 ]]; then
+ /usr/sbin/fwadm add -f - <<RULES
+{
+ "rules": [
+ {
+ "description": "allow all ICMPv6 types",
+ "rule": "FROM any TO all vms ALLOW icmp6 type all",
+ "enabled": true,
+ "global": true
+ }
+ ]
+}
+RULES
+ [[ $? -ne 0 ]] && return 1
+ echo 2 > /var/fw/.default_rules_setup
+ fi
+}
+
+configure_fwadm()
+{
+ if [[ ! -d /var/log/fw/logs ]]; then
+ mkdir -p /var/log/fw/logs
+ mv /var/log/fw/*-*.log /var/log/fw/logs
+ fi
+
+ # See also OS-2635
+ if [[ -f /var/log/fw/fw.log.0 ]]; then
+ for file in /var/log/fw/fw.log.[0-9]*; do
+ mv ${file} "/var/log/fw/fwadm_$(uname -n)_$(stat -c "%y" ${file} | cut -d'.' -f1 | tr ' ' 'T').log"
+ done
+ fi
+ if [[ -f /var/log/fw/fw.log ]]; then
+ mv /var/log/fw/fw.log /var/log/fw/fwadm.log
+ fi
+
+ if [[ ! -e /var/log/fw/fwadm.log ]]; then
+ touch /var/log/fw/fwadm.log
+ fi
+}
+
+configure_vmadm()
+{
+ # ensure /var/log/vm exists for VM.log logs
+ mkdir -p /var/log/vm/logs
+
+ # See also OS-2635
+ if [[ -f /var/log/vm/vm.log.0 ]]; then
+ for file in /var/log/vm/vm.log.[0-9]*; do
+ mv ${file} "/var/log/vm/vmadm_$(uname -n)_$(stat -c "%y" ${file} | cut -d'.' -f1 | tr ' ' 'T').log"
+ done
+ fi
+ if [[ -f /var/log/vm/vm.log ]]; then
+ mv /var/log/vm/vm.log /var/log/vm/vmadm.log
+ fi
+
+ # need to create this file so rotation works
+ if [[ ! -e /var/log/vm/vmadm.log ]]; then
+ touch /var/log/vm/vmadm.log
+ fi
+}
+
+update_root_password()
+{
+
+ enc_password=`nawk -F= '{
+ if ($1 == "root_shadow")
+ print substr($2, 2, length($2) - 2)
+ }' /opt/smartdc/config/node.config`
+
+ [[ -z "$enc_password" ]] && return 0
+
+ sed -e "s|^root:[^\:]*:|root:${enc_password}:|" /etc/shadow \
+ >/etc/shadow.new \
+ && chmod 400 /etc/shadow.new \
+ && mv /etc/shadow.new /etc/shadow
+}
+
+# Loads config file for the node. These are the config values from the headnode
+# plus authorized keys and anything else we want.
+# This function is only invoked on a compute node.
+install_config()
+{
+ # On standalone machines we don't do this update
+ [[ -n $(/usr/bin/bootparams | grep "^standalone=true") ]] && return 0
+
+ load_sdc_config
+
+ curl -k -o /tmp/node.config --silent \
+ "http://${CONFIG_assets_admin_ip}/extra/joysetup/node.config"
+
+ [[ ! -f /tmp/node.config ]] && return 0
+ grep datacenter_name /tmp/node.config >/dev/null 2>&1
+ if [ $? != 0 ]; then
+ # There is no valid config file served by the assets zone
+ rm -f /tmp/node.config
+ return 0
+ fi
+
+ # Install the file if the local copy is different
+ diff /tmp/node.config /opt/smartdc/config/node.config >/dev/null 2>&1
+ if [ $? != 0 ]; then
+ printf "Updating config file\n" >/dev/console
+ mkdir -p /opt/smartdc/config
+ mv /tmp/node.config /opt/smartdc/config
+ update_root_password
+ else
+ rm -f /tmp/node.config
+ fi
+}
+
+case "$1" in
+'start')
+
+ # Always setup socket filter no matter what happens next.
+ /sbin/soconfig -F datafilt datafilt prog '2:2:0,2:2:6,26:2:0,26:2:6'
+
+ USBMOUNT=
+
+ # If we're not importing the pools, we shouldn't try to setup as a headnode
+ # (since there'll be no zpool)
+ if /bin/bootparams | grep "^noimport=true" > /dev/null 2>&1; then
+ exit $SMF_EXIT_OK
+ fi
+
+ # If we're a headnode, we'll not have AMQP args on the cmdline, and we want
+ # to run an initial_script first anyway.
+ if /bin/bootparams | grep "^headnode=true" > /dev/null 2>&1; then
+ USBMOUNT=/mnt/`svcprop -p joyentfs/usb_mountpoint svc:/system/filesystem/smartdc:default`
+
+ # No config file (e.g. user quit during interactive configuration), so
+ # treat as if "noimport=true".
+ [[ ! -f $USBMOUNT/config ]] && exit $SMF_EXIT_OK
+
+ initial_script=${USBMOUNT}/$(grep "^initial_script=" $USBMOUNT/config.inc/generic 2>/dev/null | cut -d'=' -f2-)
+ if [ -n ${initial_script} ] && [ -e ${initial_script} ]; then
+ # Execute the script
+ ${initial_script}
+ result=$?
+ if [ ${result} -eq 2 ]; then
+ # we're rebooting, no need to start ur
+ echo "REBOOTING!" >> /dev/console
+ enable_ur="false"
+ elif [ ${result} -ne 0 ]; then
+ echo "WARNING: initial_script failed with exit code [${result}]."
+ exit $SMF_EXIT_ERR_FATAL
+ fi
+ fi
+ elif /bin/bootparams | grep "^smartos=true" > /dev/null 2>&1; then
+ set_default_fw_rules
+ else
+ install_config
+ fi
+
+ configure_fwadm
+ configure_vmadm
+
+ if /bin/bootparams | grep "^headnode=true" > /dev/null 2>&1; then
+ /usr/sbin/umount $USBMOUNT
+ fi
+
+ ;;
+
+'stop')
+ ;;
+
+*)
+ echo "Usage: $0 { start | stop }"
+ exit $SMF_EXIT_ERR_FATAL
+ ;;
+esac
+exit $SMF_EXIT_OK
diff --git a/usr/src/cmd/svc/milestone/smartdc-init.xml b/usr/src/cmd/svc/milestone/smartdc-init.xml
new file mode 100644
index 0000000000..266aac53df
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/smartdc-init.xml
@@ -0,0 +1,124 @@
+<?xml version="1.0"?>
+<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
+<!--
+ Copyright 2012 Joyent, Inc. All rights reserved.
+ Use is subject to license terms.
+
+ CDDL HEADER START
+
+ The contents of this file are subject to the terms of the
+ Common Development and Distribution License (the "License").
+ You may not use this file except in compliance with the License.
+
+ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ or http://www.opensolaris.org/os/licensing.
+ See the License for the specific language governing permissions
+ and limitations under the License.
+
+ When distributing Covered Code, include this CDDL HEADER in each
+ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ If applicable, add the following below this CDDL HEADER, with the
+ fields enclosed by brackets "[]" replaced with your own identifying
+ information: Portions Copyright [yyyy] [name of copyright owner]
+
+ CDDL HEADER END
+
+ NOTE: This service manifest is not editable; its contents will
+ be overwritten by package or patch operations, including
+ operating system upgrade. Make customizations in a different
+ file.
+-->
+
+<service_bundle type='manifest' name='Joyent:joyent'>
+
+<!--
+ This service imports the zone's zpool on bootup, before zones try to
+ start. It also sets up configuration data on that zpool, if necessary.
+-->
+<service
+ name='system/smartdc/init'
+ type='service'
+ version='1'>
+
+ <create_default_instance enabled='true' />
+
+ <single_instance />
+
+ <!--
+ dependency info
+ This depends on the system/zones svc which seems weird since that
+ svc runs late in boot because it depends on milestone/multi-user-server.
+ Our svc does the initial setup of the infrastructure zones on the
+ headnode so we need the system/zones svc to run first so that we can
+ install and boot the infrastructure zones. The reason this seems
+ weird is that this svc also sets up the zpool when we first boot,
+ before we reboot to install the infrastructure zones, so it might seem
+ like it should run early in boot, but it can't because of the zone
+ issue described above.
+
+ The dependency on network/physical is needed since all of the earlier
+ svcs which have a dependency on network/physical are using optional_all.
+ That makes sense for those svcs since they can come up without a
+ network, but for SmartOS, by this point we require the network to be
+ there.
+ -->
+ <dependency
+ name='zones'
+ type='service'
+ grouping='require_all'
+ restart_on='none'>
+ <service_fmri value='svc:/system/zones' />
+ </dependency>
+
+ <dependency
+ name='net-physical'
+ type='service'
+ grouping='require_all'
+ restart_on='none'>
+ <service_fmri value='svc:/network/physical' />
+ </dependency>
+
+ <exec_method
+ type='method'
+ name='start'
+ exec='/lib/svc/method/smartdc-init %m'
+ timeout_seconds='0'>
+ </exec_method>
+
+ <exec_method
+ type='method'
+ name='stop'
+ exec='/lib/svc/method/smartdc-init %m'
+ timeout_seconds='60'>
+ </exec_method>
+
+ <property_group name='startd' type='framework'>
+ <propval name='duration' type='astring' value='transient' />
+ </property_group>
+
+ <!--
+ The zpool holding the zones (this must be imported).
+ -->
+ <property_group name='config' type='application'>
+ <propval name='zpool' type='astring' value='zones' />
+ </property_group>
+
+ <stability value='Unstable' />
+
+ <template>
+ <common_name>
+ <loctext xml:lang='C'>
+ Joyent live-image management service
+ </loctext>
+ </common_name>
+ <documentation>
+ <manpage title='zones' section='5' manpath='/usr/share/man' />
+ <manpage
+ title='zpool'
+ section='1M'
+ manpath='/usr/share/man' />
+ </documentation>
+ </template>
+</service>
+
+</service_bundle>
diff --git a/usr/src/cmd/svc/milestone/smartdc-ur b/usr/src/cmd/svc/milestone/smartdc-ur
new file mode 100755
index 0000000000..2c32482368
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/smartdc-ur
@@ -0,0 +1,79 @@
+#!/bin/bash
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2010-2011 Joyent, Inc. All rights reserved.
+# Use is subject to license terms.
+
+set -o xtrace
+
+. /lib/svc/share/smf_include.sh
+. /lib/sdc/config.sh
+
+PATH=/usr/sbin:/usr/bin; export PATH
+
+if [[ -n "$(/bin/bootparams | grep "^standalone=true")" ||
+ -n "$(/bin/bootparams | grep "^smartos=true")" ]]; then
+ # Standalone and SmartOS systems do not need ur
+ svcadm disable "${SMF_FMRI}"
+ exit $SMF_EXIT_OK
+fi
+
+case "$1" in
+'start')
+ #
+ # Grab AMQP parameters from the kernel command line or headnode config
+ #
+
+ load_sdc_config
+ load_sdc_sysinfo
+
+ if [[ -n ${SYSINFO_Bootparam_rabbitmq} ]]; then
+ rabbit=${SYSINFO_Bootparam_rabbitmq}
+ fi
+ if [[ -z ${rabbit} ]] && [[ -n ${CONFIG_rabbitmq} ]]; then
+ rabbit=${CONFIG_rabbitmq}
+ fi
+
+ if [[ -z $rabbit ]]; then
+ echo "unable to find AMQP parameters!"
+ exit $SMF_EXIT_ERR_FATAL
+ fi
+
+ export AMQP_LOGIN=$(echo $rabbit | cut -d: -f1)
+ export AMQP_PASSWORD=$(echo $rabbit | cut -d: -f2)
+ export AMQP_HOST=$(echo $rabbit | cut -d: -f3)
+ export AMQP_PORT=$(echo $rabbit | cut -d: -f4)
+ export NODE_PATH=/usr/node/node_modules
+
+ /usr/bin/ctrun -l child -o noorphan /smartdc/ur-agent/ur-agent 2>&1 &
+
+ ;;
+
+'stop')
+ ;;
+
+*)
+ echo "Usage: $0 { start | stop }"
+ exit $SMF_EXIT_ERR_FATAL
+ ;;
+esac
+exit $SMF_EXIT_OK
diff --git a/usr/src/cmd/svc/milestone/smartdc-ur.xml b/usr/src/cmd/svc/milestone/smartdc-ur.xml
new file mode 100644
index 0000000000..7ee78dcb02
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/smartdc-ur.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
+<!--
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+-->
+
+<!--
+ Copyright (c) 2014, Joyent, Inc.
+-->
+
+<service_bundle type="manifest" name="ur">
+ <service name="smartdc/agent/ur" type="service" version="0.0.1">
+
+ <create_default_instance enabled="true"/>
+ <single_instance/>
+
+ <dependency name="smartdc-init" grouping="require_all" restart_on="error" type="service">
+ <service_fmri value="svc:/milestone/single-user"/>
+ </dependency>
+
+ <exec_method
+ type="method"
+ name="start"
+ exec="/lib/svc/method/smartdc-ur %m"
+ timeout_seconds="60">
+ <method_context>
+ <method_credential user="root" group="staff"/>
+ </method_context>
+ </exec_method>
+
+ <exec_method type="method" name="restart" exec=":kill" timeout_seconds="60">
+ <method_context>
+ <method_credential user="root" group="staff"/>
+ </method_context>
+ </exec_method>
+
+ <exec_method type="method" name="stop" exec=":kill" timeout_seconds="60">
+ <method_context>
+ <method_credential user="root" group="staff"/>
+ </method_context>
+ </exec_method>
+
+ <property_group name="startd" type="framework">
+ <propval name="ignore_error" type="astring" value="core,signal"/>
+ </property_group>
+
+ <property_group name="application" type="application">
+ </property_group>
+
+ <stability value="Evolving"/>
+
+ <template>
+ <common_name>
+ <loctext xml:lang="C">Ur Agent (node)</loctext>
+ </common_name>
+ </template>
+
+ </service>
+
+</service_bundle>
diff --git a/usr/src/cmd/svc/milestone/sysidtool-net b/usr/src/cmd/svc/milestone/sysidtool-net
new file mode 100755
index 0000000000..538d17bba1
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/sysidtool-net
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+# This exists solely to support the service on older SmartOS zone images.
+
+exit 0
diff --git a/usr/src/cmd/svc/milestone/sysidtool-system b/usr/src/cmd/svc/milestone/sysidtool-system
new file mode 100755
index 0000000000..538d17bba1
--- /dev/null
+++ b/usr/src/cmd/svc/milestone/sysidtool-system
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+# This exists solely to support the service on older SmartOS zone images.
+
+exit 0
diff --git a/usr/src/cmd/svc/profile/Makefile b/usr/src/cmd/svc/profile/Makefile
index 32ec303879..8538e630f8 100644
--- a/usr/src/cmd/svc/profile/Makefile
+++ b/usr/src/cmd/svc/profile/Makefile
@@ -23,6 +23,7 @@
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
# Copyright 2019 Peter Tribble.
+# Copyright 2019 Joyent, Inc.
#
include ../../Makefile.cmd
@@ -32,6 +33,7 @@ FILEMODE = 0444
ROOTPROFILE = $(ROOT)/etc/svc/profile
PROFILESRCS = \
+ generic.xml \
generic_open.xml \
generic_limited_net.xml \
inetd_generic.xml \
@@ -61,7 +63,7 @@ TEST = /usr/bin/test
LISTSVCS = listsvcs.pl
install: all $(PROFILES)
- $(RM) $(ROOTPROFILE)/platform.xml
+ $(CP) platform_none.xml $(ROOTPROFILE)/platform.xml
# SUNW,Sun-Fire-V890
$(RM) $(ROOTPROFILE)/platform_SUNW,Sun-Fire-V890.xml
$(LN) $(ROOTPROFILE)/platform_SUNW,Sun-Fire-880.xml \
@@ -95,7 +97,7 @@ $(CHECK_OPEN) $(CHECK_LMTD): \
@$(COMM) -23 $@.enabled $@.all | $(TEE) $@.notcovered
@$(TEST) ! -s $@.notcovered && $(TOUCH) $@
-lint _msg:
+_msg:
clobber clean:
$(RM) $(CHECK_OPEN)* $(CHECK_LMTD)*
diff --git a/usr/src/cmd/svc/profile/generic.xml b/usr/src/cmd/svc/profile/generic.xml
new file mode 100644
index 0000000000..1920d1e8a6
--- /dev/null
+++ b/usr/src/cmd/svc/profile/generic.xml
@@ -0,0 +1,392 @@
+<?xml version='1.0'?>
+<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
+<!--
+ CDDL HEADER START
+
+ The contents of this file are subject to the terms of the
+ Common Development and Distribution License (the "License").
+ You may not use this file except in compliance with the License.
+
+ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ or http://www.opensolaris.org/os/licensing.
+ See the License for the specific language governing permissions
+ and limitations under the License.
+
+ When distributing Covered Code, include this CDDL HEADER in each
+ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ If applicable, add the following below this CDDL HEADER, with the
+ fields enclosed by brackets "[]" replaced with your own identifying
+ information: Portions Copyright [yyyy] [name of copyright owner]
+
+ CDDL HEADER END
+
+ Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ Use is subject to license terms.
+
+ The purpose of the limited_net profile is to provide a set of
+ active services that allow one to connect to the machine via ssh
+ (requires sshd). The services which are deactivated here are those
+ that are at odds with this goal. Those which are activated are
+ explicit requirements for the goal's satisfaction.
+
+ NOTE: Service profiles delivered by this package are not editable,
+ and their contents will be overwritten by package or patch
+ operations, including operating system upgrade. Make customizations
+ in a distinct file. The paths, /etc/svc/profile/site.xml and
+ /var/svc/profile/site.xml, are distinguished locations for site-specific
+ service profile, treated otherwise equivalently to this file.
+-->
+<service_bundle type='profile' name='generic_limited_net'
+ xmlns:xi='http://www.w3.org/2003/XInclude' >
+
+ <!--
+ svc.startd(1M) services
+ -->
+ <service name='system/cryptosvc' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/coreadm' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/metainit' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='system/cron' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/dbus' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/extended-accounting' version='1' type='service'>
+ <instance name='flow' enabled='false'/>
+ <instance name='process' enabled='false'/>
+ <instance name='task' enabled='false'/>
+ <instance name='net' enabled='false'/>
+ </service>
+ <service name='system/identity' version='1' type='service'>
+ <instance name='domain' enabled='true'/>
+ </service>
+ <service name='system/intrd' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/keymap' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/picl' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/sac' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='system/scheduler' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/system-log' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/utmp' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/zones' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/rcap' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='network/rpc/bind' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/name-service-cache' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='network/netmask' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/nfs/status' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/nfs/nlockmgr' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/nfs/client' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/nfs/server' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/nfs/rquota' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/nfs/cbd' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/nfs/mapid' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/smb/client' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <service name='network/ssh' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='network/smtp' version='1' type='service'>
+ <instance name='sendmail' enabled='false'/>
+ </service>
+ <service name='network/sendmail-client' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/inetd' version='1' type='restarter'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='system/filesystem/autofs' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='system/filesystem/rmvolmgr' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='system/power' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+
+ <service name='network/dns/multicast' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+ <service name='network/dhcp-server' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='network/ntp' version='1' type='service'>
+ <instance name='default' enabled='true' />
+ </service>
+ <service name='network/rarp' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='network/slp' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='network/security/kadmin' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='network/security/krb5_prop' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='network/security/krb5kdc' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+
+ <service name='application/management/net-snmp' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='application/management/seaport' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='application/management/snmpdx' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='application/management/wbem' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='application/print/ipp-listener' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='application/print/ppd-cache-update' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='application/print/rfc1179' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='application/cups/in-lpd' version='1' type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='application/stosreg' version='1' type='service'>
+ <instance name='default' enabled='true' />
+ </service>
+
+ <!--
+ default inetd(1M) services
+ -->
+ <service name='network/finger' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/ftp' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/login' version='1' type='service'>
+ <instance name='rlogin' enabled='false'/>
+ <instance name='klogin' enabled='false'/>
+ <instance name='eklogin' enabled='false'/>
+ </service>
+ <service name='network/shell' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ <instance name='kshell' enabled='false'/>
+ </service>
+ <service name='network/telnet' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <!--
+ non-default inetd(1M) services
+ -->
+ <service name='network/uucp' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/chargen' version='1' type='service'>
+ <instance name='stream' enabled='false'/>
+ <instance name='dgram' enabled='false'/>
+ </service>
+ <service name='network/daytime' version='1' type='service'>
+ <instance name='stream' enabled='false'/>
+ <instance name='dgram' enabled='false'/>
+ </service>
+ <service name='network/discard' version='1' type='service'>
+ <instance name='stream' enabled='false'/>
+ <instance name='dgram' enabled='false'/>
+ </service>
+ <service name='network/echo' version='1' type='service'>
+ <instance name='stream' enabled='false'/>
+ <instance name='dgram' enabled='false'/>
+ </service>
+ <service name='network/time' version='1' type='service'>
+ <instance name='stream' enabled='false'/>
+ <instance name='dgram' enabled='false'/>
+ </service>
+ <service name='network/comsat' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/rexec' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/talk' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/stdiscover' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/stlisten' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <!--
+ default inetd(1M) RPC services enabled
+ -->
+ <service name='network/rpc/gss' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/rpc/mdcomm' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/rpc/smserver' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/security/ktkt_warn' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <!--
+ default inetd(1M) RPC services disabled
+ -->
+ <service name='network/rpc/rstat' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/rpc/rusers' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/rpc/meta' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/rpc/metamed' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/rpc/metamh' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <!--
+ non-default inetd(1M) RPC services disabled
+ -->
+ <service name='network/rpc/rex' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/rpc/spray' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+ <service name='network/rpc/wall' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <!--
+ Disable Avahi mDNS bridge service
+ -->
+ <service name='system/avahi-bridge-dsd' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <!--
+ Enable CDE/ToolTalk/GDM services.
+ -->
+ <service name='network/rpc/cde-ttdbserver' version='1' type='service'>
+ <instance name='tcp' enabled='false' />
+ </service>
+ <service name='application/graphical-login/gdm' version='1'
+ type='service'>
+ <instance name='default' enabled='false' />
+ </service>
+ <service name='network/rpc/cde-calendar-manager' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <!--
+ Disable X11 services.
+ -->
+ <service name='application/x11/xfs' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <!--
+ pkg.depotd service
+ -->
+ <service name='system/pkgserv' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <!--
+ Enable VNC config service for xVM
+ -->
+ <service name='system/xvm/vnc-config' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <service name='system/xvm/ipagent' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <service name='application/print/service-selector' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <service name='system/dumpadm' version='1' type='service'>
+ <instance name='default' enabled='true'/>
+ </service>
+
+ <service name='system/metasync' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <service name='application/font/fc-cache' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <service name='system/consolekit' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <service name='application/opengl/ogl-select' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+ <service name='system/hal' version='1' type='service'>
+ <instance name='default' enabled='false'/>
+ </service>
+
+
+</service_bundle>
diff --git a/usr/src/cmd/syslogd/syslog.conf b/usr/src/cmd/syslogd/syslog.conf
index 1ed7a40d39..a894b3ed90 100644
--- a/usr/src/cmd/syslogd/syslog.conf
+++ b/usr/src/cmd/syslogd/syslog.conf
@@ -54,3 +54,7 @@ user.err /var/adm/messages
user.alert `root, operator'
user.emerg *
)
+
+auth.info /var/log/auth.log
+mail.info /var/log/postfix.log
+#local0.info /var/log/courier.log
diff --git a/usr/src/cmd/syslogd/system-log b/usr/src/cmd/syslogd/system-log
index b7608219fc..7f7ad92d96 100644
--- a/usr/src/cmd/syslogd/system-log
+++ b/usr/src/cmd/syslogd/system-log
@@ -21,10 +21,12 @@
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
+# Copyright 2016, Joyent, Inc. All rights reserved.
#
-# ident "%Z%%M% %I% %E% SMI"
OLD_CONF=/etc/default/syslogd
+DFLT_SUM="7c87d765805cc45a0dad9fb5c86cc4f2"
+CONF_SUM="$DFLT_SUM"
. /lib/svc/share/smf_include.sh
@@ -52,14 +54,72 @@ convert()
rm -f ${OLD_CONF}.new
}
-if [ ! -f /etc/syslog.conf ]; then
- echo "/etc/syslog.conf is missing. Exiting."
- exit $SMF_EXIT_ERR_CONFIG
+#
+# If the rsyslog.conf file doesn't exist and the syslog.conf file has not
+# been customized, generate the default rsyslog.conf.
+#
+generate_rsyslog_conf()
+{
+ if [ ! -f /etc/syslog.conf ]; then
+ return
+ fi
+
+ CONF_SUM=`nawk '{
+ if (substr($1, 1, 1) != "#" && NF != 0) print $0
+ }' /etc/syslog.conf | sum -x md5`
+
+ if [ "$CONF_SUM" != "$DFLT_SUM" ]; then
+ return
+ fi
+
+ cat <<-DONE >/etc/rsyslog.conf
+ #
+ # Sample rsyslog configuration file
+ #
+
+ $ModLoad immark
+ $ModLoad imsolaris
+ $ModLoad imtcp
+ $ModLoad imudp
+
+ *.err;kern.notice;auth.notice /dev/sysmsg
+ *.err;kern.debug;daemon.notice;mail.crit /var/adm/messages
+
+ *.alert;kern.err;daemon.err operator
+ *.alert root
+
+ *.emerg *
+
+ mail.debug /var/log/syslog
+
+ auth.info /var/log/auth.log
+ mail.info /var/log/postfix.log
+ DONE
+}
+
+if [ ! -f /etc/rsyslog.conf -a -x /usr/sbin/rsyslogd ]; then
+ generate_rsyslog_conf
fi
-if [ ! -x /usr/sbin/syslogd ]; then
- echo "Executable /usr/sbin/syslogd not found. Exiting"
- exit $SMF_EXIT_ERR_CONFIG
+if [ -f /etc/rsyslog.conf ]; then
+ if [ ! -x /usr/sbin/rsyslogd ]; then
+ echo "Executable /usr/sbin/rsyslogd not found or not executable. Exiting."
+ exit $SMF_EXIT_ERR_CONFIG
+ fi
+else
+ #
+ # Fall back to old syslogd
+ #
+ echo "/etc/rsyslog.conf is missing. Using syslogd instead."
+ if [ ! -f /etc/syslog.conf ]; then
+ echo "/etc/syslog.conf is missing. Exiting."
+ exit $SMF_EXIT_ERR_CONFIG
+ fi
+
+ if [ ! -x /usr/sbin/syslogd ]; then
+ echo "Executable /usr/sbin/syslogd not found or not executable. Exiting."
+ exit $SMF_EXIT_ERR_CONFIG
+ fi
fi
if smf_is_globalzone; then
@@ -80,6 +140,27 @@ if [ ! -f /var/adm/messages ]; then
/usr/bin/cp /dev/null /var/adm/messages
/usr/bin/chmod 0644 /var/adm/messages
fi
+
+if [ -f /etc/rsyslog.conf ]; then
+ #
+ # If we have a config file for the old syslogd, only run rsyslogd
+ # if there are no customizations in the old syslog.conf file.
+ #
+ if [ -f /etc/syslog.conf ]; then
+ CONF_SUM=`nawk '{
+ if (substr($1, 1, 1) != "#" && NF != 0) print $0
+ }' /etc/syslog.conf | sum -x md5`
+ fi
+
+ if [ "$CONF_SUM" == "$DFLT_SUM" ]; then
+ /usr/sbin/rsyslogd -c5 -n &
+ exit $SMF_EXIT_OK
+ fi
+fi
+
+#
+# Run the old syslogd
+#
remote=`awk -F= '
/^LOG_FROM_REMOTE=[yY][Ee][Ss]/ {print "true"}
/^LOG_FROM_REMOTE=[Nn][Oo]/ {print "false"}' < ${OLD_CONF}`
@@ -96,3 +177,10 @@ case ${remote} in
esac
/usr/sbin/syslogd >/dev/msglog 2>&1 &
+
+if [ -f /etc/rsyslog.conf ]; then
+ logger -p daemon.err \
+ "Not using rsyslogd because there is a custom /etc/syslog.conf file"
+fi
+
+exit $SMF_EXIT_OK
diff --git a/usr/src/cmd/zoneadm/svc-resource-mgmt b/usr/src/cmd/zoneadm/svc-resource-mgmt
index 762de4c0d8..57fd21c3d9 100644
--- a/usr/src/cmd/zoneadm/svc-resource-mgmt
+++ b/usr/src/cmd/zoneadm/svc-resource-mgmt
@@ -22,25 +22,19 @@
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
-
-# ident "%Z%%M% %I% %E% SMI"
-#
+# Copyright 2012 Joyent, Inc. All rights reserved.
. /lib/svc/share/smf_include.sh
-[ ! -f /etc/zones/global.xml ] && exit $SMF_EXIT_OK # No global zone
- # resource mgmt.
- # configuration
-
-[ ! -x /usr/sbin/zoneadm ] && exit $SMF_EXIT_OK # SUNWzoneu not installed
-
# Make sure working directory is / to prevent unmounting problems.
cd /
PATH=/usr/sbin:/usr/bin; export PATH
+smf_is_globalzone || exit $SMF_EXIT_OK
+
case "$1" in
'start')
- zoneadm -z global apply
+ prctl -r -n zone.cpu-shares -v 65535 -t priv -i zone global
if [ $? -ne 0 ]; then
exit $SMF_EXIT_ERR_FATAL
fi
diff --git a/usr/src/cmd/zoneadm/svc-zones b/usr/src/cmd/zoneadm/svc-zones
index 30d54f5272..41f6b3325f 100644
--- a/usr/src/cmd/zoneadm/svc-zones
+++ b/usr/src/cmd/zoneadm/svc-zones
@@ -22,9 +22,128 @@
#
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2014 Nexenta Systems, Inc. All rights reserved.
+# Copyright (c) 2012, Joyent Inc. All rights reserved.
+
+set -o xtrace
. /lib/svc/share/smf_include.sh
+ZPOOL=`svcprop -p config/zpool svc:/system/smartdc/init:default 2>/dev/null`
+ZPOOL=${ZPOOL:-zones}
+
+MAN_SRCDIR=/lib/svc/manifest
+MAN_DESTDIR=/$ZPOOL/manifests
+
+MAN_DIRS="\
+ application \
+ milestone \
+ network \
+ network/dns \
+ network/ipsec \
+ network/ldap \
+ network/loadbalancer \
+ network/nfs \
+ network/nis \
+ network/routing \
+ network/rpc \
+ network/security \
+ network/shares \
+ network/smb \
+ network/ssl \
+ site \
+ system \
+ system/device \
+ system/filesystem \
+ system/fm \
+ system/install \
+ system/security \
+ system/svc"
+
+cp_brand_manifests()
+{
+ brand=$1
+
+ # Create the dir hierarchy under the dest dir for SMF manifests.
+ mkdir -m755 $MAN_DESTDIR/$brand
+
+ for dir in $MAN_DIRS
+ do
+ mkdir -m755 $MAN_DESTDIR/$brand/$dir
+ done
+
+ #
+ # Process the SMF SVC configuration list to setup the brand-specific
+ # SMF svcs.
+ #
+ nawk -v base=$MAN_SRCDIR -v dest=$MAN_DESTDIR/$brand '{
+ # Ignore comments and empty lines.
+ if (substr($1, 1, 1) == "#" || length($1) == 0)
+ next
+
+ # entry format is: name status
+ proc_file($1, $2);
+ }
+
+ #
+ # Copy the manifest from the global zone to the brand-specific
+ # manifest area. At the same time, update any manifests whose
+ # status needs to be changed, based on what our configuration
+ # file indicates.
+ #
+ function proc_file(fname, status)
+ {
+ f = base "/" fname
+ of = dest "/" fname
+
+ while (getline <f > 0) {
+ # Fix up the console svc to work with zones.
+ if (fname == "system/console-login.xml")
+ sub("wscons", "console")
+
+ if (($1 == "<instance" &&
+ $2 == "name=\047default\047") ||
+ $1 == "<create_default_instance") {
+ if (status == "enabled")
+ n=sub("\047false\047", "\047true\047")
+ else
+ n=sub("\047true\047", "\047false\047")
+
+ if (n > 0)
+ printf("update svc state: %s %s\n",
+ fname, $0)
+ }
+
+ print $0 >of
+ }
+ close(f)
+ close(of)
+ }' /usr/lib/brand/$brand/manifests
+}
+
+#
+# If we're running off of a live-image, setup a zone-specific collection of
+# manifest files which are mounted in a zone's /lib/svc/manifest directory.
+#
+# Regenerate the manifest data each time this service starts, so that it's
+# always in sync with the running platform (and any fixes included there).
+#
+setup_manifests()
+{
+ echo "Initializing manifest dir."
+
+ rm -rf $MAN_DESTDIR
+ mkdir -m755 -p $MAN_DESTDIR
+
+ for i in /usr/lib/brand/*
+ do
+ brand=`basename $i`
+ [[ ! -f /usr/lib/brand/$brand/manifests ]] && continue
+ # joyent-minimal uses /zones/manifests/joyent too
+ [[ "$brand" == "joyent-minimal" ]] && continue
+ cp_brand_manifests $brand
+ done
+}
+
#
# Return a list of running, non-global zones for which a shutdown via
# "/sbin/init 0" may work (typically only Solaris zones.)
@@ -32,7 +151,7 @@
shutdown_zones()
{
zoneadm list -p | nawk -F: '{
- if (($5 != "lx") && ($2 != "global")) {
+ if ($2 != "global") {
print $2
}
}'
@@ -51,6 +170,16 @@ PATH=/usr/sbin:/usr/bin; export PATH
case "$1" in
'start')
+ #
+ # Generate the manifest, even if no zones, since zones could be
+ # provisioned later.
+ #
+ zfs list -H -o name $ZPOOL >/dev/null 2>&1
+ [ $? -eq 0 ] && setup_manifests
+
+ # Create directory for zone sockets
+ mkdir -m755 -p /var/zonecontrol
+
egrep -vs '^#|^global:' /etc/zones/index || exit 0 # no local zones
#
@@ -68,6 +197,14 @@ case "$1" in
[ -z "$ZONES" ] && echo "Booting zones:\c"
ZONES=yes
echo " $zone\c"
+
+ #
+ # Make sure a site dir exists, it wasn't initially
+ # being created.
+ #
+ zonepath=`zonecfg -z $zone info zonepath | cut -d: -f2`
+ [ ! -d $zonepath/site ] && mkdir -m755 $zonepath/site
+
#
# zoneadmd puts itself into its own contract so
# this service will lose sight of it. We don't
@@ -110,7 +247,7 @@ case "$1" in
for zone in $zonelist; do
echo " $zone\c"
- zoneadm -z $zone shutdown &
+ zlogin -S $zone /sbin/init 0 < /dev/null >&0 2>&0 &
SHUTDOWN=1
done