Last active
February 4, 2023 01:53
-
-
Save reiktar/8272320674e773342b6e75747cce5b79 to your computer and use it in GitHub Desktop.
Install's bashrc.d (or other rc.d's)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env sh | |
sub_install () { | |
install_name=$1 | |
install_to=$2 | |
install_source=${3%/} | |
[ -d $install_source ] || mkdir -p $install_source; chmod 700 $install_source; | |
[ ! -w $install_to ] && touch $install_to | |
if ! grep -Fxq "# $install_name" "$install_to"; then | |
( | |
printf '\n# %s\n' $install_name | |
printf "for f in \$(printf '%s' %s/* | sort -V ); do [ -r \$f ] && . \$f;done\n" \ | |
'%s\n' "$install_source" | |
) >>$install_to | |
fi | |
} | |
sub_test () { | |
testrun=/tmp/testrun | |
sub_install Test $testrun ${testrun}.d/ | |
i=0 | |
while [ $i -ne 5 ]; do | |
i=$(($i+1)) | |
echo "echo Loading $i" > ${testrun}.d/$i.sh | |
done | |
(bash $testrun) | |
sub_install Test $testrun ${testrun}.d/ | |
(bash $testrun) | |
rm -rf $testrun ${testrun}.d | |
} | |
#sub_test | |
sub_install bashrc.d ~/.bashrc ~/.bashrc.d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment