-
Notifications
You must be signed in to change notification settings - Fork 310
/
install.sh
executable file
·56 lines (47 loc) · 1.53 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
#!/usr/bin/env bash
PKG="m-cli"
GIT_URL="https://github.com/rgcr/m-cli.git"
INSTALL_DIR="${INSTALL_DIR}"
has(){
type "$1" > /dev/null 2>&1
}
install_from_git(){
[ -z "${INSTALL_DIR}" ] && INSTALL_DIR="/usr/local/${PKG}"
if [ -e "${INSTALL_DIR}" ]; then
echo "${PKG} Is already installed"
echo "Updating ${PKG} from git"
command git --git-dir="${INSTALL_DIR}/.git" --work-tree="${INSTALL_DIR}" fetch --depth=1 || {
echo >&2 "Failed to fetch changes => ${GIT_URL}"
exit 1
}
command git --git-dir="${INSTALL_DIR}/.git" --work-tree="${INSTALL_DIR}" reset --hard origin/master || {
echo >&2 "Failed to reset changes => ${GIT_URL}"
exit 1
}
else
echo "Downloading ${PKG} from git to ${INSTALL_DIR}"
command git clone --depth 1 ${GIT_URL} ${INSTALL_DIR} || {
echo >&2 "Failed to clone => ${GIT_URL}"
exit 1
}
sudo ln -sf ${INSTALL_DIR}/plugins/itunes ${INSTALL_DIR}/plugins/music
chmod -R 755 ${INSTALL_DIR}/plugins 2>/dev/null
chmod 755 ${INSTALL_DIR}/m 2>/dev/null
sudo ln -sf ${INSTALL_DIR}/m /usr/local/bin/m
fi
}
if has "git"; then
install_from_git;
else
echo >&2 "Failed to install, please install git before."
fi
[ -z "${INSTALL_DIR}" ] && INSTALL_DIR="/usr/local/${PKG}"
if [ -f "${INSTALL_DIR}/m" ]; then
echo ""
echo "Done!"
else
echo >&2 ""
echo >&2 "Something went wrong. ${INSTALL_DIR}/m not found"
echo >&2 ""
exit 1
fi