summaryrefslogtreecommitdiffstats
path: root/modules.d/95ssh-client/module-setup.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:54:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:54:25 +0000
commit9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a (patch)
tree2efb72864cc69e174c9c5ee33efb88a5f1553b48 /modules.d/95ssh-client/module-setup.sh
parentInitial commit. (diff)
downloaddracut-9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a.tar.xz
dracut-9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a.zip
Adding upstream version 060+5.upstream/060+5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'modules.d/95ssh-client/module-setup.sh')
-rwxr-xr-xmodules.d/95ssh-client/module-setup.sh80
1 files changed, 80 insertions, 0 deletions
diff --git a/modules.d/95ssh-client/module-setup.sh b/modules.d/95ssh-client/module-setup.sh
new file mode 100755
index 0000000..75fc94f
--- /dev/null
+++ b/modules.d/95ssh-client/module-setup.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+
+# fixme: assume user is root
+
+# called by dracut
+check() {
+ [[ $mount_needs ]] && return 1
+
+ # If our prerequisites are not met, fail.
+ require_binaries ssh scp || return 1
+
+ if [[ $sshkey ]]; then
+ [[ ! -f $dracutsysrootdir$sshkey ]] && {
+ derror "ssh key: $sshkey is not found!"
+ return 1
+ }
+ fi
+
+ return 255
+}
+
+# called by dracut
+depends() {
+ # We depend on network modules being loaded
+ echo network
+}
+
+inst_sshenv() {
+ if [[ -d $dracutsysrootdir/root/.ssh ]]; then
+ inst_dir /root/.ssh
+ chmod 700 "${initdir}"/root/.ssh
+ fi
+
+ # Copy over ssh key and knowhosts if needed
+ [[ $sshkey ]] && {
+ inst_simple "$sshkey"
+ [[ -f $dracutsysrootdir/root/.ssh/known_hosts ]] && inst_simple /root/.ssh/known_hosts
+ [[ -f $dracutsysrootdir/etc/ssh/ssh_known_hosts ]] && inst_simple /etc/ssh/ssh_known_hosts
+ }
+
+ # Copy over root and system-wide ssh configs.
+ [[ -f $dracutsysrootdir/root/.ssh/config ]] && inst_simple /root/.ssh/config
+ if [[ -f $dracutsysrootdir/etc/ssh/ssh_config ]]; then
+ inst_simple /etc/ssh/ssh_config
+ sed -i -e 's/\(^[[:space:]]*\)ProxyCommand/\1# ProxyCommand/' "${initdir}"/etc/ssh/ssh_config
+ while read -r key val || [ -n "$key" ]; do
+ if [[ $key == "GlobalKnownHostsFile" ]]; then
+ inst_simple "$val"
+ # Copy customized UserKnowHostsFile
+ elif [[ $key == "UserKnownHostsFile" ]]; then
+ # Make sure that ~/foo will be copied as /root/foo in kdump's initramfs
+ # shellcheck disable=SC2088
+ if str_starts "$val" "~/"; then
+ val="/root/${val#"~/"}"
+ fi
+ inst_simple "$val"
+ fi
+ done < "$dracutsysrootdir"/etc/ssh/ssh_config
+ fi
+
+ return 0
+}
+
+# called by dracut
+install() {
+ local _nsslibs
+
+ inst_multiple ssh scp
+ inst_sshenv
+
+ _nsslibs=$(
+ cat "$dracutsysrootdir"/{,usr/}etc/nsswitch.conf 2> /dev/null \
+ | sed -e 's/#.*//; s/^[^:]*://; s/\[[^]]*\]//' \
+ | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|'
+ )
+ _nsslibs=${_nsslibs#|}
+ _nsslibs=${_nsslibs%|}
+
+ inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
+}