Add an abstract script for adding profile settings
This commit is contained in:
parent
e22ca0ec73
commit
b81b034287
2 changed files with 32 additions and 21 deletions
|
@ -1,27 +1,11 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
pushd "${BASH_SOURCE%/*}" > /dev/null;
|
||||||
|
. "../../Scripts/profile-base.sh";
|
||||||
|
|
||||||
function addBashProfile() {
|
function addBashProfile() {
|
||||||
name="$1";
|
name="$1";
|
||||||
title="$2";
|
title="$2";
|
||||||
|
addProfileStatement "$name" "$title" "/bin/bash" "/etc/bash/conf.d" "${@:3}";
|
||||||
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;
|
popd > /dev/null;
|
||||||
rm -rf "$contextRoot";
|
|
||||||
}
|
|
||||||
|
|
27
scripts/Common/Scripts/profile-base.sh
Executable file
27
scripts/Common/Scripts/profile-base.sh
Executable file
|
@ -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";
|
||||||
|
}
|
Loading…
Reference in a new issue