Skip to content

Commit 6744a50

Browse files
committed
lib
1 parent 2f30f2f commit 6744a50

File tree

7 files changed

+193
-2
lines changed

7 files changed

+193
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ If FlagDownloadHash is set and the user does not use the **--skip-checksum** par
314314

315315
The default implementation of AppsHash is to call `sha256sum "$1"` directly.
316316

317+
### AppsRequestHash
318+
319+
AppsRequestHash is optional and supported since v1.4.0.
320+
321+
If FlagDownloadHash is non-null, AppsRequestHash should request the hash value from the FlagDownloadHash address and write the value into the RequestHashValue variable.
322+
323+
The default AppsRequestHash will use the first string value of the response as a hash, you can refer to [v2fly.sh](https://github.com/powerpuffpenguin/github-apps/blob/main/bin/github-apps.configure /v2fly.sh) to implement the AppsRequestHash function.
324+
317325
### AppsUnpack
318326

319327
The first incoming parameter of AppsUnpack is the path of the downloaded installation package. You need to unpack the compressed package in this function to install the application to the path specified by **FlagInstallDir**.

README_zh.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ AppsHash 是可選實現的
315315

316316
AppsHash 的默認實現是直接調用 `sha256sum "$1"`
317317

318+
### AppsRequestHash
319+
320+
AppsRequestHash 是可選實現的,從 v1.4.0 開始被支持
321+
322+
如果 FlagDownloadHash 爲非空,則 AppsRequestHash 應該向 FlagDownloadHash 地址請求 hash 值,並將值寫入到 RequestHashValue 變量中。
323+
324+
默認的 AppsRequestHash 會將響應的第一個字符串值作爲 hash,你可以參考 [v2fly.sh](https://github.com/powerpuffpenguin/github-apps/blob/main/bin/github-apps.configure/v2fly.sh) 中的例子來實現 AppsRequestHash 函數
325+
318326
### AppsUnpack
319327

320328
AppsUnpack 的第一個傳入參數是下載的安裝包路徑,你需要在此函數中解開壓縮包將應用安裝到 **FlagInstallDir** 指定的路徑中去

bin/github-apps.configure/lib.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,15 @@ function lib_GithubSetUrl
272272
if [[ "$FlagVersion" != "" ]];then
273273
FlagUrlTag="https://api.github.com/repos/$owner_repo/releases/tags/$FlagVersion"
274274
fi
275+
}
276+
277+
# lib_CopyFile src dst
278+
# * $1 src
279+
# * $2 dst
280+
function lib_CopyFile
281+
{
282+
echo cp "\"$1\"" "\"$2\""
283+
if [[ "$FlagTest" == 0 ]];then
284+
cp "$1" "$2"
285+
fi
275286
}

bin/github-apps.configure/v2fly.sh

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,165 @@
1+
selfName=""
2+
selfService="/etc/systemd/system/v2fly.service"
3+
selfExt=""
14
function AppsPlatform
25
{
36
AppsBody="Project V is a set of network tools that helps you to build your own computer network. It secures your network connections and thus protects your privacy."
47

58
lib_Platform
9+
10+
# check os
11+
local os
12+
case $lib_OS in
13+
windows)
14+
selfExt=".exe"
15+
os=$lib_OS
16+
;;
17+
darwin|linux)
18+
selfExt=""
19+
os=$lib_OS
20+
;;
21+
*)
22+
FlagPlatformError="Not Supported: coredns on $lib_OS $lib_ARCH"
23+
return
24+
;;
25+
esac
26+
# check arch
27+
local arch
28+
case $lib_ARCH in
29+
amd64)
30+
arch=64
31+
;;
32+
*)
33+
FlagPlatformError="Not Supported: coredns on $lib_OS $lib_ARCH"
34+
return
35+
;;
36+
esac
37+
38+
# set install dir
39+
selfName="${os}-${arch}"
640
FlagInstallDir="/opt/v2fly"
41+
}
42+
function AppsSetUrl
43+
{
44+
lib_GithubSetUrl "v2fly/v2ray-core"
45+
}
46+
function AppsSetFile
47+
{
48+
local name="$1"
49+
local url="$2"
50+
if [[ "$name" == *$selfName.zip ]];then
51+
FlagDownloadFile=$url
52+
elif [[ "$name" == *$selfName.zip.dgst ]];then
53+
FlagDownloadHash=$url
54+
fi
55+
}
56+
function AppsRequestHash
57+
{
58+
if [[ "$FlagDownloadHash" == "" ]];then
59+
return
60+
fi
61+
echo curl -sL "$FlagDownloadHash"
62+
local hash=$(curl -sL "$FlagDownloadHash" | {
63+
while read line
64+
do
65+
if [[ $line == SHA256=* ]];then
66+
line=${line:7}
67+
echo $line
68+
fi
69+
done
70+
})
71+
RequestHashValue=$hash
72+
}
73+
function AppsVersion
74+
{
75+
# local app="$1"
76+
local version="$2"
77+
if [[ "$version" == "" ]];then
78+
local exe="$FlagInstallDir/v2ray$selfExt"
79+
if [[ -f "$exe" ]];then
80+
local str=$("$exe" -version )
81+
local tmp
82+
for tmp in $str
83+
do
84+
if [[ "$tmp" == "V2Ray" ]];then
85+
continue
86+
fi
87+
AppsVersionValue=v$tmp
88+
break
89+
done
90+
fi
91+
else
92+
echo write version "'$version'"
93+
fi
94+
}
95+
function AppsUnpack
96+
{
97+
lib_MkdirAll "$FlagInstallDir"
98+
local tmp="$Cache/v2flay.tmp"
99+
if [[ ! -d "$tmp" ]];then
100+
echo mkdir "$tmp"
101+
mkdir "$tmp"
102+
fi
103+
104+
echo unzip -o -d "$tmp" "$1"
105+
unzip -o -d "$tmp" "$1"
106+
107+
local name
108+
local items=(v2ray v2ctl)
109+
for name in "${items[@]}"
110+
do
111+
name="$name$selfExt"
112+
lib_CopyFile "$tmp/$name" "$FlagInstallDir/$name"
113+
done
114+
115+
items=(geosite.dat geoip.dat)
116+
for name in "${items[@]}"
117+
do
118+
lib_CopyFile "$tmp/$name" "$FlagInstallDir/$name"
119+
done
120+
121+
if [[ ! -f "$FlagInstallDir/config.json" ]];then
122+
lib_CopyFile "$tmp/config.json" "$FlagInstallDir/config.json"
123+
fi
124+
125+
# create service
126+
case $lib_OS in
127+
linux)
128+
lib_FirstFile "service" "$selfService" '[Unit]
129+
Description=V2Ray Service
130+
Documentation=https://www.v2fly.org/
131+
After=network.target nss-lookup.target
132+
133+
[Service]
134+
User=nobody
135+
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
136+
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
137+
NoNewPrivileges=true
138+
ExecStart=/opt/v2fly/v2ray -config /opt/v2fly/config.json
139+
Restart=on-failure
140+
RestartPreventExitStatus=23
141+
142+
[Install]
143+
WantedBy=multi-user.target'
144+
;;
145+
esac
146+
147+
echo rm "$tmp" -rf
148+
rm "$tmp" -rf
149+
}
150+
function AppsRemove
151+
{
152+
lib_DeleteFile "$FlagInstallDir/v2ray$selfExt"
153+
lib_DeleteFile "$FlagInstallDir/v2ctl$selfExt"
154+
if [[ "$FlagDeleteConf" != 0 ]];then
155+
lib_DeleteFile "$FlagInstallDir/config.json"
156+
fi
157+
if [[ "$FlagDeleteData" != 0 ]];then
158+
lib_DeleteFile "$FlagInstallDir/geosite.dat"
159+
lib_DeleteFile "$FlagInstallDir/geoip.dat"
160+
fi
161+
162+
lib_DeleteDir "$FlagInstallDir"
163+
164+
lib_DeleteFile "$selfService"
7165
}

src/github-apps.sh/109.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function installExecute
9090
fi
9191

9292
# get hash
93-
RequestHash
93+
AppsRequestHash
9494
local hash=$RequestHashValue
9595

9696
# download

src/github-apps.sh/119.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function upgradeExecute
6262
fi
6363

6464
# get hash
65-
RequestHash
65+
AppsRequestHash
6666
local hash=$RequestHashValue
6767

6868
# download

src/github-apps.sh/3.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,11 @@ function AppsRequestVersionList
5454
{
5555
RequestVersionList
5656
}
57+
# set download hash
58+
# RequestHashValue
59+
function AppsRequestHash
60+
{
61+
RequestHash
62+
}
5763
'
5864
}

0 commit comments

Comments
 (0)