-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
install
executable file
·152 lines (129 loc) · 4.32 KB
/
install
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/env sh
# Script for installing ugit (git undo)
#
# This script can be executed via
# curl:
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/Bhupesh-V/ugit/master/install)"
# or wget:
# sh -c "$(wget -qO- https://raw.githubusercontent.com/Bhupesh-V/ugit/master/install)"
# or httpie:
# sh -c "$(http --download https://raw.githubusercontent.com/Bhupesh-V/ugit/master/install)"
status_check() {
if command -v ugit 2>&1 > /dev/null; then
printf "\n\t%s\n" "You already have ${BOLD}ugit${RESET} installed."
printf "\n\t%s\n" "Run ${BOLD}git undo${RESET} everytime you make a git mistake :)"
exit 0
fi
}
installed() {
cmd=$(command -v "${1}")
return ${?}
}
die() {
>&2 echo "Fatal: $*"
exit 1
}
# TODO
# check if correct version of fzf is there
# check if correct version of git is there
# check if correct version of bash is there
check_dependencies() {
if ! command -v git > /dev/null 2>&1; then
printf "\n%s\n" "${BOLD}Can't work without git 😞. Please install git version >=2.30.0${RESET}"
exit 1
fi
if ! command -v fzf > /dev/null 2>&1; then
printf "\n%s\n" "${BOLD}Can't work without fzf 😞. Please install fzf version >=0.21.0${RESET}"
exit 1
fi
if ! command -v bash > /dev/null 2>&1; then
printf "\n%s\n" "${BOLD}Can't work without bash 😞. Please install bash version >=4${RESET}"
exit 1
fi
DEPS=""
DEPS="${DEPS} awk"
DEPS="${DEPS} xargs"
DEPS="${DEPS} cut"
DEPS="${DEPS} nl"
DEPS="${DEPS} tr"
for DEP in ${DEPS}; do
installed ${DEP} || die "Missing GNU Utility: '${DEP}'"
done
}
set_permissions(){
if [ -f ugit ] && ! chmod +x ugit; then
printf "\n%s\n" "Unknown error while installing ugit"
exit 1
fi
move_to_path
}
move_to_path(){
printf "%s\n" "We require some permissions to move ugit to /usr/bin"
if sudo mv ugit /usr/bin; then
sudo ln -s ugit /usr/bin/git-undo
else
printf "\n%s\n" "Unknown error while installing ugit"
exit 1
fi
}
download_ugit(){
UGIT_HOST="https://github.com/Bhupesh-V/ugit/releases/latest/download/ugit"
printf "\n%s\n" "Downloading ugit from ${BOLD}$UGIT_HOST${RESET} ..."
if curl -fsSL $UGIT_HOST -o ugit; then
set_permissions
else
printf "\n%s\n" "Unknown error while downloading ugit"
exit 1
fi
}
config_check() {
reflogExpire=$(git config --get gc.reflogExpire)
if [ "$reflogExpire" = "" ] ; then
printf "%s\n" "Setting ${BOLD}gc.reflogExpire${RESET} to 200 days"
if ! git config --global gc.reflogExpire 200; then
printf "%s\n" "Unexpected error while setting up gitconfig"
exit 1
fi
elif [ "$reflogExpire" -lt 200 ]; then
printf "%s\n" "ugit recommends increasing ${BOLD}gc.reflogExpire${RESET} config duration to 200 days."
fi
reflogExpireUnreachable=$(git config --get gc.reflogExpireUnreachable)
if [ "$reflogExpireUnreachable" = "" ]; then
printf "%s\n" "Setting ${BOLD}gc.reflogExpireUnreachable${RESET} to 90 days"
if ! git config --global gc.reflogExpireUnreachable 90; then
printf "%s\n" "Unexpected error while setting up gitconfig"
exit 1
fi
elif [ "$reflogExpireUnreachable" -lt 90 ]; then
printf "%s\n" "ugit recommends increasing ${BOLD}gc.reflogExpireUnreachable${RESET} config duration to 90 days."
fi
}
main () {
status_check
check_dependencies
download_ugit
config_check
printf "${BOLD}${ORANGE_FG}%s\n" ""
printf "%s\n" " _ _ "
printf "%s\n" " _ _ __ _(_| |_ "
printf "%s\n" "| | | |/ _\` | | __| "
printf "%s\n" "| |_| | (_| | | |_ "
printf "%s\n" " \__,_|\__, |_|\__| "
printf "%s\n" " |___/ "
printf "${RESET}\n%s" ""
printf "\t\t%s\n" ".... is now installed 👍"
printf "\n%s" "Run ${BOLD}ugit --help${RESET} for any help & assistance"
printf "\n%s\n" "Use ${BOLD}${ORANGE_FG}git undo${RESET} or ${BOLD}${ORANGE_FG}ugit${RESET} everytime you make a git mistake :)"
}
# check if tput exists
if ! command -v tput > /dev/null 2>&1; then
# tput could not be found :(
BOLD=""
RESET=""
ORANGE_FG=""
else
BOLD=$(tput bold)
RESET=$(tput sgr0)
ORANGE_FG=$(tput setaf 208)
fi
main