Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0cafeee

Browse files
authored
favor correctness by removing apt update ... short-circuiting (#98)
* favor correctness by removing apt update shortciruiting * Update install.sh * apt_get_upadate in node * update test
1 parent 58e4250 commit 0cafeee

24 files changed

Lines changed: 116 additions & 215 deletions

File tree

src/anaconda/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ updaterc() {
6464
# Checks if packages are installed and installs them if not
6565
check_packages() {
6666
if ! dpkg -s "$@" > /dev/null 2>&1; then
67-
apt-get update
67+
apt-get update -y
6868
apt-get -y install --no-install-recommends "$@"
6969
fi
7070
}

src/aws-cli/install.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,16 @@ get_common_setting() {
6262
echo "$1=${!1}"
6363
}
6464

65-
# Function to run apt-get if needed
66-
apt_get_update_if_needed()
65+
apt_get_update()
6766
{
68-
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
69-
echo "Running apt-get update..."
70-
apt-get update
71-
else
72-
echo "Skipping apt-get update."
73-
fi
67+
echo "Running apt-get update..."
68+
apt-get update -y
7469
}
7570

7671
# Checks if packages are installed and installs them if not
7772
check_packages() {
7873
if ! dpkg -s "$@" > /dev/null 2>&1; then
79-
apt_get_update_if_needed
74+
apt_get_update
8075
apt-get -y install --no-install-recommends "$@"
8176
fi
8277
}

src/azure-cli/install.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,16 @@ get_common_setting() {
3535
echo "$1=${!1}"
3636
}
3737

38-
# Function to run apt-get if needed
39-
apt_get_update_if_needed()
38+
apt_get_update()
4039
{
41-
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
42-
echo "Running apt-get update..."
43-
apt-get update
44-
else
45-
echo "Skipping apt-get update."
46-
fi
40+
echo "Running apt-get update..."
41+
apt-get update -y
4742
}
4843

4944
# Checks if packages are installed and installs them if not
5045
check_packages() {
5146
if ! dpkg -s "$@" > /dev/null 2>&1; then
52-
apt_get_update_if_needed
47+
apt_get_update
5348
apt-get -y install --no-install-recommends "$@"
5449
fi
5550
}
@@ -127,7 +122,7 @@ install_using_apt() {
127122
install_using_pip() {
128123
echo "(*) No pre-built binaries available in apt-cache. Installing via pip3."
129124
if ! dpkg -s python3-minimal python3-pip libffi-dev python3-venv > /dev/null 2>&1; then
130-
apt_get_update_if_needed
125+
apt_get_update
131126
apt-get -y install python3-minimal python3-pip libffi-dev python3-venv
132127
fi
133128
export PIPX_HOME=/usr/local/pipx

src/common-utils/install.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,10 @@ fi
6060
# Ensure apt is in non-interactive to avoid prompts
6161
export DEBIAN_FRONTEND=noninteractive
6262

63-
# Function to call apt-get if needed
64-
apt_get_update_if_needed()
63+
apt_get_update()
6564
{
66-
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
67-
echo "Running apt-get update..."
68-
apt-get update
69-
else
70-
echo "Skipping apt-get update."
71-
fi
65+
echo "Running apt-get update..."
66+
apt-get update -y
7267
}
7368

7469
# Run install apt-utils to avoid debconf warning then verify presence of other common developer tools and dependencies
@@ -134,7 +129,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
134129
apt-get update
135130
package_list="${package_list} manpages-posix manpages-posix-dev"
136131
else
137-
apt_get_update_if_needed
132+
apt_get_update
138133
fi
139134

140135
# Install libssl1.1 if available
@@ -167,7 +162,7 @@ fi
167162

168163
# Get to latest versions of all packages
169164
if [ "${UPGRADE_PACKAGES}" = "true" ]; then
170-
apt_get_update_if_needed
165+
apt_get_update
171166
apt-get -y upgrade --no-install-recommends
172167
apt-get autoremove -y
173168
fi
@@ -366,7 +361,7 @@ fi
366361
# Optionally install and configure zsh and Oh My Zsh!
367362
if [ "${INSTALL_ZSH}" = "true" ]; then
368363
if ! type zsh > /dev/null 2>&1; then
369-
apt_get_update_if_needed
364+
apt_get_update
370365
apt-get install -y zsh
371366
fi
372367
if [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then

src/desktop-lite/install.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,16 @@ copy_fluxbox_config() {
149149
fi
150150
}
151151

152-
153-
# Function to run apt-get if needed
154-
apt_get_update_if_needed()
152+
apt_get_update()
155153
{
156-
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
157-
echo "Running apt-get update..."
158-
apt-get update
159-
else
160-
echo "Skipping apt-get update."
161-
fi
154+
echo "Running apt-get update..."
155+
apt-get update -y
162156
}
163157

164158
# Checks if packages are installed and installs them if not
165159
check_packages() {
166160
if ! dpkg -s "$@" > /dev/null 2>&1; then
167-
apt_get_update_if_needed
161+
apt_get_update
168162
apt-get -y install --no-install-recommends "$@"
169163
fi
170164
}
@@ -176,7 +170,7 @@ check_packages() {
176170
# Ensure apt is in non-interactive to avoid prompts
177171
export DEBIAN_FRONTEND=noninteractive
178172

179-
apt_get_update_if_needed
173+
apt_get_update
180174

181175
# On older Ubuntu, Tilix is in a PPA. on Debian strech its in backports.
182176
if [[ -z $(apt-cache --names-only search ^tilix$) ]]; then

src/docker-from-docker/install.sh

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,16 @@ get_common_setting() {
5959
echo "$1=${!1}"
6060
}
6161

62-
# Function to run apt-get if needed
63-
apt_get_update_if_needed()
62+
apt_get_update()
6463
{
65-
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
66-
echo "Running apt-get update..."
67-
apt-get update
68-
else
69-
echo "Skipping apt-get update."
70-
fi
64+
echo "Running apt-get update..."
65+
apt-get update -y
7166
}
7267

7368
# Checks if packages are installed and installs them if not
7469
check_packages() {
7570
if ! dpkg -s "$@" > /dev/null 2>&1; then
76-
apt_get_update_if_needed
71+
apt_get_update
7772
apt-get -y install --no-install-recommends "$@"
7873
fi
7974
}
@@ -118,7 +113,7 @@ export DEBIAN_FRONTEND=noninteractive
118113
# Install dependencies
119114
check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr
120115
if ! type git > /dev/null 2>&1; then
121-
apt_get_update_if_needed
116+
apt_get_update
122117
apt-get -y install git
123118
fi
124119

@@ -212,7 +207,7 @@ else
212207
if [ "${TARGET_COMPOSE_ARCH}" != "x86_64" ]; then
213208
# Use pip to get a version that runns on this architecture
214209
if ! dpkg -s python3-minimal python3-pip libffi-dev python3-venv > /dev/null 2>&1; then
215-
apt_get_update_if_needed
210+
apt_get_update
216211
apt-get -y install python3-minimal python3-pip libffi-dev python3-venv
217212
fi
218213
export PIPX_HOME=/usr/local/pipx
@@ -287,7 +282,7 @@ DOCKER_GID="$(grep -oP '^docker:x:\K[^:]+' /etc/group)"
287282
# If enabling non-root access and specified user is found, setup socat and add script
288283
chown -h "${USERNAME}":root "${TARGET_SOCKET}"
289284
if ! dpkg -s socat > /dev/null 2>&1; then
290-
apt_get_update_if_needed
285+
apt_get_update
291286
apt-get -y install socat
292287
fi
293288
tee /usr/local/share/docker-init.sh > /dev/null \

src/docker-in-docker/install.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,16 @@ get_common_setting() {
6969
echo "$1=${!1}"
7070
}
7171

72-
# Function to run apt-get if needed
73-
apt_get_update_if_needed()
72+
apt_get_update()
7473
{
75-
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
76-
echo "Running apt-get update..."
77-
apt-get update
78-
else
79-
echo "Skipping apt-get update."
80-
fi
74+
echo "Running apt-get update..."
75+
apt-get update -y
8176
}
8277

8378
# Checks if packages are installed and installs them if not
8479
check_packages() {
8580
if ! dpkg -s "$@" > /dev/null 2>&1; then
86-
apt_get_update_if_needed
81+
apt_get_update
8782
apt-get -y install --no-install-recommends "$@"
8883
fi
8984
}
@@ -158,7 +153,7 @@ fi
158153
# Install dependencies
159154
check_packages apt-transport-https curl ca-certificates pigz iptables gnupg2 dirmngr
160155
if ! type git > /dev/null 2>&1; then
161-
apt_get_update_if_needed
156+
apt_get_update
162157
apt-get -y install git
163158
fi
164159

@@ -254,7 +249,7 @@ else
254249
if [ "${target_compose_arch}" != "x86_64" ]; then
255250
# Use pip to get a version that runs on this architecture
256251
if ! dpkg -s python3-minimal python3-pip libffi-dev python3-venv > /dev/null 2>&1; then
257-
apt_get_update_if_needed
252+
apt_get_update
258253
apt-get -y install python3-minimal python3-pip libffi-dev python3-venv
259254
fi
260255
export PIPX_HOME=/usr/local/pipx

src/dotnet/install.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,16 @@ updaterc() {
107107
fi
108108
}
109109

110-
# Run apt-get if needed.
111-
apt_get_update_if_needed() {
112-
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
113-
echo "Running apt-get update..."
114-
apt-get update
115-
else
116-
echo "Skipping apt-get update."
117-
fi
110+
apt_get_update()
111+
{
112+
echo "Running apt-get update..."
113+
apt-get update -y
118114
}
119115

120116
# Check if packages are installed and installs them if not.
121117
check_packages() {
122118
if ! dpkg -s "$@" > /dev/null 2>&1; then
123-
apt_get_update_if_needed
119+
apt_get_update
124120
apt-get -y install --no-install-recommends "$@"
125121
fi
126122
}

src/git-lfs/install.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,16 @@ receive_gpg_keys() {
105105
fi
106106
}
107107

108-
# Function to run apt-get if needed
109-
apt_get_update_if_needed()
108+
apt_get_update()
110109
{
111-
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
112-
echo "Running apt-get update..."
113-
apt-get update
114-
else
115-
echo "Skipping apt-get update."
116-
fi
110+
echo "Running apt-get update..."
111+
apt-get update -y
117112
}
118113

119114
# Checks if packages are installed and installs them if not
120115
check_packages() {
121116
if ! dpkg -s "$@" > /dev/null 2>&1; then
122-
apt_get_update_if_needed
117+
apt_get_update
123118
apt-get -y install --no-install-recommends "$@"
124119
fi
125120
}
@@ -183,7 +178,7 @@ export DEBIAN_FRONTEND=noninteractive
183178
. /etc/os-release
184179
check_packages curl ca-certificates gnupg2 dirmngr apt-transport-https
185180
if ! type git > /dev/null 2>&1; then
186-
apt_get_update_if_needed
181+
apt_get_update
187182
apt-get -y install --no-install-recommends git
188183
fi
189184
if [ "${ID}" = "debian" ]; then

src/git/install.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,16 @@ receive_gpg_keys() {
7474
fi
7575
}
7676

77-
# Function to run apt-get if needed
78-
apt_get_update_if_needed()
77+
apt_get_update()
7978
{
80-
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
81-
echo "Running apt-get update..."
82-
apt-get update
83-
else
84-
echo "Skipping apt-get update."
85-
fi
79+
echo "Running apt-get update..."
80+
apt-get update -y
8681
}
8782

8883
# Checks if packages are installed and installs them if not
8984
check_packages() {
9085
if ! dpkg -s "$@" > /dev/null 2>&1; then
91-
apt_get_update_if_needed
86+
apt_get_update
9287
apt-get -y install --no-install-recommends "$@"
9388
fi
9489
}

0 commit comments

Comments
 (0)