-
Notifications
You must be signed in to change notification settings - Fork 3
/
nuget.sh
160 lines (135 loc) · 3.72 KB
/
nuget.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
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
153
154
155
156
#!/bin/sh
# Author: Michael Goff <Michael.Goff@Quantum.com>
# Licence: MIT
# Copyright (c) 2015, Quantum Corp.
usage()
{
cat <<EOF
Usage:
$0 -h
$0 <command> [<command-args>]
Description:
Nuget commands setup for running in shippable
Commands:
commands
init
Description:
download nuget.exe and setup a fresh NuGet.config in the working directory.
addSource <name> <url> [<user> <apikey>]
Description:
Add a source [and set the apikey for it if user and apikey passed]
args:
name: The name of the source
url: The url for the source
user: the user for the source
apikey: the apikey for the source
restore
Description:
Restore the packages (download all referenced nuget packages)
pack <version> [<nuspec> ...]
Description:
Pack a nuspec file or files. If no nuspec passed it is assumed that *.nuspec should be packed
args:
version: The version to set for the nupkg
nuspec a nuspec to pack
push <source> [<nupkg> ...]
Description:
push a nupkg or packages. If no nupkg is passed it is assumed that *.nupkg should be pushed
args:
source: A nuget source to push to
nupkg - a nupkg file to push
EOF
}
while getopts ":h" opt
do
case "${opt}" in
h ) usage; exit 0 ;;
\?) echo "unrecognized option: $OPTARG" 1>&2
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ "$#" -lt 1 ]; then
echo "Invalid Params: Requires a command argument" 1>&2
usage
exit 1
fi
COMMAND=$1
shift
NUGET_CONFIG="./NuSpec.config"
case "$COMMAND" in
init)
if [ "$#" -ne 0 ]; then
echo "Invalid Params: restore takes no arguments" 1>&2
usage
exit 1
fi
cat > "$NUGET_CONFIG" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Official NuGet Gallery" value="https://www.nuget.org/api/v2/" />
</packageSources>
</configuration>
EOF
curl -LO http://nuget.org/nuget.exe
;;
addSource)
if [ "$#" -ne 2 ] && [ "$#" -ne 4 ]; then
echo "Invalid Params: Requires at least a name and url and optionally both a username and apikey" 1>&2
usage
exit 1
fi
NAME="$1"
SOURCE="$2"
MYGET_USER="$3"
MYGET_API_KEY="$4"
mono nuget.exe sources add -Name "$NAME" -Source "$SOURCE" -UserName "$MYGET_USER" -Password "$MYGET_API_KEY" -ConfigFile "$NUGET_CONFIG"
# Hide the apikey output during the run of this command by redirecting to /dev/null
mono nuget.exe setApiKey "$MYGET_API_KEY" -Source "$SOURCE" -ConfigFile "$NUGET_CONFIG" -NonInteractive 1>/dev/null
;;
restore)
if [ "$#" -ne 0 ]; then
echo "Invalid Params: restore takes no arguments" 1>&2
usage
exit 1
fi
rm -rf packages
mono nuget.exe restore -ConfigFile "$NUGET_CONFIG" -NonInteractive
;;
pack)
if [ "$#" -lt 1 ]; then
echo "Invalid Params: Requires a version" 1>&2
usage
exit 1
fi
VERSION="$1"
shift
nuspecs="${@}"
[ $# -eq 0 ] && nuspecs=*.nuspec
for nuspec in $nuspecs; do
echo "Packing $nuspec $VERSION"
TMP_FILE=`mktemp /tmp/XXXXXXXXXX`
NUSPEC="${TMP_FILE}.nuspec"
mv "$TMP_FILE" "$NUSPEC"
sed 's/\[VERSION\]/'"$VERSION"'/' "$nuspec" > "$NUSPEC"
mono nuget.exe pack "$NUSPEC" -BasePath .
done
;;
push)
if [ "$#" -ne 1 ]; then
echo "Invalid Params: push takes at least a source to push to" 1>&2
usage
exit 1
fi
SOURCE=$1
shift
nupkgs="${@}"
[ $# -eq 0 ] && nupkgs=*.nupkg
for nupkg in $nupkgs; do
echo "Pushing $nupkg"
mono nuget.exe push "$nupkg" -ConfigFile "$NUGET_CONFIG" -NonInteractive -Source "$SOURCE"
done
;;
esac