Skip to content

Instantly share code, notes, and snippets.

@reiktar
Last active February 4, 2023 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reiktar/8272320674e773342b6e75747cce5b79 to your computer and use it in GitHub Desktop.
Save reiktar/8272320674e773342b6e75747cce5b79 to your computer and use it in GitHub Desktop.
Install's bashrc.d (or other rc.d's)
#/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