/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1
13 by Gustav Hartvigsson
install.sh
1
#!/usr/bin/env bash
2
####
3
# FILE NAME install.sh
4
#
5
# Install script for these scripts.
6
#
7
####
8
9
10
__INSTALL_DIR=$HOME/bin
11
__INSTALL_SET=0
12
13
# https://stackoverflow.com/a/246128
14
__CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
15
16
#TODO: Add unistall option..
17
function __usage () {
18
  echo ""
19
  echo "install.sh [options]"
20
  echo ""
21
  echo "    Install the scripts"
22
  echo ""
23
  echo " -h"
24
  echo " --help                   Display this help message."
25
  echo ""
26
  echo ""
27
  echo " -i"
28
  echo " --install                Install the scripts. You have to provide this"
29
  echo "                          if you want to install the scripts."
30
  echo ""
31
  echo " --target <directory>     Directory to install the scripts into."
32
  echo "                          Default: \$HOME/bin"
33
  echo ""
34
  exit 0
35
}
36
37
function __parse_args () {
38
  
39
  while [[ $# -gt 0 ]]
40
  do
41
    case "${1}" in
42
      -i|--install)
43
      __INSTALL_SET=1
44
      shift
45
      ;;
46
      -h|--help)
47
      __usage
48
      shift
49
      ;;
50
      --target)
51
      __INSTALL_DIR="${2}"
52
      exit
53
      shift
54
      ;;
55
      *)
56
      shift
57
      ;;
58
      --)
59
      shift
60
      break
61
      ;;
62
    esac
63
  done
64
}
65
66
####
67
# Utility function that prints what what is being executed.
68
# See: https://stackoverflow.com/a/23342259
69
####
70
function __exe () { echo "    $@" ; "$@" ; }
71
72
function __main () {
73
  if [[ $__INSTALL_SET == 1 ]]
74
  then
75
    __exe mkdir -p $__INSTALL_DIR
76
    for __file__ in $__CWD/scripts/*.sh
77
    do
78
      __exe cp $__file__ $__INSTALL_DIR/
79
    done
80
  else
81
    echo ""
82
    echo "YOU MUST PROVIE -i OR --install FOR IT TO INSTALL THE SCRIPTS."
83
    echo "Please see -h or --help for more information."
84
    echo ""
85
    exit 1
86
  fi
87
  exit 0
88
}
89
90
__parse_args "${@}"
91
__main