This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathcopy.sh
executable file
·78 lines (64 loc) · 1.75 KB
/
copy.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
#!/bin/bash
c=${npm_package_config_couch}
if [ "$c" == "" ]; then
cat >&2 <<-ERR
Please set a valid 'npmjs.org:couch' npm config.
You can put PASSWORD in the setting somewhere to
have it prompt you for a password each time, so
it doesn't get dropped in your config file.
If you have PASSWORD in there, it'll also be read
from the PASSWORD environment variable, so you
can set it in the env and not have to enter it
each time.
ERR
exit 1
fi
case $c in
*PASSWORD*)
if [ "$PASSWORD" == "" ]; then
echo -n "Password: "
read -s PASSWORD
fi
;;
*);;
esac
c=${c/PASSWORD/$PASSWORD}
c=${c// /%20}
c="$(node -p 'process.argv[1].replace(/\/$/, "")' "$c")"
u="$(node -p 'require("url").resolve(process.argv[1], "_users")' "$c")"
if [ "$NO_PROMPT" == "" ]; then
echo "Did you already run the load-views.sh script? (type 'yes')"
read didLoad
if ! [ "$didLoad" == "yes" ]; then
echo "do that first."
exit 1
fi
fi
rev=$(curl -k "$c"/_design/app | json _rev)
if [ "$rev" != "" ]; then
rev="?rev=$rev"
fi
auth="$(node -pe 'require("url").parse(process.argv[1]).auth || ""' "$c")"
url="$(node -pe 'u=require("url");p=u.parse(process.argv[1]);delete p.auth;u.format(p)' "$c")"
if [ "$auth" != "" ]; then
auth=(-u "$auth")
fi
curl "$url/_design/scratch" \
"${auth[@]}" \
-k \
-X COPY \
-H destination:'_design/app'$rev
rev=$(curl -k "$u"/_design/_auth | json _rev)
if [ "$rev" != "" ]; then
rev="?rev=$rev"
fi
auth="$(node -pe 'require("url").parse(process.argv[1]).auth || ""' "$u")"
url="$(node -pe 'u=require("url");p=u.parse(process.argv[1]);delete p.auth;u.format(p)' "$u")"
if [ "$auth" != "" ]; then
auth=(-u "$auth")
fi
curl "$url/_design/scratch" \
"${auth[@]}" \
-k \
-X COPY \
-H destination:'_design/_auth'$rev