Skip to content

Commit

Permalink
Ignore name in gen_params.sh and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-harvey-z3q committed Sep 26, 2023
1 parent 0b7853f commit fdd8ebf
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 165 deletions.
77 changes: 51 additions & 26 deletions gen_params.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#!/usr/bin/env bash

if [ "$(uname -s)" == "Darwin" ] ; then
if [ ! -x /usr/local/bin/gsed ] ; then
echo "On Mac OS X you need to install gnu-sed:"
echo "$ brew install gnu-sed"
exit 1
fi

shopt -s expand_aliases
alias sed='/usr/local/bin/gsed'
fi

usage() {
echo "Usage: bash $0 > manifests/init.pp"
exit 1
}

[ "$1" == -h ] && usage

header() {
Expand Down Expand Up @@ -51,39 +63,52 @@ firewall_lib() {
cat "$path_to_firewall"'/lib/puppet/provider/firewall/firewall.rb'
}

sort_cols() {
sort | column -t
}
transform() {
local mode="$1"
local indent

first_transform() {
firewall_lib \
| awk '
/\$resource_map = {/ { flag=1; next }
/^ }/ { flag=0 }
flag && /:/ { split($0, arr, ":"); gsub(/^[ \t]+|[ \t]+$/, "", arr[1]); print "$" arr[1] " = undef," }
' | sort_cols | gsed '
s/^/ /
s/ = /=/
'
}
case "$mode" in
1) indent=" "
;;
2) indent=" "
;;
esac

second_transform() {
firewall_lib \
| awk '
/\$resource_map = {/ { flag=1; next }
/^ }/ { flag=0 }
flag && /:/ { split($0, arr, ":"); gsub(/^[ \t]+|[ \t]+$/, "", arr[1]); print arr[1] " => $" arr[1] "," }
' | sort_cols | gsed '
s/^/ /
s/ => /=>/
'
firewall_lib |
awk -v mode="$mode" '
/\$resource_map = {/ {
flag=1
next
}
/^ }/ {
flag=0
}
flag && /:/ && !/^[[:space:]]*name:/ {
split($0, arr, ":")
gsub(/^[ \t]+|[ \t]+$/, "", arr[1])
if (mode == "1")
print "$" arr[1] " = undef,"
else
print arr[1] " => $" arr[1] ","
}
' |
sort |
column -t |
sed '
s/^/'"$indent"'/
s/ = /=/
'
}

main() {
header
first_transform
transform "1"
middle
second_transform
transform "2"
footer
}

Expand Down
278 changes: 139 additions & 139 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -157,145 +157,145 @@
$name => {
ensure => $ensure,
protocol => $protocol,
burst => $burst,
bytecode => $bytecode,
cgroup => $cgroup,
chain => $chain,
checksum_fill => $checksum_fill,
clamp_mss_to_pmtu => $clamp_mss_to_pmtu,
clusterip_clustermac => $clusterip_clustermac,
clusterip_hash_init => $clusterip_hash_init,
clusterip_hashmode => $clusterip_hashmode,
clusterip_local_node => $clusterip_local_node,
clusterip_new => $clusterip_new,
clusterip_total_nodes => $clusterip_total_nodes,
condition => $condition,
connlimit_above => $connlimit_above,
connlimit_mask => $connlimit_mask,
connlimit_upto => $connlimit_upto,
connmark => $connmark,
ctdir => $ctdir,
ctexpire => $ctexpire,
ctorigdst => $ctorigdst,
ctorigdstport => $ctorigdstport,
ctorigsrc => $ctorigsrc,
ctorigsrcport => $ctorigsrcport,
ctproto => $ctproto,
ctrepldst => $ctrepldst,
ctrepldstport => $ctrepldstport,
ctreplsrc => $ctreplsrc,
ctreplsrcport => $ctreplsrcport,
ctstate => $ctstate,
ctstatus => $ctstatus,
date_start => $date_start,
date_stop => $date_stop,
destination => $destination,
dport => $dport,
dst_cc => $dst_cc,
dst_range => $dst_range,
dst_type => $dst_type,
gateway => $gateway,
gid => $gid,
goto => $goto,
hashlimit_above => $hashlimit_above,
hashlimit_burst => $hashlimit_burst,
hashlimit_dstmask => $hashlimit_dstmask,
hashlimit_htable_expire => $hashlimit_htable_expire,
hashlimit_htable_gcinterval => $hashlimit_htable_gcinterval,
hashlimit_htable_max => $hashlimit_htable_max,
hashlimit_htable_size => $hashlimit_htable_size,
hashlimit_mode => $hashlimit_mode,
hashlimit_name => $hashlimit_name,
hashlimit_srcmask => $hashlimit_srcmask,
hashlimit_upto => $hashlimit_upto,
helper => $helper,
hop_limit => $hop_limit,
icmp => $icmp,
iniface => $iniface,
ipsec_dir => $ipsec_dir,
ipsec_policy => $ipsec_policy,
ipset => $ipset,
ipvs => $ipvs,
isfirstfrag => $isfirstfrag,
isfragment => $isfragment,
ishasmorefrags => $ishasmorefrags,
islastfrag => $islastfrag,
jump => $jump,
kernel_timezone => $kernel_timezone,
length => $length,
limit => $limit,
log_ip_options => $log_ip_options,
log_level => $log_level,
log_prefix => $log_prefix,
log_tcp_options => $log_tcp_options,
log_tcp_sequence => $log_tcp_sequence,
log_uid => $log_uid,
mac_source => $mac_source,
mask => $mask,
match_mark => $match_mark,
month_days => $month_days,
mss => $mss,
nflog_group => $nflog_group,
nflog_prefix => $nflog_prefix,
nflog_range => $nflog_range,
nflog_size => $nflog_size,
nflog_threshold => $nflog_threshold,
notrack => $notrack,
outiface => $outiface,
physdev_in => $physdev_in,
physdev_is_bridged => $physdev_is_bridged,
physdev_is_in => $physdev_is_in,
physdev_is_out => $physdev_is_out,
physdev_out => $physdev_out,
pkttype => $pkttype,
proto => $proto,
queue_bypass => $queue_bypass,
queue_num => $queue_num,
random => $random,
random_fully => $random_fully,
rdest => $rdest,
reap => $reap,
recent => $recent,
reject => $reject,
rhitcount => $rhitcount,
rname => $rname,
rpfilter => $rpfilter,
rseconds => $rseconds,
rsource => $rsource,
rttl => $rttl,
set_dscp => $set_dscp,
set_dscp_class => $set_dscp_class,
set_mark => $set_mark,
set_mss => $set_mss,
socket => $socket,
source => $source,
sport => $sport,
src_cc => $src_cc,
src_range => $src_range,
src_type => $src_type,
stat_every => $stat_every,
stat_mode => $stat_mode,
stat_packet => $stat_packet,
stat_probability => $stat_probability,
state => $state,
string => $string,
string_algo => $string_algo,
string_from => $string_from,
string_hex => $string_hex,
string_to => $string_to,
tcp_flags => $tcp_flags,
tcp_option => $tcp_option,
time_contiguous => $time_contiguous,
time_start => $time_start,
time_stop => $time_stop,
to => $to,
todest => $todest,
toports => $toports,
tosource => $tosource,
u32 => $u32,
uid => $uid,
week_days => $week_days,
zone => $zone,
burst => $burst,
bytecode => $bytecode,
cgroup => $cgroup,
chain => $chain,
checksum_fill => $checksum_fill,
clamp_mss_to_pmtu => $clamp_mss_to_pmtu,
clusterip_clustermac => $clusterip_clustermac,
clusterip_hash_init => $clusterip_hash_init,
clusterip_hashmode => $clusterip_hashmode,
clusterip_local_node => $clusterip_local_node,
clusterip_new => $clusterip_new,
clusterip_total_nodes => $clusterip_total_nodes,
condition => $condition,
connlimit_above => $connlimit_above,
connlimit_mask => $connlimit_mask,
connlimit_upto => $connlimit_upto,
connmark => $connmark,
ctdir => $ctdir,
ctexpire => $ctexpire,
ctorigdst => $ctorigdst,
ctorigdstport => $ctorigdstport,
ctorigsrc => $ctorigsrc,
ctorigsrcport => $ctorigsrcport,
ctproto => $ctproto,
ctrepldst => $ctrepldst,
ctrepldstport => $ctrepldstport,
ctreplsrc => $ctreplsrc,
ctreplsrcport => $ctreplsrcport,
ctstate => $ctstate,
ctstatus => $ctstatus,
date_start => $date_start,
date_stop => $date_stop,
destination => $destination,
dport => $dport,
dst_cc => $dst_cc,
dst_range => $dst_range,
dst_type => $dst_type,
gateway => $gateway,
gid => $gid,
goto => $goto,
hashlimit_above => $hashlimit_above,
hashlimit_burst => $hashlimit_burst,
hashlimit_dstmask => $hashlimit_dstmask,
hashlimit_htable_expire => $hashlimit_htable_expire,
hashlimit_htable_gcinterval => $hashlimit_htable_gcinterval,
hashlimit_htable_max => $hashlimit_htable_max,
hashlimit_htable_size => $hashlimit_htable_size,
hashlimit_mode => $hashlimit_mode,
hashlimit_name => $hashlimit_name,
hashlimit_srcmask => $hashlimit_srcmask,
hashlimit_upto => $hashlimit_upto,
helper => $helper,
hop_limit => $hop_limit,
icmp => $icmp,
iniface => $iniface,
ipsec_dir => $ipsec_dir,
ipsec_policy => $ipsec_policy,
ipset => $ipset,
ipvs => $ipvs,
isfirstfrag => $isfirstfrag,
isfragment => $isfragment,
ishasmorefrags => $ishasmorefrags,
islastfrag => $islastfrag,
jump => $jump,
kernel_timezone => $kernel_timezone,
length => $length,
limit => $limit,
log_ip_options => $log_ip_options,
log_level => $log_level,
log_prefix => $log_prefix,
log_tcp_options => $log_tcp_options,
log_tcp_sequence => $log_tcp_sequence,
log_uid => $log_uid,
mac_source => $mac_source,
mask => $mask,
match_mark => $match_mark,
month_days => $month_days,
mss => $mss,
nflog_group => $nflog_group,
nflog_prefix => $nflog_prefix,
nflog_range => $nflog_range,
nflog_size => $nflog_size,
nflog_threshold => $nflog_threshold,
notrack => $notrack,
outiface => $outiface,
physdev_in => $physdev_in,
physdev_is_bridged => $physdev_is_bridged,
physdev_is_in => $physdev_is_in,
physdev_is_out => $physdev_is_out,
physdev_out => $physdev_out,
pkttype => $pkttype,
proto => $proto,
queue_bypass => $queue_bypass,
queue_num => $queue_num,
random => $random,
random_fully => $random_fully,
rdest => $rdest,
reap => $reap,
recent => $recent,
reject => $reject,
rhitcount => $rhitcount,
rname => $rname,
rpfilter => $rpfilter,
rseconds => $rseconds,
rsource => $rsource,
rttl => $rttl,
set_dscp => $set_dscp,
set_dscp_class => $set_dscp_class,
set_mark => $set_mark,
set_mss => $set_mss,
socket => $socket,
source => $source,
sport => $sport,
src_cc => $src_cc,
src_range => $src_range,
src_type => $src_type,
stat_every => $stat_every,
stat_mode => $stat_mode,
stat_packet => $stat_packet,
stat_probability => $stat_probability,
state => $state,
string => $string,
string_algo => $string_algo,
string_from => $string_from,
string_hex => $string_hex,
string_to => $string_to,
tcp_flags => $tcp_flags,
tcp_option => $tcp_option,
time_contiguous => $time_contiguous,
time_start => $time_start,
time_stop => $time_stop,
to => $to,
todest => $todest,
toports => $toports,
tosource => $tosource,
u32 => $u32,
uid => $uid,
week_days => $week_days,
zone => $zone,
}
}
)
Expand Down

0 comments on commit fdd8ebf

Please sign in to comment.