From b81b03428769569c7420573c75e3320913078211 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 20 Mar 2024 22:05:51 +0100 Subject: [PATCH] Add an abstract script for adding profile settings --- scripts/Common/Config/bash/profile.sh | 26 +++++-------------------- scripts/Common/Scripts/profile-base.sh | 27 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 21 deletions(-) create mode 100755 scripts/Common/Scripts/profile-base.sh diff --git a/scripts/Common/Config/bash/profile.sh b/scripts/Common/Config/bash/profile.sh index 037e54e1..d0812dd4 100755 --- a/scripts/Common/Config/bash/profile.sh +++ b/scripts/Common/Config/bash/profile.sh @@ -1,27 +1,11 @@ #!/bin/bash +pushd "${BASH_SOURCE%/*}" > /dev/null; +. "../../Scripts/profile-base.sh"; function addBashProfile() { name="$1"; title="$2"; - - if [ -t 1 ] - then - statement="$(cat)"; - else - statement="${@:3}"; - fi; - - contextRoot="$(mktemp -d)"; - pushd "$contextRoot" > /dev/null; - - { - echo '#!/bin/bash'; - echo "# $title"; - echo "$statement"; - } > "profile.sh"; - - sudo install -Dm755 profile.sh /etc/bash/conf.d/$name.sh - - popd > /dev/null; - rm -rf "$contextRoot"; + addProfileStatement "$name" "$title" "/bin/bash" "/etc/bash/conf.d" "${@:3}"; } + +popd > /dev/null; diff --git a/scripts/Common/Scripts/profile-base.sh b/scripts/Common/Scripts/profile-base.sh new file mode 100755 index 00000000..80c500a4 --- /dev/null +++ b/scripts/Common/Scripts/profile-base.sh @@ -0,0 +1,27 @@ +function addProfileStatement() { + name="$1"; + title="$2"; + shellBin="$3"; + profileRoot="$4"; + + if [ -t 1 ] + then + statement="$(cat)"; + else + statement="${@:5}"; + fi; + + contextRoot="$(mktemp -d)"; + pushd "$contextRoot" > /dev/null; + + { + echo '#!'"$shellBin"; + echo "# $title"; + echo "$statement"; + } > "profile.sh"; + + sudo install -Dm755 profile.sh "$profileRoot/$name.sh" + + popd > /dev/null; + rm -rf "$contextRoot"; +}