-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe4s-info-install.sh
executable file
·140 lines (116 loc) · 4.65 KB
/
e4s-info-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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/sh
argError()
{
echo
echo "Invalid arguments -- \"$ARGS\""
echo "Please use \"./e4s-info-install.sh -h\" or \"./e4s-info-install.sh --help\" to display more information"
echo
exit 1
}
argPath()
{
echo
echo "No access to directory: FIXME"
echo "Please use \"./e4s-info-install.sh -h\" or \"./e4s-info-install.sh --help\" to display more information"
echo
exit 2
}
help()
{
# Display Help
echo "Usage: ./install.sh [OPTION]... [DIRECTORY]... "
echo "Installs the e4s-info command and command manual"
echo
echo "Options:"
echo " -h --help Displays information about the command"
echo " --prefix=foo Specifies the directory the e4s-info command will reside after execution; the path must be"
echo " --mandir=foo Specifies the directory the manual entry for the e4s-info command will reside after execution"
echo
echo "Examples"
echo " ./install.sh Installs the e4s-info command and manual files in the default locations, which are /usr/local/bin/ and /usr/local/share/man/man1/ respectively"
echo " ./install.sh --prefix=~/bin/ Installs the e4s-info command in ~/bin/ and the manual file in the default location"
echo " ./install.sh --mandir=~/man/man1/ Installs the e4s-info command in the default location and the manual file in ~/man/man1"
echo " ./install.sh --prefix=~/bin/ --mandir=~/man/man1/ Installs the e4s-info command in ~/bin/ and the manual file in ~/man/man1/"
echo " sudo ./install.sh Installs the e4s-info command and manual files in the default locations, but uses sudo if permission was denied without sudo"
echo
echo "Exit Status:"
echo " 0 if okay"
echo " 1 if invalid arguments are passed"
echo " 2 if an invalid --prefix=foo or --mandir is passed"
echo " 3 if there is an error while making a directory or copying files"
echo
exit 0
}
ARGS=$*
PATHVAR=
MANPATHVAR=
while [ "$1" != "" ]; do
case $1 in
--prefix=*)
PATHVAR="$(echo "$1" | cut -c 10-)"
;;
--mandir=*)
MANPATHVAR="$(echo "$1" | cut -c 10-)"
;;
-h | --help)
help # run help function
;;
*)
# invalid option
argError
;;
esac
shift # remove the current value for `$1` and use the next
done
echo
echo "Checking command PATH..."
if [ -z "$PATHVAR" ]; then
echo "Setting command PATH to default (/usr/local/bin/)"
PATHVAR="/usr/local/bin/"
else
echo "Using specified command PATH"
PATHVAR1=$(dirname "$PATHVAR")
PATHVAR2=$(basename "$PATHVAR")
PATHVAR="${PATHVAR1}/${PATHVAR2}/bin/"
fi
echo
echo "Checking command MANPATH..."
if [ -z "$MANPATHVAR" ]; then
echo "Setting command MANPATH to default (/usr/local/share/man/man1/)"
MANPATHVAR="/usr/local/share/man/man1/"
else
echo "Using specified command MANPATH"
MANVAR1=$(dirname "$MANPATHVAR")
MANVAR2=$(basename "$MANPATHVAR")
MANPATHVAR="${MANVAR1}/${MANVAR2}/man/man1/"
fi
echo
echo "PATH for command will be set to: $PATHVAR"
echo "MANPATH for the manual page will be set to: $MANPATHVAR"
echo
echo "Copying e4s-info command to $PATHVAR"
mkdir -p "$PATHVAR"
CHECKRET=$?
[ $CHECKRET -eq 0 ] || { echo "Problems making directory: $PATHVAR. Either use \"sudo\" before command if permission was denied, check target directory for name collisions, or check the command \"mkdir\" error code: $CHECKRET"; echo; exit 3; }
echo "Directory either already exists or was created"
cp -r e4s-info-command/* "$PATHVAR"
CHECKRET=$?
[ $CHECKRET -eq 0 ] || { echo "Problems copying command. Either use \"sudo\" before command if permission was denied, check target directory for name collisions, or check the command \"cp\" error code: $CHECKRET"; echo; exit 3; }
echo "Successfully copied e4s-info command to $PATHVAR"
echo
echo "Copying e4s-info manual file to $MANPATHVAR"
mkdir -p "$MANPATHVAR"
CHECKRET=$?
[ $CHECKRET -eq 0 ] || { echo "Problems making directory $MANPATHVAR. Either use \"sudo\" before command if permission was denied, check target directory for name collisions, or check the command \"mkdir\" error code: $CHECKRET"; echo; exit 3; }
echo "Directory either already exists or was created"
cp e4s-info-manual/e4s-info.1.gz "$MANPATHVAR"
CHECKRET=$?
[ $CHECKRET -eq 0 ] || { echo "Problems copying manual file. Either use \"sudo\" before command if permission was denied, check target directory for name collisions, or check the command \"cp\" error code: $CHECKRET"; echo; rm -r "${PATHVAR}"; exit 3; }
echo
echo "Successfully installed \"e4s-info\" command and manual page."
echo
BASEMANPATH=$(dirname "$MANPATHVAR")
echo " export PATH=\$PATH:$PATHVAR"
echo " export MANPATH=\$MANPATH:$BASEMANPATH"
echo
exit 0