dotfiles

Cem's Dotfiles
git clone git://git.ckyln.com/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

updot (3741B)


      1 #!/usr/bin/env sh
      2 
      3 out() { printf "$@\\n" ;}
      4 error() { out "ERROR: $@" ; } >&2
      5 msg() { out "==> $@" ; }
      6 die() { error "$@"; exit 1; }
      7 
      8 pacman --version >/dev/null 2>&1 && carbs="carbs" && alias install="sudo pacman -S --noconfirm --needed" && defdot="git://git.ckyln.com/dotfiles"
      9 xbps-install --version >/dev/null 2>&1 && carbs="vcarbs" && alias install="sudo xbps-install -y" && defdot="git://git.ckyln.com/vdotfiles"
     10 
     11 update() {
     12 	if [ "$carbs" = "carbs" ]; then
     13 		sudo pacman -Syu --noconfirm || die "Could not update the system"
     14 	elif [ "$carbs" = "vcarbs" ]; then
     15 		sudo xbps-install -Syu && sudo xbps-install -Syu || die "Could not update the system"
     16 	fi
     17 }
     18 
     19 while getopts ':p::r::P:d' flag; do
     20 	case $flag in
     21 		P) [ -n "$carbs" ] && curl -sLo "$OPTARG" https://git.ckyln.com/raw/${carbs}/progs.csv && exit || die 'Could not download progs.csv' ;;
     22 		p) [ -e "$OPTARG" ] && progs=$OPTARG || die 'Could not find progs.csv file' ;;
     23 		r) git ls-remote "$OPTARG" >/dev/null 2>&1 && dotfiles=$OPTARG || die 'Could not find repo' ;;
     24 		d) dotonly=1 ;;
     25 		:) die "$OPTARG option requires argument" ;;
     26 		?) die "invalid option -- $OPTARG" ;;
     27 	esac
     28 done
     29 
     30 [ -z "$dotonly" ] && [ -z "$carbs" ] && \
     31 	die "It seems like you don't use Arch Linux or Void Linux\\nYou might want to run updot -d"
     32 [ -z "$dotfiles" ] && dotfiles="${defdot-git://git.ckyln.com/dotfiles}"
     33 [ -z "$progs" ] && curl -sLo /tmp/progs.csv https://git.ckyln.com/raw/${carbs-carbs}/progs.csv  && progs="/tmp/progs.csv"
     34 
     35 welcomepage() {
     36 	clear
     37 	cat <<EOF
     38 ================================================== 
     39 ===     ======  =====       ===      =====      == 
     40 ==  ===  ====    ====  ====  ==  ===  ===  ====  = 
     41 =  =========  ==  ===  ====  ==  ====  ==  ====  = 
     42 =  ========  ====  ==  ===   ==  ===  ====  ====== 
     43 =  ========  ====  ==      ====      =======  ==== 
     44 =  ========        ==  ====  ==  ===  ========  == 
     45 =  ========  ====  ==  ====  ==  ====  ==  ====  = 
     46 ==  ===  ==  ====  ==  ====  ==  ===  ===  ====  = 
     47 ===     ===  ====  ==  ====  ==      =====      == 
     48 ================================================== 
     49 
     50 Welcome to Cem's Auto-Rice Bootstrapping Script!
     51 
     52 Dotfiles Repository: $dotfiles
     53 
     54 WARNING:
     55 This update might break your personal changes, so 
     56 it is highly recommended that you backup your .config
     57 before you continue.
     58 
     59 EOF
     60 printf "Proceed? (y/N) "
     61 read ans
     62 [ "$ans" = "y" ] || die "User exited"
     63 }
     64 
     65 makeinstall() {
     66 	cd /tmp || return 1
     67 	dir="$(mktemp -d)"
     68 	git clone "$1" "$dir" || die "Could not clone git repo"
     69 	cd "$dir" || return 1
     70 	make || die "Could not build $1"
     71 	sudo make install || die "Could not install $1"
     72 }
     73 
     74 installcsv() {\
     75         out "It is best to update the system before updating CARBS packages\\nUpdate system? (y/n)"
     76 	read ans && [ "$ans" = "y" ] && update
     77 	[ -e $progs ] || die "Could not retrieve progs.csv"
     78 	while IFS=, read -r src name
     79 	do
     80 		case $src in
     81 			y)
     82 				out "Installing $name"
     83 				yay -S --noconfirm --needed "$name" >/dev/null || die "Could not install $name"
     84 				msg "Installed $name" ;;
     85 			g)
     86 				out "Installing $name"
     87 				makeinstall "$name" || die "Could not install $name"
     88 				msg "Installed $name" ;;
     89 			*)
     90 				out "Installing $name"
     91 				install "$name" >/dev/null || die "Could not install $name"
     92 				msg "Installed $name" ;;
     93 		esac
     94 	done < $progs
     95 }
     96 
     97 dotfilesinstall() {
     98 	cd /tmp || return 1
     99 	dir="$(mktemp -d)"
    100 	git clone --recursive --depth 1 "$1" "$dir/repo" || return 1
    101 	cp -rfT "$dir/repo" "$HOME" || die "Could not copy repository to your home directory"
    102 	rm "$HOME"/README* "$HOME"/LICENSE "$HOME"/.git -rf "$HOME"/screenshots
    103 }
    104 
    105 finalize() {
    106 printf "Carbs update script is finished\\n\\n"
    107 }
    108 
    109 welcomepage
    110 [ -z $dotonly ] && installcsv
    111 dotfilesinstall $dotfiles || die "Could not install dotfiles"
    112 finalize