install.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/bin/sh
  2. set -e
  3. ##############################
  4. # CONTACT
  5. ##
  6. # GitHub: @ipatch
  7. # Twitter: @truckmonth
  8. # Email: me@chrisrjones.com
  9. # Install script for @ipatch dotfiles.
  10. # version: 0.0.5
  11. ##############################
  12. # PREAMBLE
  13. ##
  14. # `curl`
  15. # -f = fail silently
  16. # -s = silent mode, ie. no progress bar
  17. # -S = works in conjunction with `-s` and shows errors if something fails "F-"
  18. # -L = useful for redirection
  19. ##
  20. #############################
  21. # INSTALLATION
  22. ##
  23. # curl -s https://raw.githubusercontent.com/ipatch/dotfiles/feature-exp-with-curl/develop/install.sh | /bin/sh
  24. # TODO: prefix all local vars in this script with `dots`, I use the word local very loosely
  25. # look for bash v1
  26. # dots_bash_path="$(type -a bash)"
  27. # printf '%s\n' "$dots_bash_path"
  28. # > the above was cool, but did not play well with Alpine Linux /bin/sh inside a docker container
  29. ##############################
  30. # TODO: clear all previous environment variables 👩
  31. ##
  32. ##############################
  33. # NOTE: taste the rainbow™ 🌈
  34. ##
  35. Bld='\e[1m' # Enable Bold text
  36. Itl='\e[3m' # Enable Italic
  37. Und='\e[4m' # Enable Underline
  38. Rst='\e[0m' # Reset text
  39. # Regular High Intensity BoldHigh Intens
  40. Bla='\e[0;30m'; IBla='\e[0;90m'; BIBla='\e[1;90m';
  41. Red='\e[0;31m'; # IRed='\e[0;91m'; BIRed='\e[1;91m';
  42. Gre='\e[0;32m'; IGre='\e[0;92m'; BIGre='\e[1;92m';
  43. Yel='\e[0;33m'; IYel='\e[0;93m'; BIYel='\e[1;93m';
  44. Blu='\e[0;34m'; IBlu='\e[0;94m'; BIBlu='\e[1;94m';
  45. Pur='\e[0;35m'; IPur='\e[0;95m'; BIPur='\e[1;95m';
  46. Cya='\e[0;36m'; ICya='\e[0;96m'; BICya='\e[1;96m';
  47. Whi='\e[0;37m'; IWhi='\e[0;97m'; BIWhi='\e[1;97m';
  48. blue=$(tput setaf 4)
  49. normal=$(tput sgr0)
  50. # NOTE: from the printf(1) man page, `%b` interprets a string with a `\`
  51. printf "%bThis text is red%s""\\n" "$Red" "$normal"
  52. printf "%sThis text is blue%s""\\n" "$blue" "$normal"
  53. # printf "%bThis text is going to be purple." "\\n" "$Pur"
  54. # Usage: `printf "${Blu}blue ${Red}red ${Rst}etc..."`
  55. printf "%bblue %bred %betc...""\\n" "$Blu" "$Red" "$Rst"
  56. printf "%bHello World""\\n" "$Gre" "$Rst"
  57. printf "%bitalics""\\n" "$Itl" "$Rst"
  58. # printf "%b %bitalics""\\n" "$Itl" "$Red" "$Rst"
  59. printf "%bBOLD + italics""\\n" "$Bld" "$Itl" "$Rst"
  60. printf "%bbold + italics""\\n" "$Bld" "$Itl" "$Rst"
  61. printf "%bThis text should bold + blue""\\n" "$Bld" "$Blu" "$Rst"
  62. # retrieve 🐕 running Operating System
  63. if test -x /usr/bin/uname
  64. then
  65. dots_os="$(/usr/bin/uname)"
  66. printf "Your %bOS%b appears to be %s, ie. %bmacOS%b""\\n" "$BIWhi" "$Rst" "$dots_os" "$BIWhi" "$Rst"
  67. # ask $USER if the above is correct?
  68. printf "Im going to test the color %bGreen%b""\\n" "$Gre" "$Rst"
  69. printf "Is your OS, macOS (%by%b/%bn%b)?""\\n" "$Gre" "$Rst" "$Red" "$Rst"
  70. read -r choice < /dev/tty
  71. case "$choice" in
  72. y|Y ) printf "👌 %bOkay, lets continue...%b""\\n" "$Gre" "$Rst";;
  73. n|N ) printf "%bWell 💩 thats embarrassing'\\n'...and we cant continue.%b""\\n" "$Red" "$Rst";;
  74. # TODO: add color for 'y' and 'n' if possible
  75. *) printf "You gotta mash %by%b or %bn%b""\\n" "$Gre" "$Rst" "$Red" "$Rst"
  76. esac
  77. elif test -x /bin/uname
  78. then
  79. dots_os="$(/bin/uname)"
  80. echo "Your OS appears to be $dots_os"
  81. # ask $USER if the above is correct?
  82. read -r "Is your OS Linux (y/n)?" choice < /dev/tty
  83. case "$choice" in
  84. y|Y ) printf "👌 Okay, wtf lets '\\n' continue...""\\n";;
  85. n|N ) printf "well 💩 that'\\''s embarrassing '\\n' and we can't continue.""\\n";;
  86. # TODO: add color for 'y' and 'n' if possible
  87. *) echo "you gotta mash 'y' or 'n'"
  88. esac
  89. else
  90. # TODO: test this condition using a FreeBSD docker image
  91. printf "Could not identify your OS 🤷"
  92. fi
  93. # look for bash v2
  94. if test -x /usr/local/bin/bash
  95. then
  96. printf "found /usr/local/bin/bash"
  97. dots_bash_bin="/usr/local/bin/bash"
  98. printf "%s =" "$dots_bash_bin"
  99. elif test -x /usr/bin/bash
  100. then
  101. echo "found /usr/bin/bash"
  102. dots_bash_bin="/usr/bin/bash"
  103. else
  104. echo "404 bash not found"
  105. fi
  106. printf "%s" "$dots_bash_bin"
  107. # > When setting the output of a command to a variable make sure to enclose `$(command)` within double quotes
  108. # Ex. `"$(type -a bash)"
  109. # > `printf` is preferred over `echo`
  110. # > However, if using `echo` do `echo "$MY_VAR"` as opposed to `echo $MY_VAR` to properly interpret new line, ie. `\n`
  111. # echo "$SHELL"
  112. # echo "$0"
  113. # > Running `echo "$0"` locally echos `./install.sh`
  114. # sanity check 👩
  115. # echo "foo"
  116. # if $DOTS_BASH_PATH contains `/usr/local/bin/bash` or `/usr/bin/bash`
  117. # change the current shell to `bash`
  118. # end / fi
  119. # if expr "$dots_bash_path" : ".*bash" >/dev/null;
  120. # then echo "found bash"
  121. # else
  122. # echo "you need to install BASH to continue"
  123. # exit 1
  124. # fi
  125. # check to see if script will stop if bash isn't found
  126. # echo "how the hell did i get here without bash"
  127. # swith from /bin/sh to /usr/bin/env bash