-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·129 lines (111 loc) · 3.95 KB
/
install
File metadata and controls
executable file
·129 lines (111 loc) · 3.95 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
127
128
129
#!/usr/bin/env sh
#Get installation directory
INSTALL_DIR="$HOME"
mkdir "$INSTALL_DIR/bin/" >> /dev/null 2>&1
#Read flags
while getopts 'uy' flag; do
case "${flag}" in
u) u_flag='true';;
y) y_flag='true';;
*) ;;
esac
done
#Warning that hoard is not being installed but rather updated. Can be overriden with the -y flag.
if [ -f "$INSTALL_DIR/bin/hoard" ]; then
if [ "$y_flag" != "true" ]; then
echo "We'll be updating the installation of hoard at $INSTALL_DIR/bin/hoard. [ctrl-c to cancel]"
sleep 2
else
echo "Updating installation of hoard at $INSTALL_DIR/bin/hoard."
fi
fi
#Attempts to pull updates from the hoard git repository. Can be disabled with the debug -d flag.
if [ "$u_flag" = "true" ]; then
echo "Pulling new updates from repository if necessary..."
cd `dirname "$0"`
git pull
$0 -y
exit $?
fi
#Install hoard by linking the hoard file here with the one in bin.
echo
echo "Performing installation..."
#Delete previous version
if [ -f "$INSTALL_DIR/bin/hoard" ]; then
rm $INSTALL_DIR/bin/hoard
fi
#Clear deprecated installation directory
if [ "`uname`" = "Darwin" ]; then
if [ -f "/usr/local/bin/hoard" ]; then
rm "/usr/local/bin/hoard"
fi
fi
#Install the script by hard-linking to the install directory.
(ln `dirname "$0"`/hoard $INSTALL_DIR/bin/hoard && echo "Installed 'hoard' at $INSTALL_DIR/bin/hoard") || (echo "Installation failure" && exit 1)
#Define and create a file at the user data file paths, if they're not already defined by the user.
if [ -z "$HOARD_SESSIONS_PATH" ]; then
export HOARD_SESSIONS_PATH="$HOME/.hoard_sessions"
fi
if [ -z "$HOARD_BOOKMARKS_PATH" ]; then
export HOARD_BOOKMARKS_PATH="$HOME/.hoard_bookmarks"
fi
touch "$HOARD_SESSIONS_PATH"
touch "$HOARD_BOOKMARKS_PATH"
#Get the user's shell profile path.
shell=`basename $SHELL`
file=
case $shell in
"bash")
if [ -f "$HOME/.bashrc" ]; then
file="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
file="$HOME/.bash_profile"
elif [ -f "$HOME/.profile" ]; then
file="$HOME/.profile"
fi
;;
"zsh")
file="$HOME/.zshrc"
;;
"ksh")
file="$HOME/.kshrc"
;;
esac
#Update with final changes.
if [ -z "$file" ]; then
#Inform the user about the need to source to be able to use it.
echo
echo "The shell you're using ($shell) is not tested, though as long as it is POSIX compliant it should work just fine."
echo
echo "Please add '. \"$INSTALL_DIR/bin/hoard\"' to your shell startup script to use the 'hoard' command directly on every new terminal session."
echo "Otherwise, you should run the hoard command '. \"$INSTALL_DIR/bin/hoard\"' to use the command 'hoard'."
else
#Include installation path in shell profile if necessary
installationPath=`echo $PATH | tr ":" "\n" | grep $HOME/bin`
if [ -z "$installationPath" ]; then
echo "export PATH=\$HOME/bin:\$PATH" >> "$file"
fi
#Update the user's bash profile to automatically source the file if it's found.
if [ "`uname`" = "Darwin" ]; then
sed -i '' "/\. .*hoard$/g" "$file"
sed -i '' "/^source .*hoard$/g" "$file"
else
sed -i "/\. .*hoard$/g" "$file"
sed -i "/^source .*hoard$/g" "$file"
fi
echo ". \"$INSTALL_DIR/bin/hoard\"" >> "$file"
echo
#Inform that the current session doesn't have the updated or installed hoard command yet.
if [ -z "$installationPath" ]; then
echo "Note that '$HOME/bin' is added to your PATH as it was not present."
echo "You'll need to run 'source $file' or restart your $shell session to use 'hoard'."
else
echo "Note that you may need to restart your $shell session"
echo "or run '. \"$INSTALL_DIR/bin/hoard\"' in order to use the 'hoard' command immediately."
fi
fi
#Yay, we're done! ^-^
echo
echo "Check README.md for configuration info."
echo
echo "Installation complete!"