Skip to content

Commit 2537d3b

Browse files
committed
feat: install.sh和简单的readme
1 parent 69f7f7a commit 2537d3b

File tree

3 files changed

+128
-13
lines changed

3 files changed

+128
-13
lines changed

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,25 @@
44
55
![](https://img.shields.io/github/stars/scriptscat/cloudcat.svg)![](https://img.shields.io/github/v/tag/scriptscat/cloudcat.svg?label=version&sort=semver)
66

7-
## 需要环境
7+
## 安装
8+
9+
### linux
10+
11+
```bash
12+
curl -sSL https://github.com/scriptscat/cloudcat/raw/main/deploy/install.sh | sudo bash
13+
```
14+
15+
## 使用
16+
17+
```bash
18+
# 查看帮助
19+
ccatctl -h
20+
# 安装脚本
21+
ccatctl install -f example/bing\ check-in.js
22+
# 查看脚本列表
23+
ccatctl get script
24+
# 导入cookie/value(storage name)
25+
ccatctl import cookie 6a0bd33 example/cookie.json
26+
# 运行脚本(脚本id)
27+
ccatctl run 6a0bd33
28+
```

deploy/install.sh

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
3+
# 根据是否有--prerelease参数来获取对应的版本信息
4+
get_release_url() {
5+
if [[ $1 == "--prerelease" ]]; then
6+
curl --silent "https://api.github.com/repos/scriptscat/cloudcat/releases" |
7+
grep "browser_download_url" |
8+
sed -E 's/.*"([^"]+)".*/\1/' | head -n 1
9+
else
10+
curl --silent "https://api.github.com/repos/scriptscat/cloudcat/releases/latest" |
11+
grep "browser_download_url" |
12+
sed -E 's/.*"([^"]+)".*/\1/'
13+
fi
14+
}
15+
16+
detect_os_and_arch() {
17+
OS=$(uname | tr '[:upper:]' '[:lower:]')
18+
ARCH=$(uname -m)
19+
20+
case $ARCH in
21+
x86_64) ARCH="amd64" ;;
22+
aarch64) ARCH="arm64" ;;
23+
armv*) ARCH="arm" ;;
24+
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
25+
esac
26+
27+
echo "Detected OS: $OS and ARCH: $ARCH"
28+
}
29+
30+
download_and_extract_binary() {
31+
local release_url="$1"
32+
33+
detect_os_and_arch
34+
35+
binary_url=$(echo $release_url | grep "$OS-$ARCH.tar.gz")
36+
37+
if [ -z "$binary_url" ]; then
38+
echo "Binary not found for $OS-$ARCH"
39+
exit 1
40+
fi
41+
42+
echo "Downloading $binary_url..."
43+
curl -L -o cloudcat.tar.gz "$binary_url"
44+
45+
mkdir -p /usr/local/cloudcat
46+
tar xzf cloudcat.tar.gz -C /usr/local/cloudcat
47+
ln -sf /usr/local/cloudcat/ccatctl /usr/local/bin/ccatctl
48+
chmod +x /usr/local/cloudcat/*
49+
}
50+
51+
install_as_service() {
52+
if [ -f /etc/systemd/system/cloudcat.service ]; then
53+
echo "CloudCat service already exists. Overwriting..."
54+
fi
55+
56+
cat > /etc/systemd/system/cloudcat.service <<EOL
57+
[Unit]
58+
Description=CloudCat Service
59+
After=network.target
60+
61+
[Service]
62+
ExecStart=/usr/local/cloudcat/cloudcat
63+
Restart=always
64+
User=root
65+
Group=root
66+
Environment=PATH=/usr/bin:/usr/local/bin
67+
68+
[Install]
69+
WantedBy=multi-user.target
70+
EOL
71+
72+
systemctl daemon-reload
73+
systemctl enable cloudcat
74+
systemctl start cloudcat
75+
echo "CloudCat service started!"
76+
}
77+
78+
main() {
79+
release_url=$(get_release_url $1)
80+
download_and_extract_binary "$release_url"
81+
install_as_service
82+
}
83+
84+
main $1

example/bing check-in.js

+22-12
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,28 @@ function searchKeyword() {
144144
let retryNum = 0;
145145
let lastProcess = 0;
146146
let domain = "www.bing.com";
147+
let firstReq = true;
148+
147149

148150
function handler() {
151+
const onload = (resp) => {
152+
const url = new URL(resp.finalUrl);
153+
if (url.host != domain) {
154+
domain = url.host;
155+
}
156+
if (firstReq) {
157+
firstReq = false;
158+
// 处理一下cookie问题
159+
let ig = getSubstring(resp.responseText, "_IG=\"", "\"");
160+
let iid = getSubstring(resp.responseText, "_iid=\"", "\"");
161+
GM_xmlhttpRequest({
162+
url: "https://" + domain + "/rewardsapp/ncheader?ver=39980043&IID=" + iid + "&IG=" + ig
163+
});
164+
GM_xmlhttpRequest({
165+
url: "https://" + domain + "/rewardsapp/reportActivity?IG=" + ig + "&IID=" + iid + "&&src=hp",
166+
});
167+
}
168+
}
149169
return getRewardsInfo().then(async resp => {
150170
// 获取今日已获取积分
151171
const data = resp.responseText;
@@ -168,12 +188,7 @@ function handler() {
168188
// 进行一次手机搜索
169189
GM_xmlhttpRequest({
170190
url: "https://" + domain + "/search?q=" + await searchKeyword(),
171-
onload(resp) {
172-
const url = new URL(resp.finalUrl);
173-
if (url.host != domain) {
174-
domain = url.host;
175-
}
176-
},
191+
onload: onload,
177192
headers: {
178193
"User-Agent": getMobileUA()
179194
}
@@ -195,12 +210,7 @@ function handler() {
195210
// 进行一次搜索
196211
GM_xmlhttpRequest({
197212
url: "https://" + domain + "/search?q=" + await searchKeyword(),
198-
onload(resp) {
199-
const url = new URL(resp.finalUrl);
200-
if (url.host != domain) {
201-
domain = url.host;
202-
}
203-
}
213+
onload: onload,
204214
});
205215
return false;
206216
}

0 commit comments

Comments
 (0)