Skip to content

Commit bc2a238

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 1c08018 + 1a99270 commit bc2a238

7 files changed

Lines changed: 261 additions & 220 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ git clone --depth=1 -b master --single-branch [https|ssh]://<PAT>@github.com/pkg
5858
- `-m 0` ensures only the public packages of the owners you've added are updated (default)
5959
- You'll need the proper permissions to update private packages
6060
- `-d 0` allows everything to be updated in one go
61-
- A graceful restart is initiated every 4.5 hours by default
61+
- A graceful restart is initiated every 4 hours by default
6262

6363
```bash
6464
echo "[Unit]
@@ -74,7 +74,7 @@ ExecStart=/usr/bin/sh -c ' \\
7474
GITHUB_TOKEN=<PAT> ;\\
7575
GITHUB_OWNER=<username> ;\\
7676
GITHUB_REPO=backage ;\\
77-
GITHUB_BRANCH=master ;\\
77+
GITHUB_BRANCH= ;\\
7878
BKG_PATH=\$GITHUB_REPO/\$GITHUB_BRANCH ;\\
7979
mkdir -p /opt/\$BKG_PATH ;\\
8080
docker run -v /opt/\$BKG_PATH:/app \\

src/bkg.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ main() {
141141
mv "$connections".bak "$connections"
142142

143143
echo "$(
144+
missed_owners
144145
cat "$BKG_OWNERS"
145-
find "$BKG_INDEX_DIR" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; 2>/dev/null | sort -u | awk '{print "0/"$1}'
146146
)" >"$BKG_OWNERS"
147147

148148
: >all_owners_in_db
@@ -155,7 +155,7 @@ main() {
155155
mv owners.tmp "$BKG_OWNERS"
156156
grep -vFxf all_owners_in_db "$connections" >"$temp_connections"
157157

158-
if [[ "$pkg_left" == "0" || "${db_size_curr::-5}" == "${db_size_prev::-5}" ]]; then
158+
if [[ "$pkg_left" == "0" || "${db_size_curr::-4}" == "${db_size_prev::-4}" ]]; then
159159
set_BKG BKG_BATCH_FIRST_STARTED "$today"
160160
rm -f packages_to_update
161161
\cp packages_all packages_to_update
@@ -194,15 +194,17 @@ main() {
194194
else
195195
save_owner "$GITHUB_OWNER"
196196
get_membership "$GITHUB_OWNER" >"$connections"
197-
[ ! -s "$connections" ] || env_parallel --lb save_owner <"$connections"
197+
if [ -s "$connections" ]; then
198+
env_parallel --lb save_owner <"$connections" || while read -r connection; do save_owner "$connection"; done <"$connections"
199+
fi
198200
fi
199201

200202
rm -f "$connections"
201203
rm -f "$temp_connections"
202204
BKG_BATCH_FIRST_STARTED=$(get_BKG BKG_BATCH_FIRST_STARTED)
203205
[ -d "$BKG_INDEX_DIR" ] || mkdir "$BKG_INDEX_DIR"
204206

205-
if [ "$GITHUB_OWNER" = "ipitio" ]; then
207+
if [[ "$GITHUB_OWNER" = "ipitio" && "$(git branch --show-current)" = "master" ]]; then
206208
get_BKG_set BKG_OWNERS_QUEUE | env_parallel --lb update_owner
207209
else # typically fewer owners
208210
run_parallel update_owner "$(get_BKG_set BKG_OWNERS_QUEUE)"

src/lib/owner.sh

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,31 +124,16 @@ update_owner() {
124124
find "$BKG_INDEX_DIR/$owner" -type f -name '*.json' ! -name '.*' -print0 | xargs -0 jq -cs '[.] | add' >"$BKG_INDEX_DIR/$owner/.json.tmp"
125125
jq -cs '{ ("package"): . }' "$BKG_INDEX_DIR/$owner/.json.tmp" >"$BKG_INDEX_DIR/$owner/.json"
126126
ytoxt "$BKG_INDEX_DIR/$owner/.json"
127-
128-
# if .package exists, split it into array
129-
if jq -e '.package' "$BKG_INDEX_DIR/$owner/.json" &>/dev/null; then
130-
jq -c '.package[]' "$BKG_INDEX_DIR/$owner/.json" >"$BKG_INDEX_DIR/$owner/.json.tmp"
131-
mv -f "$BKG_INDEX_DIR/$owner/.json.tmp" "$BKG_INDEX_DIR/$owner/.json"
132-
fi
127+
jq -c '.package[]' "$BKG_INDEX_DIR/$owner/.json" >"$BKG_INDEX_DIR/$owner/.json.tmp" 2>/dev/null
128+
mv -f "$BKG_INDEX_DIR/$owner/.json.tmp" "$BKG_INDEX_DIR/$owner/.json" 2>/dev/null
133129

134130
echo "Creating $owner repo arrays..."
135-
# shellcheck disable=SC2086,SC2016
136-
parallel '
137-
repo={}
138-
repo_dir="$BKG_INDEX_DIR/'"$owner"'/$repo"
139-
src="$BKG_INDEX_DIR/'"$owner"'/.json"
140-
tmp="$repo_dir/.json.tmp"
141-
dst="$repo_dir/.json"
142-
143-
jq -c --arg repo "$repo" '"'"'[.[] | select(.repo == $repo)]'"'"' "$src" >"$tmp" &&
144-
jq -cs '"'"'{ ("package"): . }'"'"' "$tmp" >"$dst" &&
145-
ytoxt "$dst"
146-
if jq -e '"'"'.package'"'"' "$dst" &>/dev/null; then
147-
jq -c '"'"'.package[]'"'"' "$dst" >"$tmp"
148-
mv -f "$tmp" "$dst"
149-
fi
150-
' ::: $owner_repos
151-
fi
131+
parallel "jq -c --arg repo {} '[.[] | select(.repo == \$repo)]' \"$BKG_INDEX_DIR/$owner/.json\" > \"$BKG_INDEX_DIR/$owner/{}/.json.tmp\"" <<<"$owner_repos"
132+
xargs -I {} bash -c "jq -cs '{ (\"package\"): . }' \"$BKG_INDEX_DIR/$owner/{}/.json.tmp\" > \"$BKG_INDEX_DIR/$owner/{}/.json\"" <<<"$owner_repos"
133+
xargs -I {} bash -c "ytoxt \"$BKG_INDEX_DIR/$owner/{}/.json\"" <<<"$owner_repos"
134+
xargs -I {} bash -c "jq -c '.package[]' \"$BKG_INDEX_DIR/$owner/{}/.json\" > \"$BKG_INDEX_DIR/$owner/{}/.json.tmp\"" 2>/dev/null <<<"$owner_repos"
135+
xargs -I {} mv -f "$BKG_INDEX_DIR/$owner/{}/.json.tmp" "$BKG_INDEX_DIR/$owner/{}/.json" 2>/dev/null <<<"$owner_repos"
136+
fi
152137

153138
sed -i '/^\(.*\/\)*'"$owner"'$/d' "$BKG_OWNERS"
154139
echo "Updated $owner"

src/lib/package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ update_package() {
121121
sqlite3 "$BKG_INDEX_DB" "select id from '$table_version_name' where date >= '$BKG_BATCH_FIRST_STARTED';" | sort -u >"${table_version_name}"_already_updated
122122
local break_now=false
123123

124-
for page in $(seq 0 5); do
124+
for page in $(seq 0 1); do
125125
((page > 0)) || continue
126126
local pages_left=0
127127
page_version "$page"

0 commit comments

Comments
 (0)