install_unattended.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # Go trough all the files available in this folder.
  3. commonFiles=();
  4. for sourceFile in .*; do
  5. # Exclude some files.
  6. if [[ "$sourceFile" == "install_unattended.sh" || "$sourceFile" == "install.sh" ]] || [[ "$sourceFile" == "README.md" ]] || [[ "$sourceFile" == "." ]] || [[ "$sourceFile" == ".." ]] || [[ "$sourceFile" == ".git" ]]; then
  7. continue;
  8. fi;
  9. # Set the target path for the source file.
  10. # We'll port them to the ~/ (home) directory.
  11. targetFile="$HOME/$sourceFile";
  12. # The file already exists.
  13. if [ -e "$targetFile" ]; then
  14. # The source and target point to the same file, continue.
  15. [ "$sourceFile" -ef "$targetFile" ] && continue;
  16. # The content of the file is the same, continue.
  17. diff -rq "$sourceFile" "$targetFile" > /dev/null 2>&1 && continue;
  18. # The source file is another file than our dotfile.
  19. # Store it in the commonFiles array so we can back it up.
  20. commonFiles+=("$sourceFile");
  21. fi;
  22. done;
  23. # Show the files that will be overwritten.
  24. conflictCount=${#commonFiles[@]};
  25. # Create a suffix with a timestamp so the user can see which
  26. # files and when they've been backupped.
  27. backupSuffix=".jsVimconfig-$(date +'%Y%m%d-%H%M%S')";
  28. # Rename the conflicting files as backup.
  29. for sourceFile in "${commonFiles[@]}"; do
  30. targetFile="$HOME/$sourceFile";
  31. mv -v "$targetFile" "$targetFile$backupSuffix";
  32. done;
  33. # Symlink the files in the home dir by those in the dotfiles repo.
  34. for sourceFile in .*; do
  35. # Exclude some files.
  36. if [[ "$sourceFile" == "install_unattended.sh" || "$sourceFile" == "install.sh" ]] || [[ "$sourceFile" == "README.md" ]] || [[ "$sourceFile" == "." ]] || [[ "$sourceFile" == ".." ]] || [[ "$sourceFile" == ".git" ]]; then
  37. continue;
  38. fi;
  39. targetFile="$HOME/$sourceFile";
  40. # Delete the old file and replace it by the symlink.
  41. rm -rf "$targetFile" &&
  42. ln -vs "$PWD/$sourceFile" "$targetFile";
  43. done;
  44. # This will add a tag to our prompt, so we know which environment we're in.
  45. # It is adaptable in ~/.bash_environment
  46. touch ~/.bash_environment;
  47. echo -e "export __prompt_environment='[DEVELOPMENT] '" | tee ~/.bash_environment > /dev/null;