1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-13 20:29:02 -08:00
rc/regenerate

82 lines
2.8 KiB
Text
Raw Normal View History

2021-08-01 00:35:56 -07:00
#!/usr/bin/env dash
NAME="$0"
note() {
local IFS=" "
printf "%s\n" "$*"
}
warn() {
note "$@" >&2
}
die() {
warn "$NAME:" "$@"
#cleanup
exit 1
}
cleanup() {
:
#[ ! -e temp.tar.gz ] || rm temp.tar.gz || die failed
#[ ! -d temp ] || rm -r temp || die failed
}
backup() {
2021-08-01 01:02:28 -07:00
if [ -e "${1}~" ]; then
2021-08-01 00:35:56 -07:00
backup "${1}~" || die 'failed to backup file' "$1"
fi
mv "$1" "${1}~" || die 'failed to backup file' "$1"
}
rc="$(readlink -f "$(dirname "$NAME")" )"
[ -d "$rc" ] || die 'failed to determine rc directory'
cd "$rc" || die 'failed to change directory'
if ! which git >/dev/null 2>&1; then
[ "$1" != commit ] || die 'git not found'
# git unavailable. just document everything as it is.
2021-08-01 00:35:56 -07:00
dash ./sh/document || die 'failed to generate documentation'
printf '%s\n' '' '## compatibility' '' >> README.md~ || die 'failed to make room for compatibility table'
dash ./tableize >> README.md~ || die 'failed to generate compatibility table'
2021-08-01 00:35:56 -07:00
elif [ "$1" = local ]; then
# user requested to ignore git.
dash ./sh/document || die 'failed to generate documentation'
printf '%s\n' '' '## compatibility' '' >> README.md~ || die 'failed to make room for compatibility table'
dash ./tableize >> README.md~ || die 'failed to generate compatibility table'
2021-08-01 00:35:56 -07:00
else
# git available. document the most recent commit, without pending changes.
[ ! -e temp.tar.gz ] || backup temp.tar.gz || die 'failed to backup existing temp archive'
git archive --prefix=temp/ HEAD -o temp.tar.gz || die 'failed to create git archive'
[ ! -e temp ] || backup temp || die 'failed to backup existing temp directory'
tar -zxf temp.tar.gz || die 'failed to unarchive temp archive'
#( cd temp; HOME="$rc/temp" dash ./install )
ln temp/home/zshrc temp/.zshrc || die 'failed to copy files'
ln temp/home/shrc temp/.shrc || die 'failed to copy files'
2021-08-01 00:35:56 -07:00
ln temp/home/bashrc temp/.bashrc || die 'failed to copy files'
# use new documentation-generating scripts on old shell scripts.
2021-08-01 00:35:56 -07:00
cp -p README.md temp/README.md || die 'failed to copy existing readme'
dash ./sh/document temp || die 'failed to generate documentation'
printf '%s\n' '' '## compatibility' '' >> temp/README.md~ || die 'failed to make room for compatibility table'
dash ./tableize temp >> temp/README.md~ || die 'failed to generate compatibility table'
2021-08-01 00:35:56 -07:00
#[ ! -e README.md ] || backup README.md || die 'failed to backup existing readme'
mv temp/README.md~ README.md~ || die 'failed to move generated readme'
rm temp.tar.gz || die 'failed to clean up temp archive'
rm -r temp || die 'failed to clean up temp directory'
if [ "$1" = commit ]; then
mv README.md~ README.md || die 'failed to overwrite readme'
git commit README.md -m 'regenerate readme' || die 'failed to commit'
fi
fi