2013-08-15 12:04:40 -04:00
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
2017-05-25 16:07:35 +02:00
# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems #
2013-08-15 12:04:40 -04:00
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require " erb "
2013-08-15 13:58:43 -04:00
2013-08-15 12:04:40 -04:00
CMDS = {
:MISC = > %w( dd mkfs sync ) ,
2016-11-09 19:21:48 -06:00
:NET = > %w( brctl ebtables iptables ip6tables ip ipset ) ,
2016-05-10 15:03:09 +02:00
:LVM = > %w( lvcreate lvremove lvs vgdisplay lvchange lvscan ) ,
2013-08-15 12:04:40 -04:00
:ISCSI = > %w( iscsiadm tgt-admin tgtadm ) ,
:OVS = > %w( ovs-ofctl ovs-vsctl ) ,
2015-11-02 15:47:42 +01:00
:XEN = > %w( xentop xl xm ) ,
:CEPH = > %w( rbd )
2013-08-15 12:04:40 -04:00
}
2015-11-02 15:47:42 +01:00
KEYS = CMDS . keys
2013-08-15 12:04:40 -04:00
abs_cmds = { }
not_found_cmds = [ ]
2013-08-15 13:58:43 -04:00
KEYS . each do | label |
cmds = CMDS [ label ]
2013-08-15 12:04:40 -04:00
2013-08-15 13:58:43 -04:00
_abs_cmds = [ ]
2013-08-15 12:04:40 -04:00
cmds . each do | cmd |
abs_cmd = ` which #{ cmd } 2>/dev/null `
if ! abs_cmd . empty?
_abs_cmds << abs_cmd . strip
else
not_found_cmds << cmd
end
end
abs_cmds [ " ONE_ #{ label } " ] = _abs_cmds
end
abs_cmds . reject! { | k , v | v . empty? }
puts ERB . new ( DATA . read , nil , " <> " ) . result ( binding )
if ! not_found_cmds . empty?
STDERR . puts " \n --- \n \n Not found: "
not_found_cmds . each { | cmd | STDERR . puts ( " - #{ cmd } " ) }
end
__END__
Defaults ! requiretty
Defaults secure_path = / sbin: / bin : / usr /s bin : / usr / bin
2013-08-15 15:05:00 -04:00
< % KEYS.each do | k | ; l = " ONE_ #{ k } " ; v = abs_cmds [ l ] % >
2013-08-15 13:58:43 -04:00
< % if ! v . nil? % >
2013-08-15 15:05:00 -04:00
Cmnd_Alias < %= l %> = < %= v . join ( " , " ) % >
2013-08-15 12:04:40 -04:00
< % end % >
2013-08-15 13:58:43 -04:00
< % end % >
2013-08-15 12:04:40 -04:00
2013-08-15 15:05:00 -04:00
oneadmin ALL = ( ALL ) NOPASSWD : < %= KEYS . select { | k | ! abs_cmds [ " ONE_ #{ k } " ] . nil? } . collect { | k | " ONE_ #{ k } " } . join ( " , " ) % >