-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmirror-maven-fn
168 lines (132 loc) · 3.83 KB
/
mirror-maven-fn
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
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# Author: Cangsheng Sheng
# Email: shencangsheng@126.com
# Created: 2024-06-10
# Version: 1.0
source ./tools
function mirror_maven_install() {
echo '' >.env
if contains_args "--magic"; then
if [ ! -f "$_PWD/magic/.env" ]; then
Error "Need to install magic. exec: ./ctl magic hlep"
exit 1
fi
source $_PWD/magic/.env
cat <<EOF >.env
MAGIC_ENABLE="TRUE"
MAGIC_USERNAME="$MAGIC_USERNAME"
MAGIC_PASSWORD="$MAGIC_PASSWORD"
EOF
fi
docker compose up -d
cat <<EOF
http address - http://0.0.0.0:18081/
EOF
}
function mirror_maven_uninstall() {
docker compose down
}
function mirror_maven_help() {
cat <<EOF
Usage: ./ctl maven [OPTION...]
Examples:
./ctl maven install # Install Maven registry
./ctl maven install --magic # Install Maven registry, enable proxy
./ctl maven uninstall # Uninstall Maven registry
./ctl maven join # Show using registry
./ctl maven magic # Configuration magic, @deprecated
./ctl maven status # Show Maven status
./ctl maven clean # Clean out
./ctl maven user # Show registry default user
./ctl maven start # Start
./ctl maven stop # Stop
./ctl maven restart # Restart
EOF
}
function mirror_maven_join() {
local content=$(
cat <<EOF
Methods to Set Custom Registry
Options:
1. pom.xml
<repositories>
$_GREEN
<repository>
<id>private-nexus</id>
<url>http://xx.xx.xx.xx:18081/repository/maven-public/</url>
</repository>
$_NC
</repositories>
2. settings.xml
<mirrors>
$_GREEN
<mirror>
<id>Nexus</id>
<name>Nexus</name>
<mirrorOf>central</mirrorOf>
<url>http://xx.xx.xx.xx:18081/repository/maven-public/</url>
</mirror>
$_NC
</mirrors>
EOF
)
echo -e "$content"
}
function mirror_maven_magic() {
local content=$(
cat <<EOF
作者已经找到安装部署时自动配置代理的方法,如果之前已经安装了并且未开启代理,则可以使用此方法手动配置;
step-1:
访问 http://xx.xx.xx.xx:18081
step-2:
右上角: ${_GREEN}Sign in${_NC}
账号:admin
密码:执行 ${_GREEN}docker exec -it mirror-maven-maven-registry-1 sh -c "cat /nexus-data/admin.password"${_NC} 来获取
step-3:
左上角: ${_GREEN}Config${_NC}
step-4:
System -> HTTP -> Proxy Settings
step-5:
配置 Host 与 Authentication
HTTP Proxy Host: magic
HTTP Proxy Port: 7890
HTTP Authentication Username: user
HTTP Authentication Password: 执行 ${_GREEN}./ctl magic auth ${_NC}来获取
HTTPS Proxy Host: magic
HTTPS Proxy Port: 7890
HTTPS Authentication Username: user
HTTPS Authentication Password: 执行 ${_GREEN}./ctl magic auth ${_NC}来获取
EOF
)
echo -e "$content"
}
function mirror_maven_status() {
local content=$(
cat <<EOF
● maven.service
$(get_service_status)
EOF
)
echo -e "$content"
}
function mirror_maven_clean() {
mirror_maven_uninstall
del_docker_vol 'mirror-maven-vol'
}
function mirror_maven_user() {
local password=$(docker compose exec maven-registry sh -c 'cat /nexus-data/admin.password || echo "默认密码已被更改"')
cat <<EOF
user: admin
password: $password
EOF
}
function mirror_maven_stop() {
docker compose down
}
function mirror_maven_start() {
docker compose up -d
}
function mirror_maven_restart() {
mirror_maven_stop
mirror_maven_start
}