Skip to content

Commit

Permalink
feat: install.sh和简单的readme
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Oct 6, 2023
1 parent 69f7f7a commit 2537d3b
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 13 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,25 @@
![](https://img.shields.io/github/stars/scriptscat/cloudcat.svg)![](https://img.shields.io/github/v/tag/scriptscat/cloudcat.svg?label=version&sort=semver)

## 需要环境
## 安装

### linux

```bash
curl -sSL https://github.com/scriptscat/cloudcat/raw/main/deploy/install.sh | sudo bash
```

## 使用

```bash
# 查看帮助
ccatctl -h
# 安装脚本
ccatctl install -f example/bing\ check-in.js
# 查看脚本列表
ccatctl get script
# 导入cookie/value(storage name)
ccatctl import cookie 6a0bd33 example/cookie.json
# 运行脚本(脚本id)
ccatctl run 6a0bd33
```
84 changes: 84 additions & 0 deletions deploy/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

# 根据是否有--prerelease参数来获取对应的版本信息
get_release_url() {
if [[ $1 == "--prerelease" ]]; then
curl --silent "https://api.github.com/repos/scriptscat/cloudcat/releases" |
grep "browser_download_url" |
sed -E 's/.*"([^"]+)".*/\1/' | head -n 1
else
curl --silent "https://api.github.com/repos/scriptscat/cloudcat/releases/latest" |
grep "browser_download_url" |
sed -E 's/.*"([^"]+)".*/\1/'
fi
}

detect_os_and_arch() {
OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

case $ARCH in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
armv*) ARCH="arm" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac

echo "Detected OS: $OS and ARCH: $ARCH"
}

download_and_extract_binary() {
local release_url="$1"

detect_os_and_arch

binary_url=$(echo $release_url | grep "$OS-$ARCH.tar.gz")

if [ -z "$binary_url" ]; then
echo "Binary not found for $OS-$ARCH"
exit 1
fi

echo "Downloading $binary_url..."
curl -L -o cloudcat.tar.gz "$binary_url"

mkdir -p /usr/local/cloudcat
tar xzf cloudcat.tar.gz -C /usr/local/cloudcat
ln -sf /usr/local/cloudcat/ccatctl /usr/local/bin/ccatctl
chmod +x /usr/local/cloudcat/*
}

install_as_service() {
if [ -f /etc/systemd/system/cloudcat.service ]; then
echo "CloudCat service already exists. Overwriting..."
fi

cat > /etc/systemd/system/cloudcat.service <<EOL
[Unit]
Description=CloudCat Service
After=network.target
[Service]
ExecStart=/usr/local/cloudcat/cloudcat
Restart=always
User=root
Group=root
Environment=PATH=/usr/bin:/usr/local/bin
[Install]
WantedBy=multi-user.target
EOL

systemctl daemon-reload
systemctl enable cloudcat
systemctl start cloudcat
echo "CloudCat service started!"
}

main() {
release_url=$(get_release_url $1)
download_and_extract_binary "$release_url"
install_as_service
}

main $1
34 changes: 22 additions & 12 deletions example/bing check-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,28 @@ function searchKeyword() {
let retryNum = 0;
let lastProcess = 0;
let domain = "www.bing.com";
let firstReq = true;


function handler() {
const onload = (resp) => {
const url = new URL(resp.finalUrl);
if (url.host != domain) {
domain = url.host;
}
if (firstReq) {
firstReq = false;
// 处理一下cookie问题
let ig = getSubstring(resp.responseText, "_IG=\"", "\"");
let iid = getSubstring(resp.responseText, "_iid=\"", "\"");
GM_xmlhttpRequest({
url: "https://" + domain + "/rewardsapp/ncheader?ver=39980043&IID=" + iid + "&IG=" + ig
});
GM_xmlhttpRequest({
url: "https://" + domain + "/rewardsapp/reportActivity?IG=" + ig + "&IID=" + iid + "&&src=hp",
});
}
}
return getRewardsInfo().then(async resp => {
// 获取今日已获取积分
const data = resp.responseText;
Expand All @@ -168,12 +188,7 @@ function handler() {
// 进行一次手机搜索
GM_xmlhttpRequest({
url: "https://" + domain + "/search?q=" + await searchKeyword(),
onload(resp) {
const url = new URL(resp.finalUrl);
if (url.host != domain) {
domain = url.host;
}
},
onload: onload,
headers: {
"User-Agent": getMobileUA()
}
Expand All @@ -195,12 +210,7 @@ function handler() {
// 进行一次搜索
GM_xmlhttpRequest({
url: "https://" + domain + "/search?q=" + await searchKeyword(),
onload(resp) {
const url = new URL(resp.finalUrl);
if (url.host != domain) {
domain = url.host;
}
}
onload: onload,
});
return false;
}
Expand Down

0 comments on commit 2537d3b

Please sign in to comment.