bootstrap/replicate.sh

69 lines
2.0 KiB
Bash
Raw Normal View History

2018-08-24 17:30:41 -05:00
#!/bin/sh
## Set up some variables
name="$(basename "$0" .sh)"
deps="git rsync mktemp basename"
logfile="${PWD}/${name}.log"
tempfolder="$(mktemp -d tmp.replicate.XXXXXXXX --tmpdir)"
gitdir="$PWD/.dotfiles"
homedir="$PWD"
repo='git@gitlab.com:rehashedsalt/home.git'
## Define some functions
log() {
[ -z ${1+x} ] && return 1
2018-10-10 16:44:00 -05:00
printf "\e[94m${name}\e[0m: $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
if ! validatedep "$dep"; then
log "Could not find critical dependency \"$dep\""
2018-08-24 17:30:41 -05:00
exit 1
fi
done
# Build Home folder skeleton
log "Building skeleton folder layout"
2018-10-10 16:52:11 -05:00
mkdir Desktop Documents Downloads Games Music Pictures Projects Public ROMs System Templates Videos
2018-08-24 17:30:41 -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="$?"
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
# Move them to where they should be
log "Moving cloned repo from \"$tempfolder\" into \"$homedir\""
rsync -rvl --exclude ".git" "$tempfolder/" "$homedir/" >> "$logfile"
rm -rf "$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" submodule foreach 'git checkout master && git pull' >> "$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 "You may now delete the script"
2018-08-24 17:30:41 -05:00
exit 0