forked from dslzuha/MyRepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.node.sh
84 lines (70 loc) · 2.41 KB
/
script.node.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
#!/bin/bash
epoch_time=`date +%s`
# Set the target directory where .npmrc will be written by setting the $DIR
# environment variable prior to running this script.
#
# If $DIR is left unset, the script will default to writing an .npmrc in
# the current user's home directory.
#
# Alternatively, $DIR can be set to a specific directory so that the npmrc
# takes effect only for commands run in that directory.
set_write_dir () {
if [[ -z $DIR ]]; then
NPMRC_DEST_DIR=$HOME
elif [[ ! -d $DIR ]]; then
echo "${DIR} does not exist. You must specify an existing directory for .npmrc to be written."
exit 1
else
NPMRC_DEST_DIR=$DIR
fi
}
curl_check ()
{
echo "Checking for curl..."
if command -v curl > /dev/null; then
echo "Detected curl..."
else
echo "curl could not be found, please install curl and try again"
exit 1
fi
}
abort_if_npmrc_exists ()
{
if [[ ( -e ${NPMRC_DEST_DIR}/.npmrc ) && ( -z "${force_npm}" ) ]]; then
echo
echo "WARNING: your system already has an ${NPMRC_DEST_DIR}/.npmrc file"
echo " this script will now exit without doing anything!"
echo
echo "You can also specify an alternate directory where .npmrc will be written by setting"
echo "DIR and re-running the script (e.g., DIR=/var/code/project ./script.sh)"
echo
echo "If you want to use ${NPMRC_DEST_DIR} even though it has an .npmrc already, you should either"
echo "delete your existing ${NPMRC_DEST_DIR}/.npmrc or set force_npm=1 when running"
echo "this script!"
echo
exit 1
elif [[ ( -e ${NPMRC_DEST_DIR}/.npmrc ) ]]; then
echo "Existing ${NPMRC_DEST_DIR}/.npmrc file detected, but force_npm specified."
echo "Renaming your existing file to: ${NPMRC_DEST_DIR}/${epoch_time}.npmrc.bak."
mv ${NPMRC_DEST_DIR}/.npmrc ${NPMRC_DEST_DIR}/${epoch_time}.npmrc.bak
fi
}
generate_npmrc ()
{
echo "Generating ${NPMRC_DEST_DIR}/.npmrc..."
repo_url=https://packagecloud.io/dslzuha/MyRepo/npm/
echo "registry=${repo_url}" > ${NPMRC_DEST_DIR}/.npmrc
if [[ -z "$DIR" ]]; then
echo
echo "You didn't specify the environment variable DIR, so your .npmrc file was written to your home directory (${NPMRC_DEST_DIR})."
echo "If you want to create a project specific npmrc, you can re-run this script and set \$DIR to the directory where .npmrc should be written."
fi
}
main ()
{
curl_check
set_write_dir
abort_if_npmrc_exists
generate_npmrc
}
main