forked from yadm-dev/yadm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·88 lines (71 loc) · 2.07 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
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
CURRENT_DIR="$(pwd -P)"
CLONE_URL="https://git.envs.net/lfdev/yadm-install.git"
CLONE_DIR="${1:-${CURRENT_DIR}}"
BIN_DIR="${HOME}/bin"
MAN_DIR="${HOME}/.local/share/man/man1"
CREATE_DIR=false
is_app_installed() {
type "${1}" &>/dev/null
}
confirm_prompt() {
read -p "${1} (y/N)? " response
case "$response" in
[yY])
# comtinue
;;
*)
exit 0
;;
esac
}
transform_path() {
if [[ "$1" == "/"* ]]; then
printf "${1}/yadm"
else
printf "${CURRENT_DIR}/${1}/yadm"
fi
}
if ! is_app_installed git; then
printf "ERROR: \"git\" not found.\n"
printf " Please install it first.\n"
exit 1
fi
CLONE_DIR="$(transform_path ${CLONE_DIR})"
if [[ "${CLONE_DIR}" == "//yadm" ]]; then
printf "ERROR: \"yadm\" cannot be installed to the root directoty.\n"
printf " Please change directoty first or provide a destination path.\n"
exit 1
fi
if [ -e "${CLONE_DIR}" ]; then
printf "${CLONE_DIR} exists, it will cause an error if not empty.\n"
else
printf "${CLONE_DIR} does not exist, it will be created.\n"
CREATE_DIR=true
fi
confirm_prompt "Continue"
[ "${CREATE_DIR}" ] && mkdir -p "${CLONE_DIR}" || true
git clone --single-branch --branch master --depth=1 "${CLONE_URL}" "${CLONE_DIR}"
CREATE_DIR=false
if [ ! -e "${BIN_DIR}" ]; then
BIN_DIR="${HOME}/.local/bin"
CREATE_DIR=true
fi
[ "${CREATE_DIR}" ] && mkdir -p "${BIN_DIR}" || true
ln -sf "${CLONE_DIR}/yadm" "${BIN_DIR}/"
mkdir -p "${MAN_DIR}" && ln -sf "${CLONE_DIR}/yadm.1" "${MAN_DIR}/"
printf "\n"
printf "yadm executable was simlinked to ${BIN_DIR}\n"
printf "Make sure it is in the \$PATH.\n"
printf "\n"
confirm_prompt "Do you want to clone your dotfiles repo now"
printf "Please type the HTTPS or SSH repo address and press ENTER:\n"
read -p "> " dot_repo
[ ! -z "$dot_repo" ] && "${CLONE_DIR}"/yadm clone "${dot_repo}" || true
printf "\n"
printf "You may want to logout or source ${SHELL##*/} profile to apply any changes.\n"
printf "Done.\n"
printf "\n"