2018-08-24 17:30:41 -05:00
|
|
|
#!/bin/sh
|
2018-09-16 12:13:54 -05:00
|
|
|
|
|
|
|
## Set up some variables
|
|
|
|
name="$(basename "$0" .sh)"
|
|
|
|
deps="git rsync mktemp basename"
|
|
|
|
|
|
|
|
logfile="${PWD}/${name}.log"
|
|
|
|
tempfolder="$(mktemp -d)"
|
|
|
|
gitdir="$PWD/.dotfiles"
|
|
|
|
homedir="$PWD"
|
|
|
|
repo='git@gitlab.com:rehashedsalt/home.git'
|
|
|
|
|
|
|
|
## Define some functions
|
|
|
|
log() {
|
|
|
|
[ -z ${1+x} ] && return 1
|
|
|
|
printf "${name}: $1\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
validatedep() {
|
|
|
|
if ! which $1 > /dev/null 2>&1; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
## Do the do
|
|
|
|
# Rotate the logfile, if necessary
|
|
|
|
if [ -f "$logfile" ]; then
|
|
|
|
log "Found old logfile. Rotating"
|
|
|
|
mv "$logfile" "$logfile.old"
|
|
|
|
fi
|
|
|
|
# Ensure we have the proper dependencies
|
|
|
|
log "Validating dependencies"
|
2018-08-24 17:30:41 -05:00
|
|
|
for dep in $deps; do
|
2018-09-16 12:13:54 -05:00
|
|
|
if ! validatedep "$dep"; then
|
|
|
|
log "Could not find critical dependency \"$dep\""
|
2018-08-24 17:30:41 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2018-09-16 12:13:54 -05:00
|
|
|
# Build Home folder skeleton
|
|
|
|
log "Building skeleton folder layout"
|
|
|
|
mkdir Desktop Documents Downloads Games Music Pictures Projects System Videos
|
2018-08-24 17:30:41 -05:00
|
|
|
|
2018-09-16 12:13:54 -05:00
|
|
|
# Clone the dotfiles
|
|
|
|
log "Cloning repository"
|
|
|
|
git clone --recursive --depth 100 --separate-git-dir="$gitdir" "$repo" "$tempfolder" >> "$logfile" 2>&1
|
2018-08-24 17:30:41 -05:00
|
|
|
error="$?"
|
2018-09-16 12:13:54 -05:00
|
|
|
if ! [ "$error" -eq "0" ]; then
|
|
|
|
log "Failed cloning repository \"$repo\": git returned $error"
|
|
|
|
log "See $logfile for details"
|
|
|
|
log "Do you have the appropriate permissions? Does the remote host know your key?"
|
2018-08-24 17:30:41 -05:00
|
|
|
exit 2
|
|
|
|
fi
|
2018-09-16 12:13:54 -05:00
|
|
|
# Move them to where they should be
|
|
|
|
log "Moving cloned repo from \"$tempfolder\" into \"$homedir\""
|
|
|
|
rsync -rvl --exclude ".git" "$tempfolder/" "$homedir/" >> "$logfile"
|
|
|
|
rm -r "$tempfolder"
|
|
|
|
rmdir "$tempfolder"
|
|
|
|
# Finish syncing
|
|
|
|
log "Updating submodules and performing basic configuration"
|
|
|
|
git --git-dir="$gitdir" --work-tree="$homedir" submodule update --init --recursive --remote >> "$logfile" 2>&1
|
|
|
|
git --git-dir="$gitdir" --work-tree="$homedir" config status.showUntrackedFiles no >> "$logfile" 2>&1
|
|
|
|
|
|
|
|
# Print some post-install instructions
|
|
|
|
log "Dotfiles set up successfully"
|
|
|
|
log "Be sure and configure the following before issuing any commits:"
|
|
|
|
log " git config --global user.email"
|
|
|
|
log " git config --global user.name"
|
|
|
|
log "You may now delete the script"
|
2018-08-24 17:30:41 -05:00
|
|
|
exit 0
|