From 16decdf8051604b9bfff921c924fd3e66eaf84c9 Mon Sep 17 00:00:00 2001 From: Youngjin Han Date: Sat, 16 May 2020 00:05:44 +0900 Subject: [PATCH] Learning Circle : cidst #6 :Initial commit --- youngjin.han/dot-cdist/manifest/init | 6 ++- .../dot-cdist/type/__all_in_one/manifest | 44 +++++++++++++++++++ .../type/__all_in_one/parameter/boolean | 1 + .../__all_in_one/parameter/optional_multiple | 1 + .../dot-cdist/type/__my_firewall/manifest | 11 +++++ .../dot-cdist/type/__my_firewall/manifest~ | 44 +++++++++++++++++++ .../type/__my_firewall/parameter/required | 1 + .../dot-cdist/type/__my_firewall/singleton | 0 youngjin.han/learning-node02-2020.org | 3 +- 9 files changed, 108 insertions(+), 3 deletions(-) create mode 100755 youngjin.han/dot-cdist/type/__all_in_one/manifest create mode 100644 youngjin.han/dot-cdist/type/__all_in_one/parameter/boolean create mode 100644 youngjin.han/dot-cdist/type/__all_in_one/parameter/optional_multiple create mode 100755 youngjin.han/dot-cdist/type/__my_firewall/manifest create mode 100755 youngjin.han/dot-cdist/type/__my_firewall/manifest~ create mode 100644 youngjin.han/dot-cdist/type/__my_firewall/parameter/required create mode 100644 youngjin.han/dot-cdist/type/__my_firewall/singleton diff --git a/youngjin.han/dot-cdist/manifest/init b/youngjin.han/dot-cdist/manifest/init index 48e4995..1de48dc 100644 --- a/youngjin.han/dot-cdist/manifest/init +++ b/youngjin.han/dot-cdist/manifest/init @@ -2,12 +2,14 @@ __file /etc/cdist-configured case "$__target_host" in localhost) - __motd - __timezone Asia/Seoul +# __motd +# __timezone Asia/Seoul # __my_computer # __colourful_file --colour yellow --colour blue --colour red --colour green # __my_dotfiles # __my_nginx_site $__target_host +# __all_in_one $__target_host --with-x --extra-packages tree --extra-packages htop + __my_firewall --file /etc/my-nftables ;; jafo.laptop) __motd diff --git a/youngjin.han/dot-cdist/type/__all_in_one/manifest b/youngjin.han/dot-cdist/type/__all_in_one/manifest new file mode 100755 index 0000000..ee5f9a7 --- /dev/null +++ b/youngjin.han/dot-cdist/type/__all_in_one/manifest @@ -0,0 +1,44 @@ +#!/bin/sh -e + +os="$(cat "$__global/explorer/os")" +default_package_name="socat sipalc sudo" + +if [ -f "$__object/parameter/with-x" ]; then + with_x="$(cat "$__object/parameter/with-x")" +else + with_x="$__object_id" +fi + +case "$os" in + alpine) + name_netcat="netcat-openbsd" + name_wireshark="tshark" + ;; + debian) + name_netcat="netcat" + name_wireshark="tshark" + ;; + fedora) + name_netcat="nmap-ncat" + name_wireshark="wireshark-cli" + ;; + *) + echo "Don't know how to manage packages on: $os" >&2 + exit 1 + : + ;; +esac + +all_package_name="$default_package_name $name_netcat $name_wireshark" + +__package_update_index + +for package in $all_package_name; + do require="__apt_update_index" __package $package --state=present +done + +if [ -f "$__object/parameter/extra-packages" ]; then + for package in $(cat "$__object/parameter/extra-packages"); do + require="__apt_update_index" __package $package --state=present + done +fi diff --git a/youngjin.han/dot-cdist/type/__all_in_one/parameter/boolean b/youngjin.han/dot-cdist/type/__all_in_one/parameter/boolean new file mode 100644 index 0000000..836c0dd --- /dev/null +++ b/youngjin.han/dot-cdist/type/__all_in_one/parameter/boolean @@ -0,0 +1 @@ +with-x diff --git a/youngjin.han/dot-cdist/type/__all_in_one/parameter/optional_multiple b/youngjin.han/dot-cdist/type/__all_in_one/parameter/optional_multiple new file mode 100644 index 0000000..2cfc07b --- /dev/null +++ b/youngjin.han/dot-cdist/type/__all_in_one/parameter/optional_multiple @@ -0,0 +1 @@ +extra-packages diff --git a/youngjin.han/dot-cdist/type/__my_firewall/manifest b/youngjin.han/dot-cdist/type/__my_firewall/manifest new file mode 100755 index 0000000..bc33c7a --- /dev/null +++ b/youngjin.han/dot-cdist/type/__my_firewall/manifest @@ -0,0 +1,11 @@ +#!/bin/sh -e + +if [ -x nft ]; then + echo "nft is founded" +else + echo "nft is not founded" + exit 1 +fi + +__file /etc/my_nftables \ + --mode 0644 diff --git a/youngjin.han/dot-cdist/type/__my_firewall/manifest~ b/youngjin.han/dot-cdist/type/__my_firewall/manifest~ new file mode 100755 index 0000000..ee5f9a7 --- /dev/null +++ b/youngjin.han/dot-cdist/type/__my_firewall/manifest~ @@ -0,0 +1,44 @@ +#!/bin/sh -e + +os="$(cat "$__global/explorer/os")" +default_package_name="socat sipalc sudo" + +if [ -f "$__object/parameter/with-x" ]; then + with_x="$(cat "$__object/parameter/with-x")" +else + with_x="$__object_id" +fi + +case "$os" in + alpine) + name_netcat="netcat-openbsd" + name_wireshark="tshark" + ;; + debian) + name_netcat="netcat" + name_wireshark="tshark" + ;; + fedora) + name_netcat="nmap-ncat" + name_wireshark="wireshark-cli" + ;; + *) + echo "Don't know how to manage packages on: $os" >&2 + exit 1 + : + ;; +esac + +all_package_name="$default_package_name $name_netcat $name_wireshark" + +__package_update_index + +for package in $all_package_name; + do require="__apt_update_index" __package $package --state=present +done + +if [ -f "$__object/parameter/extra-packages" ]; then + for package in $(cat "$__object/parameter/extra-packages"); do + require="__apt_update_index" __package $package --state=present + done +fi diff --git a/youngjin.han/dot-cdist/type/__my_firewall/parameter/required b/youngjin.han/dot-cdist/type/__my_firewall/parameter/required new file mode 100644 index 0000000..f73f309 --- /dev/null +++ b/youngjin.han/dot-cdist/type/__my_firewall/parameter/required @@ -0,0 +1 @@ +file diff --git a/youngjin.han/dot-cdist/type/__my_firewall/singleton b/youngjin.han/dot-cdist/type/__my_firewall/singleton new file mode 100644 index 0000000..e69de29 diff --git a/youngjin.han/learning-node02-2020.org b/youngjin.han/learning-node02-2020.org index 2034589..52a96fb 100644 --- a/youngjin.han/learning-node02-2020.org +++ b/youngjin.han/learning-node02-2020.org @@ -3,7 +3,8 @@ **** Lecture content ***** Objective - Apply learnings from the previous cdist sessions -***** Steps 1: *__all_in_one* (1.25h) +***** DONE Steps 1: *__all_in_one* (1.25h) + CLOSED: [2020-05-15 금 23:16] - Create a new type named *__all_in_one* - Decide yourself whether it is a singleton or not - Reason why in your cdist.org file