Last active
March 16, 2023 15:40
-
-
Save Kaizen86/0d2c2727231cae0328e529501ac0e406 to your computer and use it in GitHub Desktop.
Automatically clones and copies my tilde repository into the user's home folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # get-tilde.sh | |
| # | |
| # Clone the tilde repository and install it into the user's home directory | |
| # If you have wget installed, you can download the installer with this: | |
| # wget https://gist.githubusercontent.com/Kaizen86/0d2c2727231cae0328e529501ac0e406/raw/6b019bdc055aa0753958787f33d9d8d86a139e10/get-tilde.sh | |
| git clone https://github.com/Kaizen86/tilde.git | |
| # Did that work? | |
| if [ $? -ne 0 ]; then | |
| echo Abort - failed to clone. | |
| exit | |
| fi | |
| echo # Separator newline | |
| # Move all files, including hidden ones, to ~ | |
| shopt -s dotglob | |
| mv -vn tilde/* ~/ # Crucially, we mustn't clobber existing files! | |
| # If the folder cannot be removed, then it still has stuff in it. | |
| rmdir tilde | |
| if [ $? -ne 0 ]; then | |
| # Ask the user how they would prefer to solve this | |
| echo -e "\nWarning: conflicting items" | |
| echo Some files already exist in ~, so those were skipped. | |
| echo You can either merge the files manually, or overwrite them. | |
| read -p "Proceed to overwrite? [y/N] " opt | |
| # Exit if anything other than Y was entered | |
| case $opt in | |
| [Yy]* ) ;; # Do nothing and continue | |
| * ) echo Aborting.; exit;; | |
| esac | |
| # User chose to continue. | |
| # This time we need to account for conflicting directories | |
| # mv will refuse to rename into an existing folder; it must instead be copied. | |
| cp -rv ./tilde/* ~ && rm -Rf ./tilde/* | |
| # Try again | |
| rmdir tilde | |
| if [ $? -ne 0 ]; then | |
| # If this somehow fails again, then I'm at a loss. | |
| echo huh what | |
| exit | |
| fi | |
| fi | |
| # All done! User can now load the customisations | |
| echo -e "\nInstallation complete!" | |
| echo 'You can now run "source ~/.bashrc" :)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment