#!/bin/sh # Install script for dotfiles repo # Copyright © 2017 Alex Hirschberg # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . dotfiles_repo="http://www.github.com/ahirschberg/dotfiles.git" echo "Now beginning dotfiles setup! Take a look at $dotfiles_repo in a web browser to see will be downloaded. We won't install anything until we run some checks and get your confirmation that you are ready to get set up." echo homefolder="$1" if [ ! -t 0 ]; then echo "ERROR: You're running this script from a pipe. \`curl | bash\`? CURLing" echo "scripts from random people on the internet is a bad idea, and causes this" echo "script not to work properly because we need to use STDIN confirmation. If" echo "you are downloading this script via CURL, please rerun it with an output" echo "file and then run the resulting file from bash." exit -1 fi if [ -z "$homefolder" ]; then read -p "What path do you want to install to? (leave blank for $HOME) ~> " homefolder homefolder=${homefolder:-$HOME} fi echo "Will install everything to $homefolder (current working dir: $PWD)" git_bin=$(which git) cfg_folder_name=".cfg.git" if [ -z $git_bin ]; then echo "No git binary found. Make sure you have git installed and on your path." exit 1 fi bare_gitfolder="$homefolder/$cfg_folder_name" if [ -d $bare_gitfolder ]; then echo "Looks like you've already got a bare repo folder $bare_gitfolder. Exiting..." exit 2 fi echo echo "You may find it useful to fork this repo and modify it to suit your needs before installing. If you do this, simply update my \$dotfiles_repo variable (at the top of this file) and re-run me!" read -p "Really start the dotfiles install? [y/n] ~> " install_confirm if [ "$install_confirm" != "y" ]; then echo "Not ready to install yet? That's ok :/" exit fi # BEGIN SETUP mkdir $bare_gitfolder # create and configure the git repo git init --bare $bare_gitfolder cat < $bare_gitfolder/config [core] repositoryformatversion = 0 filemode = true bare = true [status] showUntrackedFiles = no [remote "origin"] url = $dotfiles_repo fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master EOF gdot_cmd="$git_bin --git-dir=$bare_gitfolder --work-tree=$homefolder" $gdot_cmd pull origin master if [ $? != 0 ]; then echo echo "Something went wrong when pulling the dotfiles from git." echo "If you'd like to continue the git pull manually, paste the following command into your console and use gitdf to issue git commands:" echo " alias gitdf=\"$gdot_cmd\"" echo "If you really don't care about your current dotfiles and want to completely nuke them to install, I've found that taking the above output of conflicting files and passing it to the the rm -r command is useful, but do this WITH CARE. You may also want to cp everything to a backup folder first, before removing." exit 3 fi # set up bash to source all _scriptname.sh files in the .scripts/ dir echo "Adding a line to your bashrc: source .init_scripts.sh" echo "source ~/.init_scripts.sh" >> $homefolder/.bashrc . $homefolder/.init_scripts.sh echo "Here are the files being tracked in the dotfiles:" $gdot_cmd ls-tree -r master --name-only echo "Completed install of dotfiles!" exit 0 # need exit statement here so that the stdin redirects back if running from pipe