-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcotls-installer.sh
executable file
·75 lines (57 loc) · 2.16 KB
/
cotls-installer.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
#!/usr/bin/env bash
COTLS_ALIAS="cotls"
SYSTEM_COMPLETION_DIR="/etc/bash_completion.d/"
if [ -z "$INSTALL_PREFIX" ] ; then
INSTALL_PREFIX=~/
fi
if [ -z "$REPO_NAME" ] ; then
REPO_NAME=$COTLS_ALIAS
fi
if [ -z "$REPO_HOME" ] ; then
REPO_HOME="http://github.com/hansek/cotls.git"
fi
EXEC_FILES="cotls.sh"
echo "### COTLS installer ###"
echo ""
case "$1" in
help)
echo "Usage: [environment] install.sh [install|uninstall]"
echo "Environment:"
echo " INSTALL_PREFIX=$INSTALL_PREFIX"
echo " REPO_HOME=$REPO_HOME"
echo " REPO_NAME=$REPO_NAME"
exit
;;
*)
# echo "Installing COTLS to $INSTALL_PREFIX$REPO_NAME"
if [ -d "$INSTALL_PREFIX$REPO_NAME" -a -d "$INSTALL_PREFIX$REPO_NAME/.git" ] ; then
echo "Using existing repo: $INSTALL_PREFIX$REPO_NAME"
else
echo "Cloning repo from GitHub to $INSTALL_PREFIX$REPO_NAME"
git clone "$REPO_HOME" "$INSTALL_PREFIX$REPO_NAME"
fi
# for exec_file in $EXEC_FILES ; do
chmod +x "$INSTALL_PREFIX$REPO_NAME/$EXEC_FILES"
# done
if ! grep --quiet "$COTLS_ALIAS=" ~/.bashrc
then
echo -e "\nalias $COTLS_ALIAS='$INSTALL_PREFIX$REPO_NAME/$EXEC_FILES'" >> ~/.bashrc
fi
OLD_COMPLETION_FILE="$SYSTEM_COMPLETION_DIR$COTLS_ALIAS"
NEW_COMPLETION_FILE="$INSTALL_PREFIX$REPO_NAME/cotls_completion.sh"
$(cmp --silent "$OLD_COMPLETION_FILE" "$NEW_COMPLETION_FILE")
FILES_THE_SAME=$?
if [ -d "$SYSTEM_COMPLETION_DIR" ] && [ ! -f "$OLD_COMPLETION_FILE" -o "$FILES_THE_SAME" -ne 0 ]
then
echo "Installing BASH completion file to: $OLD_COMPLETION_FILE"
cp "$NEW_COMPLETION_FILE" "$OLD_COMPLETION_FILE"
fi
echo ""
echo "COTLS installed successfully"
echo "- You should reload .bashrc (execute \"source ~/.bashrc\") to alias will be active"
echo "- You should reload BASH completion file (execute \"source $OLD_COMPLETION_FILE\") to autocompletion work"
echo "- Voilà, use your new \"$COTLS_ALIAS\" command tool."
echo ""
exit
;;
esac