From 04dd2653ba4c924a37c0e8f75cbef0bdd4aee610 Mon Sep 17 00:00:00 2001 From: hiimgoodpack Date: Sun, 29 Nov 2020 17:15:13 -0600 Subject: [PATCH] Add locking --- aps.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/aps.sh b/aps.sh index 4bd8c31..9c26ae4 100644 --- a/aps.sh +++ b/aps.sh @@ -4,6 +4,7 @@ AL_TEMP_LOCATION="/tmp" AL_INSTALL_ROOT="/tmp/alroot" AL_INSTALLED_PKG_DATABASE="${AL_INSTALL_ROOT}/var/aps/installed" AL_LOCAL_PKG_DATABASE="${AL_INSTALL_ROOT}/var/aps/repos" +AL_LOCK="${AL_INSTALL_ROOT}/var/aps/lock" # Repo config official="https://git.hippoz.xyz/alnux/repo" @@ -192,6 +193,13 @@ upgrade() { } main() { + if [ -f "${AL_LOCK}" ]; then + echo "[E] A lock file already exists." + echo " If you're sure no package manager is running," + echo " remove the file ${AL_LOCK}" + fi + touch "${AL_LOCK}" + case ${1} in install) install_local_package "${2}" @@ -212,9 +220,12 @@ main() { ;; *) echo "[E] Invalid option ${1}, exiting..." + rm "${AL_LOCK}" exit 0 ;; esac + + rm "${AL_LOCK}" } -main "${1}" "${2}" \ No newline at end of file +main "${1}" "${2}"