Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 110 lines (92 sloc) 1.95 KB
#!/usr/bin/env bash
set -e
# List of files that should not be installed.
exclude='
*.in
.git/*
.gitignore
INSTALL*
README
'
usage () {
echo "Usage: $0 [OPTIONS]"
echo
echo "Options:"
echo " -n, --dry-run Do not execute commands."
echo " -v, --verbose Print each command as they are executed."
echo " -l, --bashlocal Move .bashrc to .bashrc.local instead."
echo " -h, --help Display help message and exit."
}
get_full_username () {
getent passwd "$USER" |
cut -d ':' -f 5 |
cut -d ',' -f 1
}
# Expands environmental variables in file.
process_file () {
env |
sed 's/[\%]/\\&/g;s/\([^=\]*\)=\(.*\)/s%${\1}%\2%/' |
sed -f /dev/stdin "$1"
}
# Parse arguments.
rsync_args=
while [ $# -gt 0 ]; do
case "$1" in
-n|--dry-run)
rsync_args="$rsync_args -n"
;;
-v|--verbose)
rsync_args="$rsync_args -v"
;;
-l|--bashlocal)
bash_local=1
;;
-h|--help)
usage >&2
exit 0
;;
*)
echo "unknown option: $1" >&2
usage >&2
exit 1
;;
esac
shift
done
# If we already have a cache, read it.
if [ -f ./INSTALL.cache ]; then
. ./INSTALL.cache
fi
# Ask user for information that we should know.
export FULLNAME="${FULLNAME:-$(get_full_username)}"
printf 'Full name [%s]: ' "$FULLNAME"
read input
if [ "$input" != "" ]; then
export FULLNAME="$input"
fi
export EMAIL="${EMAIL:-"$USER@localhost"}"
printf 'Email address [%s]: ' "$EMAIL"
read input
if [ "$input" != "" ]; then
export EMAIL="$input"
fi
# Build cache.
env |
grep -e EMAIL -e FULLNAME |
sed -e 's/=/=\"/g' -e 's/$/\"/g' >./INSTALL.cache
# Process '*.in' files.
for i in $(find . -name '*.in'); do
out="$(dirname "$i")/$(basename "$i" .in)"
process_file "$i" >"$out"
done
# Move .bashrc to .bashrc.local first.
if [ "$bash_local" = "1" ]; then
mv .bashrc .bashrc.local
fi
# Install the files.
echo "$exclude" |
rsync -a $rsync_args --exclude-from /dev/stdin . "$HOME"
# Put .bashrc back to where it was.
if [ "$bash_local" = "1" ]; then
mv .bashrc.local .bashrc
fi
Something went wrong with that request. Please try again.