aboutsummaryrefslogtreecommitdiffstats
path: root/System/dpkg-lock.sh
blob: fcae98044b81ef39c3812a865d00291ea491eafb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
########################################################################################################################
# dpkg-lock.sh
########################################################################################################################
#
# All rights reserved Ⓒ 2017-2023 sdxlive.com
#
# Written by Jean-Christophe Manciot <jcmanciot@sdxlive.com>
#
# Licensed under a GPLv3 License.
# You may not use this file except in compliance with the License. You may obtain a copy of the License at
#
#    https://www.gnu.org/licenses/gpl-3.0.md
#
# The licensor cannot revoke these freedoms as long as you follow the license terms.
#
# Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. 
# You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
#
########################################################################################################################

########################################################################################################################
#
# Waiting until dpkg locks become available to execute the passed command under lock.
#
########################################################################################################################
#
# Requirements:
# ------------
#
# - We assume that the following packages are already installed:
#       + dpkg
#       + util-linux
#
########################################################################################################################
#
# Parameters:
# ----------
#
# the command with its arguments to be executed under lock
# 
#######################################################################################################################
#
# Usage: example
# -----
#
# dpkg-lock.sh apt --show-progress --assume-yes upgrade 
#
########################################################################################################################
# set -x

sudo flock --verbose --exclusive /var/lib/apt/lists/lock echo
sudo flock --verbose --exclusive /var/cache/apt/archives/lock echo
sudo flock --verbose --exclusive /var/lib/dpkg/lock-frontend echo
sudo flock --verbose --exclusive /var/lib/dpkg/lock "$@"

exit $?