-
Notifications
You must be signed in to change notification settings - Fork 89
/
install.sh
executable file
·94 lines (78 loc) · 2.03 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# Script Purpose {{{1
# This scripts helps to install Bash-Scripts into $HOME/bin.
# Hard links will be created in ~/bin for the main scripts in the
# current directory.
#
# License: CC-BY-SA 3.0 v2 {{{1
# Code {{{1
# Obtain current script dir {{{2
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in/2633580#2633580
# This comment and code Copyleft, selectable license under the GPL2.0 or
# later or CC-SA 3.0 (CreativeCommons Share Alike) or later. (c) 2008.
# All rights reserved. No warranty of any kind. You have been warned.
# http://www.gnu.org/licenses/gpl-2.0.txt
# http://creativecommons.org/licenses/by-sa/3.0/
current_dir() {
pushd $(dirname $(readlink -f "$BASH_SOURCE")) > /dev/null
local SCRIPT_DIR="$PWD"
popd > /dev/null
echo $SCRIPT_DIR
}
# ----
# Usage and options {{{2
usage() {
echo "USAGE: $0 [-v|--verbose] [HOMEDIR]"
echo "USAGE: $0 [-h|--help]"
}
verbose=0
HOMEDIR=""
while [ $# -gt 0 ] ; do
case $1 in
-h|--help)
usage
exit -1
;;
-v|--verbose)
verbose=1
shift
;;
*)
if [ x"$HOMEDIR0" != x"" ] ; then
echo "$0: Error HOMEDIR already overridden"
usage
exit 1
fi
HOMEDIR0=$1
shift
;;
esac
done
HOMEDIR=${HOMEDIR0:-$HOME}
# The main code
ORIG=$(current_dir)
cd "$ORIG"
files=$(ls *.bashrc *.sh)
cd "$HOMEDIR/bin"
if [ $verbose -gt 0 ] ; then
echo cd "$HOMEDIR/bin"
fi
for f in $files ; do
case $f in
install.sh) # ignore this script
continue
;;
cyg-wrapper.sh) # ignore cyg-wrapper.sh on non-cygwin systems
uname=$(uname)
if [ "${uname/CYGWIN/}" = "$uname" ] ; then
continue
fi
;;
esac
if [ $verbose -gt 0 ] ; then
echo ln "$ORIG/$f"
fi
rm "$f"
ln "$ORIG/$f"
done
# vim:set fdm=marker: