Skip to content

Commit 9783bf7

Browse files
committed
feat: Add ability to update system package cache
Adds the `--update_cache` option to allow/disallow system package manager cache updates. By default, this option is enabled, and system package manager cache will be update once when installing packages.
1 parent 3654121 commit 9783bf7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

package_tool

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ usage()
99
echo " --update: Update the system."
1010
echo " --usage: This usage message."
1111
echo " --pip_packages: comma separated list of pip modules to install"
12+
echo " --update_cache: Update package cache before install/updating packages, 1 (default) updates cache, 0 skips cache update"
1213
echo " --python_exec: path to python intrepreter to install pip modules for (default \"python3\"), will require installation of relevant packages to install pip"
1314
exit 1
1415
}
@@ -27,10 +28,19 @@ remove_packages=""
2728
wrapper_config=""
2829
pip_packages=""
2930
python_exec="python3"
31+
update_cache=1
32+
cache_cmd=""
3033

3134
base_dir=$(dirname $(realpath $0))
3235
running_os=$($base_dir/detect_os)
3336

37+
update_system_cache() {
38+
if [[ "$update_cache" -eq 1 ]]; then
39+
$install_cmd $cache_cmd
40+
fi
41+
update_cache=0 # Prevent multiple cache updates
42+
}
43+
3444
# Install System packages
3545
# Args:
3646
# - Comma separated list of packages, can also be space separated and work
@@ -41,7 +51,7 @@ install_system_pkgs() {
4151
if [[ -z "$package_list" ]]; then
4252
return 0 # Nothing to do
4353
fi
44-
54+
update_system_cache
4555
for package in $package_list; do
4656
$install_cmd install -y $package
4757
if [ $? -ne 0 ]; then
@@ -116,6 +126,7 @@ install_pip_pkgs() {
116126
ARGUMENT_LIST=(
117127
"is_installed"
118128
"no_packages"
129+
"update_cache"
119130
"packages"
120131
"remove_packages"
121132
"wrapper_config"
@@ -179,6 +190,10 @@ while [[ $# -gt 0 ]]; do
179190
wrapper_config=$2
180191
shift 2
181192
;;
193+
--update_cache)
194+
update_cache=$2
195+
shift 2
196+
;;
182197
-h)
183198
usage $0
184199
;;
@@ -196,16 +211,19 @@ install_cmd=""
196211
case "$running_os" in
197212
"ubuntu")
198213
install_cmd="/bin/apt"
214+
cache_cmd="update"
199215
;;
200216
"sles")
201217
install_cmd="/usr/bin/zypper"
218+
cache_cmd="refresh"
202219
;;
203220
*)
204221
if [[ -f "/bin/dnf" ]]; then
205222
install_cmd="/bin/dnf"
206223
elif [[ -f "/bin/yum" ]]; then
207224
install_cmd="/bin/yum"
208225
fi
226+
cache_cmd="makecache"
209227
;;
210228
esac
211229

0 commit comments

Comments
 (0)