-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·127 lines (106 loc) · 2.55 KB
/
install.sh
File metadata and controls
executable file
·127 lines (106 loc) · 2.55 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/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] [-s|--symlink] [HOMEDIR]"
echo "USAGE: $0 [-h|--help]"
}
verbose=0
symlink=""
HOMEDIR=""
while [ $# -gt 0 ] ; do
case $1 in
-h|--help)
usage
exit -1
;;
-v|--verbose)
verbose=1
shift
;;
-s|--symlink)
symlink="-s"
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)
if [ ! -d "$HOMEDIR/bin" ]; then
mkdir "$HOMEDIR/bin"
if [ $verbose -gt 0 ] ; then
echo mkdir "$HOMEDIR/bin"
fi
fi
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
if [ -L "$f" ]; then
rm "$f"
elif [ -e "$f" ]; then
while true; do
read -p "$f exists and is not a symbolic link, delete anyway? [Y/N] " yn
case $yn in
[Yy]* )
rm -rf $f
break;
;;
[Nn]* )
echo "Skipping $f"
continue 2
;;
* ) echo "Please answer yes or no.";;
esac
done
fi
ln $symlink "$ORIG/$f"
done
# vim:set fdm=marker: