Several shell scripts in a wrapper pretending to be automation. User assumes all risk. http://functions.sh/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

120 lines
3.5 KiB

  1. #!/bin/bash
  2. # @author:'jakimfett'
  3. # @license;'cc-by-sa'
  4. #
  5. # A jumble of things meant to configure, set up, and otherwise assemble
  6. # the functions.sh framework and runtime environment.
  7. #
  8. # Commitment to non-destructive default paths:
  9. # # Generally, this script attempts to check with the user before doing #
  10. # # something (anything) destructive. The use of flags, or mashing your keyboard, #
  11. # # will override this non-destructive path, so read the warning lables. #
  12. #
  13. # Shorthand:
  14. # <name> = a variable, of the designation 'name'
  15. # ~/ = /home/<username>, directory reference
  16. #
  17. # files modified by this script:
  18. includeFilePath="$(realpath ~/.profile)" # <-- single line added to the end
  19. # set this next line to wherever you want your deployment of f.sh to live:
  20. defaultInstallRoot=$(realpath ~/functions.sh) # <-- default install location.
  21. # Yeah, that's actually it for the user configurable values.
  22. #
  23. # Here there be heavy wizardy and/or voodoo programming.
  24. # Which is which is left as an exercise for the end user.
  25. # http://eps.mcgill.ca/jargon/jargon.html#heavy%20wizardry
  26. # This is suboptimal, but *useful*.
  27. if [[ ! "$@" == *"--persistLog"* ]]; then
  28. clear
  29. fi
  30. echo "The functions.sh default location is:"
  31. echo "${defaultInstallRoot}"
  32. # currently, development is all we've got:
  33. defaultBranch='development'
  34. # where are you getting your code?
  35. repoSource='https://git.functions.sh/'
  36. # have you considered mirroring?
  37. # flags - set programmatically, tinker, but make backups
  38. # Get the current directory from the pa
  39. currentDirectory="$(realpath $(pwd) | rev| cut -d'/' -f1 | rev)"
  40. echo
  41. echo "Found current directory as:"
  42. echo "${currentDirectory}"
  43. echo "...done with found 'currentDirectory'."
  44. if [[ "$@" == *"--force"* ]]; then
  45. echo "Hidden force install protocal enabled, overwriting default install location."
  46. rm -rf "${defaultInstallRoot}"
  47. fi
  48. if [ -d "${defaultInstallRoot}" ]; then
  49. echo "Default install location exists, attempting to update."
  50. else
  51. echo "...default install location is empty, creating..."
  52. mkdir -p "${defaultInstallRoot}"
  53. echo "(exit code for directory creation was: '$?')"
  54. echo "...cloning tool locally..."
  55. git clone -b "${defaultBranch}" "${repoSource}" "${defaultInstallRoot}"
  56. echo "(exit code for repo clone was: '$?')"
  57. fi
  58. echo
  59. echo "...moving into install location..."
  60. cd "${defaultInstallRoot}"
  61. echo "Directory path is now:"
  62. pwd
  63. echo
  64. echo "Checking git status"
  65. git status 2>/dev/null > /dev/null
  66. isGit=$?
  67. if [ "${isGit}" == 0 ];then
  68. echo
  69. echo "The install directory is git."
  70. else
  71. echo
  72. echo "Directory at '${defaultInstallRoot}' not a git repo, please debug!"
  73. exit "${isGit}"
  74. fi
  75. if [[ "$@" == *"--force"* ]]; then
  76. echo "Forcing install of source to bash profile..."
  77. cp "${includeFilePath}" "${includeFilePath}.bak"
  78. cat "${includeFilePath}.bak" | egrep -v 'f.sh|functions.sh' >> "${includeFilePath}.install"
  79. echo "source '${defaultInstallRoot}/com/usr/aliases.src'" >> "${includeFilePath}.install"
  80. echo
  81. echo
  82. echo "See '${includeFilePath}.bak' file."
  83. echo "Execute the following command to complete installation:"
  84. echo "mv ${includeFilePath}.install ${includeFilePath}"
  85. exit 0
  86. fi
  87. # check if fsh is sourced in a variety of user files, eg .bash_aliases or .profile
  88. fshSourced="$(egrep 'f.sh|functions.sh' $(realpath ~/)/.* 2>/dev/null | grep -v grep | grep source | tail -1 )"
  89. if [ ! -z "${fshSourced}" ]; then
  90. echo "Found source directive in '$(echo ${fshSourced} | cut -d':' -f1)', debug?"
  91. echo "${fshSourced}"
  92. exit 0
  93. else
  94. echo "source '${defaultInstallRoot}/com/usr/aliases.src'" >> "${includeFilePath}"
  95. exit 0
  96. fi