diff options
| author | mobinmob <mobinmob@disroot.org> | 2024-08-23 19:30:24 +0300 |
|---|---|---|
| committer | mobinmob <mobinmob@disroot.org> | 2024-08-23 19:32:56 +0300 |
| commit | 35795794f28be83afa4faff82c4faacdded39de9 (patch) | |
| tree | 1ae032b5c897b6ab3b25e7a935fc78146b9eb295 /apkg-reposync | |
| parent | a9107929029a5dac1a40b18cae397720fa7f3f4a (diff) | |
| download | autils-35795794f28be83afa4faff82c4faacdded39de9.tar.gz autils-35795794f28be83afa4faff82c4faacdded39de9.zip | |
apkg-reposync: check if the user cannot write to the repos.
Diffstat (limited to 'apkg-reposync')
| -rwxr-xr-x | apkg-reposync | 13 |
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 |