forked from eacousineau/util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·106 lines (97 loc) · 1.42 KB
/
install
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
#!/bin/bash
set -e -u
# Is there a script like this already?
# Too lazy for /bin/sh
bin="$(basename $0)"
usage()
{
echo "$bin [--no-clean] [--link] [-u | --uninstall] <DEST>"
exit $1
}
clean=1
link=
uninstall=
while test $# -gt 0
do
case $1 in
--no-clean)
clean=
;;
--link)
link=1
;;
-u|--uninstall)
uninstall=1
;;
-h|--help)
usage 0
;;
*)
break
;;
esac
shift
done
if test $# -eq 0
then
echo "Need to supply directory (absolute path) to put this stuff in."
dir=/usr/local/bin
else
dir=$1
shift
fi
path=$(dirname $BASH_SOURCE)
cd $path
linkerade()
{
new=$(basename $1 .sh)
src=~+/$1
dest=$dir/$new
if test -h "$dest" -a \( -n "$uninstall" -o -n "$clean" \)
then
echo -e "Removing $dest"
rm $dest
fi
if test -z "$uninstall"
then
if test -z "$link"
then
echo "Copying $src -> $dest"
cp $src $dest
else
echo "Linking $src -> $dest"
ln -s $src $dest
fi
fi
}
if test $# -eq 0
then
scripts=$(dir *.sh)
else
scripts=$@
fi
for script in $scripts
do
linkerade $script
done
# Install bash completion
fname=git-sube
src=~+/$fname
dest=/etc/bash_completion.d/$fname
if test -h "$dest" -a \( -n "$uninstall" -o -n "$clean" \)
then
echo -e "Removing $dest"
rm $dest
fi
if test -z "$uninstall"
then
if test -z "$link"
then
echo "Copying $src -> $dest"
cp $src $dest
else
echo "Linking $src -> $dest"
ln -s $src $dest
fi
chmod 644 $src $dest
fi