aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xapkg-reposync13
1 files changed, 11 insertions, 2 deletions
diff --git a/apkg-reposync b/apkg-reposync
index e1e14e3..6b275c1 100755
--- a/apkg-reposync
+++ b/apkg-reposync
@@ -2,6 +2,7 @@
APKG_CONF="${APKG_CONF:-/etc/apkg.conf}"
temp_repos_file=$(mktemp)
+write_permission=0
die() {
[ "$1" ] && echo "error: $1"
@@ -20,6 +21,11 @@ find_current_branch() {
current_branch=$(git remote show "${default_remote}" | sed -n '/HEAD branch/s/.*: //p')
}
+check_write_permissions() {
+ random_file=$(find "${1}" -type f -print0 | shuf -z -n 1)
+ test -w "$random_file" || write_permission=$((write_permission+1))
+}
+
source_and_sanity_checks() {
[ ! -e "$(realpath "${APKG_CONF}")" ] && die "There is no configuration file in ${APKG_CONF}! Exiting..."
@@ -27,9 +33,11 @@ source_and_sanity_checks() {
[ -z "${APKG_REPO}" ] && die "There are no repos configured in $APKG_CONF, exiting..."
-for r in ${APKG_REPO}; do printf "%s\n" "$r" >> "$temp_repos_file"; done
+for r in ${APKG_REPO}; do
+printf "%s\n" "$r" >> "$temp_repos_file"
+check_write_permissions "$r"; done
+[ "$write_permission" = 0 ] || die "You need to execute the script as root!"
printf "%s\n" "Configured repos:" && awk ' {print $0} ' "$temp_repos_file"
-
grep -q "alicelinux/repos/core" "$temp_repos_file" || die "No official repos configured in $APKG_CONF"
}
@@ -58,6 +66,7 @@ sync_or_skip() {
fi
done
}
+
source_and_sanity_checks
sync_official
sync_or_skip