aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormobinmob <mobinmob@disroot.org>2024-08-22 17:14:51 +0300
committermobinmob <mobinmob@disroot.org>2024-08-22 17:14:51 +0300
commit51fd1a7e010a30c2b399681649a3e131ea2c24f0 (patch)
tree4d75b90928a99a9569cb80efd4f8dff0f4e575a5
parent1d375c30fb693224405700612e672f19aff45738 (diff)
downloadautils-51fd1a7e010a30c2b399681649a3e131ea2c24f0.tar.gz
autils-51fd1a7e010a30c2b399681649a3e131ea2c24f0.zip
apkg-reposync: new util
-rwxr-xr-xapkg-reposync53
1 files changed, 53 insertions, 0 deletions
diff --git a/apkg-reposync b/apkg-reposync
new file mode 100755
index 0000000..b3cec1c
--- /dev/null
+++ b/apkg-reposync
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+APKG_CONF="${APKG_CONF:-/etc/apkg.conf}"
+temp_repos_file=$(mktemp)
+
+die() {
+ [ "$1" ] && echo "error: $1"
+ exit 1
+}
+
+source_and_sanity_checks() {
+[ ! -e $(realpath ${APKG_CONF}) ] && die "There is no configuration file in ${APKG_CONF}! Exiting..."
+
+. "${APKG_CONF}"
+
+[ -z ${APKG_REPO} ] && die "There are no repos configured in $APKG_CONF, exiting..."
+
+for r in ${APKG_REPO}; do printf "%s\n" "$r" >> $(realpath $temp_repos_file); done
+printf "%s\n" "Configured repos:" && awk ' {print $0} ' "$temp_repos_file"
+
+cat $temp_repos_file | grep -q "alicelinux/repos/core" > /dev/null || die "No official repos configured,exiting"
+}
+
+sync_official() {
+ # This assumes the current repo structure.
+ dir_for_official_repo=$(cat $temp_repos_file | grep alicelinux/repos/core)
+ [ -d "$dir_for_official_repo" ] || die "No $dir_for_official_repo exists, exiting..."
+ dir_for_official_repo=$(echo "$dir_for_official_repo" | sed "s/repos\/core//")
+ printf "%s\n" "~> Syncing official repos in $dir_for_official repo..."
+ cd "$dir_for_official_repo" || die "Cannot change to the repo directory, exiting..."
+ git pull origin main && printf "%s\n" "[~> Successfully synced the <official> repo!]"
+
+}
+
+sync_or_skip() {
+ # Remove all official repo lines from the temp_repos_file
+ unofficial_repos=$(grep -v alicelinux/repos "$temp_repos_file" | tr "\n" " ")
+ for r in $unofficial_repos; do
+ if [ -d "$r"/.git ]; then
+ cd "$r" || die "cannot cd to the repo"
+ default_remote=$(git branch --list "$(git branch --show-current)" \
+ "--format=%(upstream:remotename)")
+ default_branch=$(git remote show "${default_remote}" | sed -n '/HEAD branch/s/.*: //p')
+ git pull "$default_remote" "$default_branch"
+ else
+ printf "%s\n" "Repo in <$r> is not a git repo, Skipping..."
+ fi
+ done
+}
+source_and_sanity_checks
+sync_official
+sync_or_skip
+[ "$?" -eq 0 ] && echo "~> Repo(s) succesfully synced!"