From ad51c30997402b922e5ae76dc55e5f1e89593ad7 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 14 Nov 2018 18:48:26 +0100
Subject: [PATCH] Improve new setup.

---
 all_new_2018/apt-mark/all                     |  8 +++++
 all_new_2018/apt-mark/server                  |  4 +++
 all_new_2018/install_for_target.sh            | 15 ++++++++++
 .../limit_packages/required_nonrequireds      |  3 --
 .../purge_nonrequireds.sh                     | 16 ++++++----
 all_new_2018/symlink_etc.sh                   | 30 ++++++++-----------
 6 files changed, 51 insertions(+), 25 deletions(-)
 create mode 100644 all_new_2018/apt-mark/all
 create mode 100644 all_new_2018/apt-mark/server
 create mode 100755 all_new_2018/install_for_target.sh
 delete mode 100644 all_new_2018/limit_packages/required_nonrequireds
 rename all_new_2018/{limit_packages => }/purge_nonrequireds.sh (65%)

diff --git a/all_new_2018/apt-mark/all b/all_new_2018/apt-mark/all
new file mode 100644
index 0000000..f9caab8
--- /dev/null
+++ b/all_new_2018/apt-mark/all
@@ -0,0 +1,8 @@
+# connectivity
+ifupdown
+isc-dhcp-client
+# git
+ca-certificates
+git
+# to avoid constant warnings about no locale being found 
+locales
diff --git a/all_new_2018/apt-mark/server b/all_new_2018/apt-mark/server
new file mode 100644
index 0000000..3994b43
--- /dev/null
+++ b/all_new_2018/apt-mark/server
@@ -0,0 +1,4 @@
+# connectivity
+openssh-server
+# provides /etc/inputrc and understanding of ctrl+arrow key combos
+readline-common
diff --git a/all_new_2018/install_for_target.sh b/all_new_2018/install_for_target.sh
new file mode 100755
index 0000000..9d2e1a6
--- /dev/null
+++ b/all_new_2018/install_for_target.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# Walks through the package names in the argument-selected files of
+# apt-mark/ and ensures the respective packages are installed.
+set -e
+
+config_tree_prefix="${HOME}/config/all_new_2018/apt-mark/"
+
+for target in "$@"; do
+    path="${config_tree_prefix}${target}"
+    for line in $(cat "${path}"); do
+        if [ ! $(echo "${line}" | cut -c1) = "#" ]; then
+            apt-get -y install "${line}"
+        fi
+    done
+done
diff --git a/all_new_2018/limit_packages/required_nonrequireds b/all_new_2018/limit_packages/required_nonrequireds
deleted file mode 100644
index dca4024..0000000
--- a/all_new_2018/limit_packages/required_nonrequireds
+++ /dev/null
@@ -1,3 +0,0 @@
-ifupdown
-isc-dhcp-client
-openssh-server
diff --git a/all_new_2018/limit_packages/purge_nonrequireds.sh b/all_new_2018/purge_nonrequireds.sh
similarity index 65%
rename from all_new_2018/limit_packages/purge_nonrequireds.sh
rename to all_new_2018/purge_nonrequireds.sh
index 36b6f38..34692da 100755
--- a/all_new_2018/limit_packages/purge_nonrequireds.sh
+++ b/all_new_2018/purge_nonrequireds.sh
@@ -1,14 +1,20 @@
 #!/bin/sh
 # This script removes all Debian packages that are not of Priority
 # "required" or not depended on by packages of priority "required"
-# or not listed in the file ./required_nonrequireds.
-# If ./required_nonrequireds does not exist, will abort, as user
-# probably does not know what they are doing then.
-set -x
+# or not listed in the argument-selected files of apt-mark/.
 set -e
 
+config_tree_prefix="${HOME}/config/all_new_2018/apt-mark/"
+
 dpkg-query -Wf '${Package} ${Priority}\n' | grep ' required' | sed 's/ required//' > /tmp/list_white_unsorted
-cat 'required_nonrequireds' >> /tmp/list_white_unsorted
+for target in "$@"; do
+    path="${config_tree_prefix}${target}"
+    for line in $(cat "${path}"); do
+        if [ ! $(echo "${line}" | cut -c1) = "#" ]; then
+            echo "${line}" >> /tmp/list_white_unsorted
+        fi
+    done
+done
 sort /tmp/list_white_unsorted > /tmp/list_white
 dpkg-query -Wf '${Package}\n' > /tmp/list_all_packages
 sort /tmp/list_all_packages > /tmp/foo
diff --git a/all_new_2018/symlink_etc.sh b/all_new_2018/symlink_etc.sh
index edee563..dd78fdf 100755
--- a/all_new_2018/symlink_etc.sh
+++ b/all_new_2018/symlink_etc.sh
@@ -1,22 +1,18 @@
 #!/bin/sh
-# Symbolically link files to those under linkable_etc_files/$1/, e.g.
-# link /etc/foo/bar to linkable_etc_files/$1/etc/foo/bar. Create
-# directories as necessary.
+# Symbolically link files to those in argument-selected subdirectories
+# of linkable_etc_files//, e.g. link /etc/foo/bar to
+# linkable_etc_files/$1/etc/foo/bar and so on. Create directories as
+# necessary.
 # CAUTION: This removes original files at the affected paths.
 set -e
 
-target="$1"
-if [ ! "${target}" = "all" ] && [ ! "${target}" = "server" ]; then
-    echo "Need proper target."
-    false
-fi
-
-config_tree_prefix="${HOME}/config/all_new_2018/linkable_etc_files/"
-cd "${config_tree_prefix}""${target}"
-for path in $(find . -type f); do
-    linking=$(echo "${path}" | cut -c2-)
-    linked=$(realpath "${path}")
-    dir=$(dirname "${linking}")
-    mkdir -p "${dir}"
-    ln -fs "${linked}" "${linking}"
+for target in "$@"; do
+    cd "${config_tree_prefix}${target}"
+    for path in $(find . -type f); do
+        linking=$(echo "${path}" | cut -c2-)
+        linked=$(realpath "${path}")
+        dir=$(dirname "${linking}")
+        mkdir -p "${dir}"
+        ln -fs "${linked}" "${linking}"
+    done
 done
-- 
2.30.2