From 4ead9be4468d8d58c027bf6e6616e3b4d6e727eb Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 22 Aug 2019 18:30:24 +0200 Subject: Complete re-structuring so it's easier to install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- install.sh | 167 ++++++++++++++++++++++++++++--------------------------------- 1 file changed, 76 insertions(+), 91 deletions(-) (limited to 'install.sh') diff --git a/install.sh b/install.sh index 224546d..851b133 100755 --- a/install.sh +++ b/install.sh @@ -1,101 +1,86 @@ #!/bin/bash +# Copyright (C) 2014-2019 Miquel Sabaté Solà +# +# 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 . -PROJECTS="$HOME/Projects" - -# If something goes wrong, get the f*ck out. set -e -# Initialize and update git submodules. -git submodule init -git submodule update - -# Install the files on this repo. -cp bashrc $HOME/.bashrc -cp bash_profile $HOME/.bash_profile -cp psqlrc $HOME/.psqlrc -cp valgrindrc $HOME/.valgrindrc -cp irbrc $HOME/.irbrc -cp gemrc $HOME/.gemrc -cp gitcompletion.sh $HOME/.gitcompletion.sh -cp gitconfig $HOME/.gitconfig -cp global.gitignore $HOME/.gitignore -cp agignore $HOME/.agignore -cp hgrc $HOME/.hgrc -cp hgcompletion.sh $HOME/.hgcompletion.sh -cp global.hgignore $HOME/.hgignore -cp tmux.conf $HOME/.tmux.conf -cp rake_completion $HOME/.rake_completion -cp rvmrc $HOME/.rvmrc -cp gnupg/gpg.conf $HOME/.gnupg/gpg.conf -cp gnupg/gpg-agent.conf $HOME/.gnupg/gpg-agent.conf -cp mbsyncrc $HOME/.mbsyncrc -chmod +x $HOME/.rake_completion - -# Some random scripts -cp -r bin $HOME/bin -rm -rf $HOME/bin/test -chmod +x $HOME/bin/* -sudo mv $HOME/bin/e /usr/bin/e - -# i3 and X stuff. An incomplete list of openSUSE packages that I need in order -# to have a good i3 environment is: i3 xlockmore dunst i3status nitrogen scrot -# breeze5-cursors konsole gpicview okular dmenu the_silver_searcher. -mkdir -p $HOME/.config/dunst $HOME/.i3 -cp i3/config $HOME/.i3/config -cp i3status.conf $HOME/.i3status.conf -cp inputrc $HOME/.inputrc -cp Xresources $HOME/.Xresources -cp xinitrc $HOME/.xinitrc -cp -r fonts $HOME/.fonts -cp config/dunst/dunstrc $HOME/.config/dunst/dunstrc - -# Make Caps Lock an extra control. -# sudo localectl set-x11-keymap es "" cat, 'ctrl:nocaps' -sudo localectl set-x11-keymap us "" us, 'ctrl:nocaps' - -# Wipe out the current vim config and replace it with this one. -rm -rf $HOME/.vim -rm -rf $HOME/.vimrc -cp -rf vim $HOME/.vim -cp vimrc $HOME/.vimrc +## +# First some checks: we need GNU Emacs and Vim because we are going to +# initialize them right after installing their files. + +if ! [ -x "$(command -v emacs)" ]; then + echo 'Error: GNU Emacs is not installed.' >&2 + exit 1 +fi + +if ! [ -x "$(command -v vim)" ]; then + echo 'Error: Vim is not installed.' >&2 + exit 1 +fi + +## +# Main procedure: link as many files as possible. + +ary=(.git .gitignore .gitmodules LICENSE *.gitignore *.yml *.org install.sh + update.sh .emacs.d .config .gnupg Images) +ignore="-name ${ary[0]}" +for i in "${ary[@]:1:${#ary[@]}}"; do + ignore+=" -or -name $i" +done + +for file in $(find "$(pwd)" -mindepth 1 -maxdepth 1 ! \( $ignore \)); do + # The -F and -f flags of ln suck. Let's rm all the way. + rm -rf "${HOME:?}/$(basename $file)" + ln -s "$file" "${HOME:?}/$(basename $file)" +done + +## +# And now let's go for the exceptional cases. + +# Link the global.gitignore file +rm "${HOME:?}/.gitignore" +ln -s global.gitignore "${HOME:?}/.gitignore" + +# Copy entries of some of the directories inside of maybe existing ones. +for i in Images .config .gnupg; do + mkdir -p "${HOME:?}/$i" + cp -r "$i"/* "${HOME:?}/$i/" +done + +# GNU Emacs: most files can be simply linked, the only exception being +# init.el. To know why check .emacs.d/README.org. +mkdir -p "${HOME:?}/.emacs.d" +for i in lisp org-templates snippets custom.el gtkrc init.org; do + rm -rf "${HOME:?}/.emacs.d/$i" + ln -s "$(readlink -f .emacs.d/$i)" "${HOME:?}/.emacs.d/$i" +done +rm -f "${HOME:?}/.emacs.d/init.elc" +cp .emacs.d/init.el "${HOME:?}/.emacs.d/init.el" +emacs -l "${HOME:?}/.emacs.d/init.el" --eval "(kill-emacs)" + +## +# Other stuff + +# Initialize Vim plugins. vim +PluginInstall +qall -# GNU Emacs -rm -rf $HOME/.emacs.d -mkdir -p $HOME/.emacs.d -cp emacs/custom.el $HOME/.emacs.d/custom.el -cp emacs/init.el $HOME/.emacs.d/init.el -ln -s emacs/init.org $HOME/.emacs.d/init.org - -# Update the style for KTE users (KWrite, Kate, KDevelop & Kile). Note that -# there are two configs: the global one and the KDE one. The KDE one assumes -# that all your KDE projects are stored in the `$HOME/Projects/kde` directory. -# The global one is installed in the $HOME directory. -mkdir -p $PROJECTS/kde -cp kte/kde.kateconfig $PROJECTS/kde/.kateconfig -cp kte/global.kateconfig $HOME/.kateconfig - # Download and install the g utility -cd /tmp +pushd /tmp rm -rf g git clone https://github.com/mssola/g cd g -cp g.sh $HOME/.g.sh -cp gcompletion.sh $HOME/.gcompletion.sh - -# Download and install the review utility -cat <