@@ -21,15 +21,18 @@ wait_for_apt_locks() {
2121 sleep 3
2222 done
2323}
24- apt_get_update () {
25- retries=10
26- apt_update_output=/tmp/apt-get-update.out
24+ # Core update function used by apt_get_update and apt_get_install_from_local_repo
25+ _apt_get_update () {
26+ local retries=$1
27+ local apt_opts=$2
28+ local apt_update_output=/tmp/apt-get-update.out
29+
2730 for i in $( seq 1 $retries ) ; do
2831 wait_for_apt_locks
2932 export DEBIAN_FRONTEND=noninteractive
3033 dpkg --configure -a --force-confdef
31- apt-get -f -y install
32- ! (apt-get update 2>&1 | tee $apt_update_output | grep -E " ^([WE]:.*)|^([Ee][Rr][Rr][Oo][Rr].*)$" ) && \
34+ apt-get ${apt_opts} -f -y install
35+ ! (apt-get ${apt_opts} update 2>&1 | tee $apt_update_output | grep -E " ^([WE]:.*)|^([Ee][Rr][Rr][Oo][Rr].*)$" ) && \
3336 cat $apt_update_output && break || \
3437 cat $apt_update_output
3538 if [ $i -eq $retries ]; then
@@ -40,22 +43,37 @@ apt_get_update() {
4043 echo Executed apt-get update $i times
4144 wait_for_apt_locks
4245}
43- apt_get_install () {
44- retries=$1 ; wait_sleep=$2 ; timeout=$3 ; shift && shift && shift
46+ apt_get_update () {
47+ _apt_get_update 10 " "
48+ }
49+ _apt_get_install () {
50+ local retries=$1
51+ local wait_sleep=$2
52+ local apt_opts=$3
53+ shift && shift && shift
54+
4555 for i in $( seq 1 $retries ) ; do
4656 wait_for_apt_locks
4757 export DEBIAN_FRONTEND=noninteractive
4858 dpkg --configure -a --force-confdef
49- apt-get install -o Dpkg::Options::=" --force-confold" --no-install-recommends -y ${@ } && break || \
59+
60+ if apt-get install ${apt_opts} -o Dpkg::Options::=" --force-confold" --no-install-recommends " ${@ } " ; then
61+ echo " Executed apt-get install \" ${packages[@]} \" $i times"
62+ wait_for_apt_locks
63+ return 0
64+ fi
65+
5066 if [ $i -eq $retries ]; then
5167 return 1
5268 else
5369 sleep $wait_sleep
5470 apt_get_update
5571 fi
5672 done
57- echo Executed apt-get install --no-install-recommends -y \" $@ \" $i times ;
58- wait_for_apt_locks
73+ }
74+ apt_get_install () {
75+ retries=$1 ; wait_sleep=$2 ; timeout=$3 ; shift && shift && shift
76+ _apt_get_install $retries $wait_sleep " -y" " $@ "
5977}
6078apt_get_purge () {
6179 retries=$1 ; wait_sleep=$2 ; timeout=$3 ; shift && shift && shift
@@ -101,4 +119,65 @@ installDebPackageFromFile() {
101119 return 1
102120 fi
103121}
122+
123+ apt_get_install_from_local_repo () {
124+ local local_repo_dir=$1
125+ local package_name=$2
126+ local installation_root=$3
127+
128+ # Convert to absolute path
129+ local_repo_dir=$( realpath " ${local_repo_dir} " )
130+
131+ if [ ! -d " ${local_repo_dir} " ]; then
132+ echo " Local repo directory ${local_repo_dir} does not exist"
133+ return 1
134+ fi
135+
136+ # Check if Packages.gz exists in the repo
137+ if [ ! -f " ${local_repo_dir} /Packages.gz" ]; then
138+ echo " Packages.gz not found in ${local_repo_dir} "
139+ return 1
140+ fi
141+
142+ wait_for_apt_locks
143+
144+ local tmp_list=$( mktemp)
145+ local tmp_dir=$( mktemp -d)
146+
147+ # Create temporary sources.list pointing to local repo
148+ printf ' deb [trusted=yes] file:%s ./\n' " ${local_repo_dir} " > " ${tmp_list} "
149+
150+ local opts=" -o Dir::Etc::sourcelist=${tmp_list} -o Dir::Etc::sourceparts=${tmp_dir} "
151+
152+ # Update apt cache with local repo using core update function
153+ if ! _apt_get_update 10 " ${opts} " ; then
154+ echo " Failed to update apt cache from local repo ${local_repo_dir} "
155+ rm -f " ${tmp_list} "
156+ rmdir " ${tmp_dir} "
157+ return 1
158+ fi
159+
160+ # Install package from local repo using core installation function
161+ local retries=10
162+ local wait_sleep=5
163+ if ! _apt_get_install $retries $wait_sleep " ${opts} " " ${package_name} " ; then
164+ echo " Failed to install ${package_name} from local repo"
165+ rm -f " ${tmp_list} "
166+ rmdir " ${tmp_dir} "
167+ return 1
168+ fi
169+
170+ # Cleanup
171+ rm -f " ${tmp_list} "
172+ rmdir " ${tmp_dir} "
173+
174+ # If installation_root is specified, copy binaries to that location
175+ if [ -n " ${installation_root} " ]; then
176+ echo " Copying binaries ${package_name} to ${installation_root} "
177+ mkdir -p " ${installation_root} "
178+ mv " /usr/bin/${package_name} " " /usr/local/bin/${package_name} "
179+ fi
180+
181+ return 0
182+ }
104183# EOF
0 commit comments