Skip to content

Commit ca8d1ca

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 0bfe1bd + 0fbd7fc commit ca8d1ca

File tree

12 files changed

+263
-69
lines changed

12 files changed

+263
-69
lines changed

.github/workflows/manual.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ jobs:
3939
- name: Checkout repository
4040
uses: actions/checkout@v4
4141

42+
- name: Tune dpkg
43+
uses: abbbi/github-actions-tune@v1
44+
45+
- name: Set dpkg
46+
run: sudo rm -f /usr/local/bin/dpkg
47+
48+
- name: Tune apt
49+
uses: firebuild/apt-eatmydata-action@v1
50+
4251
- name: Check for release
4352
id: release
4453
continue-on-error: true
@@ -48,6 +57,7 @@ jobs:
4857

4958
- name: Fetch all data
5059
if: ${{ steps.release.outcome == 'success' }}
60+
continue-on-error: true
5161
uses: robinraju/release-downloader@v1
5262
with:
5363
latest: true
@@ -60,11 +70,11 @@ jobs:
6070
run: |
6171
docker run -v $PWD:/app --env-file <(env | grep GITHUB) \
6272
ghcr.io/$GITHUB_OWNER/$GITHUB_REPO:master \
63-
bash src/test/update.sh; echo "updated=$?" >> "$GITHUB_OUTPUT"
73+
src/test/update.sh; echo "updated=$?" >> "$GITHUB_OUTPUT"
6474
6575
- name: Get date
6676
id: date
67-
run: echo "tag=$(date -u +%-Y.%-m).$((($(date -u +%-d)-1)/7))" >> "$GITHUB_OUTPUT"
77+
run: echo "tag=$(date -u +%-Y.%-m).$((($(date -u +%-d)-1)/14))" >> "$GITHUB_OUTPUT"
6878

6979
- name: Save database
7080
if: ${{ steps.update.outputs.updated == '0' }}

.github/workflows/publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: build
22

33
on:
4+
workflow_dispatch:
5+
46
push:
57
branches:
68
- master

.github/workflows/update.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ jobs:
3131
- name: Checkout repository
3232
uses: actions/checkout@v4
3333

34+
- name: Tune dpkg
35+
uses: abbbi/github-actions-tune@v1
36+
37+
- name: Set dpkg
38+
run: sudo rm -f /usr/local/bin/dpkg
39+
40+
- name: Tune apt
41+
uses: firebuild/apt-eatmydata-action@v1
42+
3443
- name: Check for release
3544
id: release
3645
continue-on-error: true
@@ -40,6 +49,7 @@ jobs:
4049

4150
- name: Fetch all data
4251
if: ${{ steps.release.outcome == 'success' }}
52+
continue-on-error: true
4353
uses: robinraju/release-downloader@v1
4454
with:
4555
latest: true
@@ -52,11 +62,11 @@ jobs:
5262
run: |
5363
docker run -v $PWD:/app --env-file <(env | grep GITHUB) \
5464
ghcr.io/ipitio/backage:master \
55-
bash src/test/update.sh; echo "updated=$?" >> "$GITHUB_OUTPUT"
65+
src/test/update.sh; echo "updated=$?" >> "$GITHUB_OUTPUT"
5666
5767
- name: Get date
5868
id: date
59-
run: echo "tag=$(date -u +%-Y.%-m).$((($(date -u +%-d)-1)/7))" >> "$GITHUB_OUTPUT"
69+
run: echo "tag=$(date -u +%-Y.%-m).$((($(date -u +%-d)-1)/14))" >> "$GITHUB_OUTPUT"
6070

6171
- name: Save database
6272
if: ${{ steps.update.outputs.updated == '0' }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FROM ubuntu:22.04
22
WORKDIR /app
3-
COPY src src
3+
COPY . .
44
RUN cd src && bash bkg.sh

README.md

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,84 @@ If this is [`ipitio/backage`](https://github.com/ipitio/backage), all you have t
2020

2121
Otherwise, if this is a fork, you'd prefer an alternative method, or your packages weren't added to the [index](https://github.com/pkgforge-dev/backage/tree/index) after a day, enter the case-sensitive name of each missing user or organization on a new line at the top of `owners.txt` [here](https://github.com/pkgforge-dev/backage/edit/master/owners.txt) and make a pull request. Please submit just the name(s) -- ids, repos, and packages will be found automatically!
2222

23-
New packages won't be added until *all* existing ones are refreshed; you should also create an independent instance that'll update faster and more frequently, up to hourly. Simply fork just the `master` branch, enable Actions from its tab and all disabled workflows, and use the [Alternative URL](#alternative-url) when it changes. Your own packages will be picked up automatically! If you need to edit `owners.txt`, do so after the first run. This centralized repo will then serve as a backup for all subsets of packages not in `optout.txt`.
23+
Otherwise, if this is a fork, you'd prefer an alternative method, or your packages weren't added to the [index](https://github.com/ipitio/backage/tree/index) after a day, enter the case-sensitive name of each missing user or organization on a new line at the top of `owners.txt` [here](https://github.com/ipitio/backage/edit/master/owners.txt) and make a pull request. Don't worry -- while my Contribution Graph is an uptime monitor of sorts, yours won't be. See the top of `bkg.sh` for details about available options, which must come last when passed to `update.sh`, as shown in `Self-Host`.
24+
25+
> [!TIP]
26+
> You only need to add the name(s), IDs are fetched as needed.
27+
28+
New packages won't be added until *all* existing ones are refreshed; you should also create an independent instance that'll update faster and more frequently. Simply fork just the `master` branch, choose one of the following options, and use the [Alternative URL](#alternative-url) when it changes. This centralized repo will then serve as a backup for all subsets of packages not in `optout.txt`.
29+
30+
> [!IMPORTANT]
31+
> Your own packages will be picked up automatically! If you need to edit `owners.txt`, do so after the first run.
32+
33+
<details>
34+
<summary>With Actions</summary>
35+
36+
This will use a lot of minutes on GitHub-hosted runners, so you may want to use your own.
37+
38+
1. Enable Actions from its tab
39+
2. Enable all disabled workflows
40+
41+
</details>
42+
43+
<details>
44+
<summary>Self-Host</summary>
45+
46+
This is an example for `systemd`; adapt it to your needs. Please note:
47+
48+
- Docker needs to be installed
49+
- You don't need to set `GITHUB_TOKEN` if you're logged in with `gh` or you'll first use your PAT to run (replace `*` with `https` or `ssh`):
50+
51+
```bash
52+
git clone --depth=1 -b master --single-branch *://<PAT>@github.com/ipitio/backage /opt/backage/master
53+
```
54+
55+
- `-m 0` ensures only the public packages of the owners you've added are updated (default)
56+
- You'll need the proper permissions to update private packages
57+
- `-d 0` allows everything to be updated in one go
58+
- A graceful restart is initiated every 4.5 hours by default
59+
60+
```bash
61+
echo "[Unit]
62+
Description=Run Backage
63+
After=network.target
64+
StartLimitIntervalSec=0
65+
66+
[Service]
67+
Type=simple
68+
Restart=always
69+
RestartSec=5
70+
ExecStart=/usr/bin/sh -c ' \\
71+
GITHUB_TOKEN=<PAT> ;\\
72+
GITHUB_OWNER=<username> ;\\
73+
GITHUB_REPO=backage ;\\
74+
GITHUB_BRANCH=master ;\\
75+
BKG_PATH=\$GITHUB_REPO/\$GITHUB_BRANCH ;\\
76+
mkdir -p /opt/\$BKG_PATH ;\\
77+
docker run -v /opt/\$BKG_PATH:/app \\
78+
--env-file <(env | grep GITHUB) \\
79+
ghcr.io/\$GITHUB_OWNER/\${BKG_PATH////:} \\
80+
src/test/update.sh -m 0 -d 0'
81+
82+
[Install]
83+
WantedBy=multi-user.target
84+
" | sudo tee /etc/systemd/system/bkg.service
85+
sudo systemctl daemon-reload
86+
sudo systemctl enable --now bkg
87+
```
88+
89+
</details>
2490

2591
## The Endpoint
2692

2793
```py
2894
https://ipitio.github.io/backage/OWNER/[REPO/[PACKAGE]].FORMAT
2995
```
3096

31-
Once the packages you're interested in have been added, replace the parameters with their respective values, scoping to your parsing needs, then access the latest data however you want. The format can be either `json` or `xml`. Use something like [shields.io/json](https://shields.io/badges/dynamic-json-badge) or [shields.io/xml](https://shields.io/badges/dynamic-xml-badge) to make badges like [this one](https://github.com/badges/shields/issues/5594#issuecomment-2157626147); you'll need the latter to evaluate expressions, like filters ([issue](https://github.com/ipitio/backage/issues/23)).
97+
Once the packages you're interested in have been added, replace the parameters with their respective values, scoping to your parsing needs, then access the latest data however you want. The format can be either `json` or `xml`.
98+
99+
> [!NOTE]
100+
> Use something like [shields.io/json](https://shields.io/badges/dynamic-json-badge) or [shields.io/xml](https://shields.io/badges/dynamic-xml-badge) to make badges like [this one](https://github.com/badges/shields/issues/5594#issuecomment-2157626147). You'll need the latter to evaluate expressions, like filters ([issue](https://github.com/ipitio/backage/issues/23)).
32101
33102
### Available Properties
34103

@@ -164,7 +233,7 @@ As can packages in `owner[/repo]/.xml` files:
164233
https://github.com/pkgforge-dev/backage/raw/index/OWNER/[REPO/[PACKAGE]].FORMAT
165234
```
166235
167-
The endpoint is also available here!
236+
The endpoint is also available here! This will change to your fork once it updates.
168237
169238
## JSON2XML Proxy
170239

src/bkg.sh

100644100755
Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#!/bin/bash
2-
# shellcheck disable=SC1091,SC2015
2+
# shellcheck disable=SC1091,SC2015,SC2034
33
#
44
# Modes:
5-
# 0 - Update all public (default)
6-
# 1 - Update own public
7-
# 2 - Just clean up
8-
# 3 - Update all public and own private
9-
# 4 - Update own public and private
10-
# 5 - Update own private
5+
# 0 - Update all public pkgs (default)
6+
# 1 - Update own public pkgs
7+
# 2 - Just clean the dir
8+
# 3 - Update all public and own private pkgs
9+
# 4 - Update own public and private pkgs
10+
# 5 - Update own private pkgs
1111
#
12-
# Usage: source bkg.sh && main [-m <mode>]
12+
# Duration:
13+
# < 0 - Unlimited
14+
# >= 0 - Run for this many seconds
15+
#
16+
# Usage: source bkg.sh && main [-d <duration>] [-m <mode>]
1317

1418
source lib/owner.sh
1519

@@ -25,11 +29,15 @@ main() {
2529
local return_code=0
2630
local opted_out
2731
local opted_out_before
32+
local len_conn
2833
connections=$(mktemp) || exit 1
2934
temp_connections=$(mktemp) || exit 1
3035

31-
while getopts "m:" flag; do
36+
while getopts "d:m:" flag; do
3237
case ${flag} in
38+
d)
39+
BKG_MAX_LEN=$((OPTARG))
40+
;;
3341
m)
3442
BKG_MODE=$((OPTARG))
3543
;;
@@ -120,14 +128,13 @@ main() {
120128
cat "$temp_connections" >>"$connections"
121129

122130
sed -i 's/^[[:space:]]*//;s/[[:space:]]*$//; /^$/d; /^0\/$/d' "$connections"
123-
[[ "$(wc -l <"$BKG_OWNERS")" -ge $(($(sort -u "$connections" | wc -l) + 100)) ]] || seq 1 2 | env_parallel --lb --halt soon,fail=1 page_owner
131+
# shellcheck disable=SC2319
132+
BKG_PAGE_ALL=$( (($(wc -l <"$BKG_OWNERS") < $(($(sort -u "$connections" | wc -l) + 100)))); echo "$?")
133+
seq 1 2 | env_parallel --lb --halt soon,fail=1 page_owner
124134
else
125135
get_membership "$GITHUB_OWNER" >"$connections"
126-
curl "https://raw.githubusercontent.com/ipitio/backage/refs/heads/$GITHUB_BRANCH/optout.txt" > base_out
127-
curl "https://raw.githubusercontent.com/ipitio/backage/refs/heads/$GITHUB_BRANCH/owners.txt" > base_own
128-
! diff -q "$BKG_OWNERS" base_own || : > "$BKG_OWNERS"
129-
! diff -q "$BKG_OPTOUT" base_out || : > "$BKG_OPTOUT"
130-
rm -f base_out base_own
136+
[ "$BKG_IS_FIRST" = "false" ] || : > "$BKG_OWNERS"
137+
[ "$BKG_IS_FIRST" = "false" ] || : > "$BKG_OPTOUT"
131138
fi
132139

133140
sort "$connections" | uniq -c | sort -nr | awk '{print $2}' >"$connections".bak
@@ -177,9 +184,10 @@ main() {
177184

178185
rm -f all_owners_in_db all_owners_tu
179186
clean_owners "$BKG_OWNERS"
180-
head -n $(($(wc -l <"$connections") + 2)) "$BKG_OWNERS" | env_parallel --lb save_owner
187+
len_conn=$(wc -l <"$connections")
188+
head -n $(( len_conn < 100 ? len_conn + 100 : len_conn * 3 / 2 )) "$BKG_OWNERS" | env_parallel --lb save_owner
181189
awk -F'|' '{print $1"/"$2}' packages_to_update | sort -uR 2>/dev/null | head -n1000 | env_parallel --lb save_owner
182-
parallel "sed -i '\,^{}$,d' $BKG_OWNERS" <"$connections"
190+
parallel "sed -i '\,^{}$,d' $BKG_OWNERS" ::: "$(sed 's/"/\\"/g' "$connections")"
183191
sed -i '/^0\//d' "$BKG_OWNERS"
184192
set_BKG BKG_DIFF "$db_size_curr"
185193
fi

src/lib/owner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ page_owner() {
6262
jq -e '.[].login' <<<"$owners_more" &>/dev/null || return 2
6363
local owners_lines
6464
owners_lines=$(jq -r '.[] | @base64' <<<"$owners_more")
65-
run_parallel request_owner "$owners_lines"
65+
(( BKG_PAGE_ALL > 0 )) && request_owner "$(echo "$owners_lines" | head -n1)" || run_parallel request_owner "$owners_lines"
6666
echo "Checked owners page $1"
6767
[ "$(wc -l <<<"$owners_lines")" -gt 1 ] || return 2
6868
}

src/lib/package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ update_package() {
144144
fi
145145

146146
# calculate the overall downloads and size
147-
size=$(sqlite3 "$BKG_INDEX_DB" "select size from '$table_version_name' where id in (select id from '$table_version_name' order by id desc limit 1) order by date desc limit 1;")
147+
size=$(sqlite3 "$BKG_INDEX_DB" "select size from '$table_version_name' where size > 1 order by id desc, date desc limit 1;")
148148
raw_all=$(sqlite3 "$BKG_INDEX_DB" "select sum(downloads), sum(downloads_month), sum(downloads_week), sum(downloads_day) from '$table_version_name' where date in (select date from '$table_version_name' order by date desc limit 1);")
149149
summed_raw_downloads=$(cut -d'|' -f1 <<<"$raw_all")
150150
raw_downloads_month=$(cut -d'|' -f2 <<<"$raw_all")

0 commit comments

Comments
 (0)