-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·125 lines (95 loc) · 3.21 KB
/
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
#!/bin/sh
TID_ARCH=""
TID_OS=""
TID_DIR="$HOME/.tid"
TID_BIN_DIR="$TID_DIR/bin"
TID_VERSION=""
prepareArch() {
TID_ARCH=$(uname -m)
case "$TID_ARCH" in
x86) TID_ARCH="386";;
x86_64) TID_ARCH="amd64";;
i686) TID_ARCH="386";;
i386) TID_ARCH="386";;
esac
}
prepareOS() {
TID_OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
case "$TID_OS" in
# Minimalist GNU for Windows
mingw*) TID_OS='windows';;
esac
}
prepareTidDir() {
if test ! -d "$TID_DIR"; then
mkdir -p "$TID_DIR"
fi
if test ! -d "$TID_BIN_DIR"; then
mkdir -p "$TID_BIN_DIR"
fi
}
prepareVersion() {
if type "curl" > /dev/null; then
TID_VERSION=$(curl -s https://raw.githubusercontent.com/SeerUK/tid/master/VERSION)
elif type "wget" > /dev/null; then
TID_VERSION=$(wget -q -O - https://raw.githubusercontent.com/SeerUK/tid/master/VERSION)
fi
}
installRelease() {
if test -z "$TID_ARCH"; then
echo "Sorry, we it looks like your system architecture is unsupported."
echo "You can always compile the Go source from https://github.com/SeerUK/tid though!"
exit 1
fi
if test -z "$TID_OS"; then
echo "Sorry, we it looks like your operating system is unsupported."
echo "You can always compile the Go source from https://github.com/SeerUK/tid though!"
exit 1
fi
BINARIES="tid tiddate"
for BINARY in ${BINARIES}; do
BINARY_RELEASE_URL="https://github.com/SeerUK/tid/releases/download/${TID_VERSION}/${BINARY}_${TID_OS}_${TID_ARCH}"
echo "Downloading $BINARY $TID_VERSION..."
BINARY_VERSION_DIR="${TID_BIN_DIR}-${TID_VERSION}"
BINARY_VERSION_FILE="$BINARY_VERSION_DIR/$BINARY"
if test "$TID_OS" = "windows"; then
BINARY_VERSION_FILE="$BINARY_VERSION_FILE.exe"
fi
mkdir -p "$BINARY_VERSION_DIR"
if type "curl" > /dev/null; then
curl -L "$BINARY_RELEASE_URL" -o "$BINARY_VERSION_FILE"
elif type "wget" > /dev/null; then
wget -q -O "$BINARY_VERSION_FILE" "$BINARY_RELEASE_URL"
fi
if test "$TID_OS" != "windows"; then
chmod +x "$BINARY_VERSION_FILE"
fi
echo "Linking $BINARY $TID_VERSION..."
ln -fs "$BINARY_VERSION_FILE" "$TID_BIN_DIR/${BINARY}"
done
echo ""
echo "Installed to '$TID_BIN_DIR'."
echo "This should be have automatically been added to your path."
echo "If it hasn't been, make sure you add it manually!"
}
installPath() {
BASH_LINE="export PATH=\"\$PATH:\$HOME/.tid/bin\""
FISH_LINE="set -gx PATH \$HOME/.tid/bin \$PATH"
ZSH_LINE="$BASH_LINE"
grep -qF "$BASH_LINE" "$HOME/.bashrc" ||
echo "$BASH_LINE" >> "$HOME/.bashrc"
grep -qF "$BASH_LINE" "$HOME/.profile" ||
echo "$BASH_LINE" >> "$HOME/.profile"
grep -qF "$FISH_LINE" "$HOME/.config/fish/config.fish" ||
echo "$FISH_LINE" >> "$HOME/.config/fish/config.fish"
grep -qF "$ZSH_LINE" "$HOME/.zshrc" ||
echo "$ZSH_LINE" >> "$HOME/.zshrc"
}
prepareArch
prepareOS
prepareTidDir
prepareVersion
installRelease
installPath
# @todo:
# Backup existing data (how do we know where the DB is? parse config for path?)