-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·79 lines (57 loc) · 2.35 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
#!/usr/bin/env bash
{ # this ensures the entire script is downloaded
# exit if anything fails
set -e
# setup some formatting vars
term=${TERM:-"dumb"}
green=$(tput -T$term setaf 10)
yellow=$(tput -T$term setaf 11)
blue=$(tput -T$term setaf 12)
white=$(tput -T$term setaf 15)
gray=$(tput -T$term setaf 8)
bold=$(tput -T$term bold)
normal=$(tput -T$term sgr0)
# retrieve the latest version number
latestVersion="$(curl -s https://api.github.com/repos/simbo/rm-node_modules/releases/latest | grep "tag_name" | cut -d '"' -f 4)"
# inform about installation
printf "\nInstalling ${yellow}rm-node_modules $latestVersion${normal} to ${blue}$HOME/bin${normal}...\n"
# ask for confirmation
printf "\nPress ${white}${bold}[ENTER] to continue${normal} or anything else to cancel.\n"
IFS= read -s -n 1 key
# exit if not confirmed
if [[ $key != "" ]]; then
printf "\n${gray}Aborted.${normal}\n"
exit 0
fi
# ensure ~/bin directory exists
mkdir -p $HOME/bin
# change to ~/bin directory
cd $HOME/bin
# remove existing version and symlink
rm -f ./rm-node_modules
rm -f ./rmnm
# inform about downloading
printf "\n${gray}Downloading...${normal}\n"
# download latest version
curl -s https://raw.githubusercontent.com/simbo/rm-node_modules/$latestVersion/rm-node_modules -o ./rm-node_modules
# make script executable
chmod +x ./rm-node_modules
# inform about linking
printf "${gray}Linking...${normal}\n"
# create symlink
ln -s ./rm-node_modules rmnm
# ensure ~/bin is within PATH
export PATH="$HOME/bin:$PATH"
# inform about status
printf "${gray}Done.${normal}\n"
printf "\n${green}Successfully installed ${bold}rm-node_modules $latestVersion${normal}${green}.${normal}\n"
# inform about PATH
printf "\nIf $HOME/bin is not within your PATH by default, add this line to your shell profile:\n"
printf "\n ${white}${bold}export PATH=\"\$HOME/bin:\$PATH\"${normal}\n"
# inform about execution
printf "\nRun the script using ${yellow}${bold}rm-node_modules${normal} or ${yellow}${bold}rmnm${normal}.\n"
# inform about usage
printf "\nRun ${yellow}${bold}rmnm -h${normal} to display usage information.\n"
# inform about configuration
printf "\nYou may want to configure your default base directory using ${yellow}${bold}rmnm -c <DIR>${normal}.\n"
} # this ensures the entire script is downloaded