#!/bin/sh # ===================================================================== # Projet : DARKCONTAINER # Fichier : lib/chroot-apt # Auteur : Nicolas "DarkHack" Chapuis (c) 2026 # ================== DARKHACK ================== # [ darkweb.fr - system online ] # Powered by Perplexity, your AI assistant # https://www.perplexity.ai # ============================================== # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ===================================================================== if ! type "shInclude" > /dev/null; then racineSh="${racineSh:-/etc/darksh}" rootDarkContainer="${rootDarkContainer:-/etc/darkcontainer}" . "$racineSh/lib/shTools" shLog="${shLog:-"no-parent"}-chroot-apt-init" shDebugEnable="${shDebugEnable:-1}" shDebugHidden "[ib/chroot-apt] racineSh:${racineSh} rootDarkContainer:${rootDarkContainer}" >&2 fi [ ! -d "$rootDarkContainer" ] && shDebug 0 "exit cause rootDarkContainer is not dir:$rootDarkContainer" >&2 && exit 0 # chroot function $( shInclude "${rootDarkContainer}/lib/chroot" ) # apt function $( shInclude "${rootDarkContainer}/lib/apt" ) #|------------------------------| #| base "which" tools | #| cp | rm | echo | head | tail | #| grep | rev | tr | cut | sh | #| date | cat | touch | #|------------------------------| requiresCmd="cp rm echo head tail grep rev tr cut sh date cat touch ln" shWhichCmd $requiresCmd >/dev/null #shWarnOnMissing $( shWhichCmd $requiresCmd | $cmdTr '_' ' ' ) shErrorOnMissing $( shWhichCmd $requiresCmd | $cmdTr '_' ' ' ) # &&&&& #|-----------------------------------------------------------------------| #| which "directory" tools : mkdir | chmod | chgrp | mount | umount | #|-----------------------------------------------------------------------| requiresCmd="mkdir chmod chgrp mount umount" shWhichCmd $requiresCmd >/dev/null #shWarnOnMissing $( shWhichCmd $requiresCmd | $cmdTr '_' ' ' ) shErrorOnMissing $( shWhichCmd $requiresCmd | $cmdTr '_' ' ' ) # &&&&& #|----------------------------------| #| user right "which" tools | #| chmod | chown | chgrp | groupadd | #| useradd | chroot | getent | #|----------------------------------| requiresCmd="chmod chown chgrp groupadd useradd chroot getent" shWhichCmd $requiresCmd >/dev/null #shWarnOnMissing $( shWhichCmd $requiresCmd | $cmdTr '_' ' ' ) shErrorOnMissing $( shWhichCmd $requiresCmd | $cmdTr '_' ' ' ) requiresCmd="dpkg" shWhichCmd $requiresCmd >/dev/null #shWarnOnMissing $( shWhichCmd $requiresCmd | $cmdTr '_' ' ' ) shErrorOnMissing $( shWhichCmd $requiresCmd | $cmdTr '_' ' ' ) cmdDpkgReconfigure="${cmdDpkgReconfigure:-$( which dpkg-reconfigure )}" cmdDpkgReconfigure="${cmdDpkgReconfigure:-$( PATH=$PATH:/usr/sbin which dpkg-reconfigure )}" #$(shInclude $rootDarkContainer/which/lib/base) && $(shInclude $rootDarkContainer/which/lib/directory) && $(shInclude $rootDarkContainer/which/lib/userRight) cmdStartStopDaemon="${cmdStartStopDaemon:-$(which start-stop-daemon 2>/dev/null)}" #pChrootDir="$pChrootDir" pName="$pName" pUser="$pUser" pGroup="$pGroup"\ #pCacheDir="$pCacheDir" pServiceInfo="$pServiceInfo" cmdDaemon="$cmdDaemon"\ #pLibFiles="$pLibFiles" pLibFolders="$pLibFolders" pCopyLib="$pCopyLib" pDirStruct="$pDirStruct"\ # apt_init_install apt_init_install() { local log="apt_init_install:" shErrorOnMissing "pChrootDir pName pUser pGroup" shErrorOnMissing "pCacheDir pServiceInfo cmdDaemon" shWarnOnMissing "pApt pLibFiles pLibFolders pCopyLib pDirStruct" shDebug 1 ""$log" chroot clear" apt_init_clear for aptToInstall in $pApt;do chroot_apt_install $pChrootDir $aptToInstall 2>&1 done } #apt_init_clear $pChrootDir $pName $pUser $pGroup $pBaseDir $pUserComment $pExtra apt_init_clear() { local log="apt_init_clear:" local pChrootDir="${pChrootDir:-$1}" local pName="${pName:-$2}" local pUser="${pUser:-$3}" local pGroup="${pGroup:-$4}" local pBaseDir="${pBaseDir:-$5}" local pUserComment="${pUserComment:-$6}" local pExtra="${pExtra:-$7}" chroot_init_dpkg "$pChrootDir" "$pName" "$pUser" "$pGroup" "$pBaseDir" "$pUserComment" "$pExtra" shDebug 1 ""$log" chroot install" for file in apt-get apt-cache start-stop-daemon;do chroot_install $pChrootDir "$( $cmdWhich $file )" done apt_install_essential $pChrootDir $pName $pUser $pGroup $pBaseDir $pUserComment $pExtra shDebug 1 ""$log" :end apt init clear" } #apt_install_essential $pChrootDir $pName $pUser $pGroup $pBaseDir $pUserComment $pExtra apt_install_essential() { local shLog="apt_install_essential" local pChrootDir="${pChrootDir:-$1}" local pName="${pName:-$2}" local pUser="${pUser:-$3}" local pGroup="${pGroup:-$4}" local pBaseDir="${pBaseDir:-$5}" local pUserComment="${pUserComment:-$6}" local pExtra="${pExtra:-$7}" # chroot_root_execute $pChrootDir "$cmdGroupadd -g 65534 nogroup" # chroot_root_execute $pChrootDir "$cmdUseradd -u 42 -g 65534 -c \"download apt\" -d /nonexistent -e \"\" -s $cmdNologin _apt" # [ ! -d "$pChrootDir/var/cache/apt/archives" ] && mkdir -p "$pChrootDir/var/cache/apt/archives" # $cmdChroot $pChrootDir $cmdChown -R _apt:root "/var/cache/apt/archives" # chown -R _apt:root "/var/cache/apt/archives" chroot_root_execute $pChrootDir "$cmdGroupadd -g 65534 nogroup" chroot_root_execute $pChrootDir "$cmdUseradd -u 42 -g 65534 -c \"download apt\" -d /nonexistent -e \"\" -s $cmdNologin _apt" [ ! -d "$pChrootDir/var/cache/apt/archives" ] && $cmdMkdir -p "$pChrootDir/var/cache/apt/archives" $cmdChroot $pChrootDir $cmdChown -R _apt "/var/cache/apt/archives" # $cmdChroot $pChrootDir $cmdChown -R 42:0 "/var/cache/apt/archives" # $cmdChown -R _apt:root "/var/cache/apt/archives" # chroot $pChrootDir chown -R _apt:root "/var/cache/apt/archives" # chroot_umount "$pChrootDir" chroot_mount "$pChrootDir" /proc chroot_mount "$pChrootDir" /sys chroot_mount "$pChrootDir" /dev # # local libperlvers="$( apt-file search threads.pm | grep perl | cut -f1 -d\: | grep -v pdl | tr -d '\n' )" # local packagesPerl="perl-base perl-modules libperl$perlVersion perl-modules-$perlVersion libtext-unidecode-perl ${libperlvers}" # local packagesPerl="${packagesPerl} libthreads-perl libthreads-shared-perl libfile-find-rule-perl libtext-glob-perl libnumber-compare-perl" local perlVersion="$( apt-cache policy perl-base | grep Install | cut -d: -f2 |tr -d ' ' | cut -d. -f1,2 )" # local perlVersion2="$( apt-cache policy perl-base | grep Install | cut -d: -f2 |tr -d ' ' | cut -d. -f1,2,3 | cut -d- -f1 )" # echo $perlVersion/$perlVersion2 local packagesPerl="perl-base perl-modules libperl$perlVersion perl-modules-$perlVersion libtext-unidecode-perl liblocale-gettext-perl" # aptDepsListStage0="" # exit 0 # for subPerl in $packagesPerl;do # aptNoDeps="" chroot_apt_stage0 $pChrootDir $subPerl 2>&1 | tee "$pChrootDir/chroot_0stage_install_first_perl.log" ## chroot_apt_install $pChrootDir $subPerl 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_first_perl.log" # done # aptNoDeps="" chroot_apt_stage0 $pChrootDir libgcc1 2>&1 | tee "$pChrootDir/chroot_0stage_install_first_libgcc1.log" # aptNoDeps="" chroot_apt_stage0 $pChrootDir multiarch-support 2>&1 | tee "$pChrootDir/chroot_0stage_install_first_multiarch-support.log" # aptNoDeps="" chroot_apt_stage0 $pChrootDir libc6 2>&1 | tee "$pChrootDir/chroot_0stage_install_first_libc6.log" # aptNoDeps="" chroot_apt_stage0 $pChrootDir libc-bin 2>&1 | tee "$pChrootDir/chroot_0stage_install_first_libc-bin.log" # aptNoDeps="" chroot_apt_stage0 $pChrootDir dpkg 2>&1 | tee "$pChrootDir/chroot_0stage_install_first_dpkg.log" aptDepsListStage0="" aptDepsListInstall="" forceDeps="1" chroot_apt_install $pChrootDir libgcc1 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_libgcc1.log" forceDeps="1" chroot_apt_install $pChrootDir multiarch-support 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_multiarch-support.log" forceDeps="1" chroot_apt_install $pChrootDir libc6 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_libc6.log" forceDeps="1" chroot_apt_install $pChrootDir libc-bin 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_libc-bin.log" forceDeps="1" chroot_apt_install $pChrootDir dpkg 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_dpkg.log" for subPerl in $packagesPerl;do forceDeps="1" chroot_apt_install $pChrootDir $subPerl 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_perl.log" # chroot_apt_install $pChrootDir $subPerl 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_perl.log" done rm "$pChrootDir/chroot_apt.lst" forceDeps="1" chroot_apt_install $pChrootDir multiarch-support 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_multiarch-support.log" forceDeps="1" chroot_apt_install $pChrootDir dialog 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_dialog.log" forceDeps="1" chroot_apt_install $pChrootDir coreutils 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_coreutils.log" forceDeps="1" chroot_apt_install $pChrootDir locales 2>&1 >> "$pChrootDir/darkcontainer-chroot-apt-stage0_locales.log" shDebug 1 "first try locale-gen for:$pChrootDir" chroot_root_execute $pChrootDir "$(which locale-gen)" forceDeps="1" chroot_apt_install $pChrootDir debianutils 2>&1 >> "$pChrootDir/darkcontainer-chroot-apt-stage0_debianutils.log" for subPerl in $packagesPerl;do forceDeps="1" chroot_apt_install $pChrootDir $subPerl 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_perl.log" # chroot_apt_install $pChrootDir $subPerl 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-stage0_perl.log" done rm "$pChrootDir/chroot_apt.lst" # echo "================================================ retry libc6" # forceDeps="1" chroot_apt_install $pChrootDir libc6 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-substage0_libc6.log" # forceDeps="1" chroot_apt_install $pChrootDir multiarch-support 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-substage0_multiarch-support.log" # rm "$pChrootDir/chroot_apt.lst" # echo "================================================ retry libc6" # forceDeps="1" chroot_apt_install $pChrootDir libc6 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-substage1_libc6.log" # forceDeps="1" chroot_apt_install $pChrootDir multiarch-support 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-substage1_multiarch-support.log" # rm "$pChrootDir/chroot_apt.lst" # # forceDeps="1" chroot_apt_install $pChrootDir libcrypt1 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-substage0_libcrypt1.log" # chroot_apt_stage0 $pChrootDir debconf 2>&1 >> "$pChrootDir/darkcontainer-chroot-apt-stage0_debconf.log" # chroot_apt_stage0 $pChrootDir libbz2-1.0 2>&1 >> "$pChrootDir/darkcontainer-chroot-apt-stage0_libbz2-1.0.log" # chroot_apt_stage0 $pChrootDir tar 2>&1 >> "$pChrootDir/darkcontainer-chroot-apt-stage0_dpkg.log" # chroot_apt_stage0 $pChrootDir dpkg 2>&1 >> "$pChrootDir/darkcontainer-chroot-apt-stage0_dpkg.log" # chroot_apt_stage0 $pChrootDir libc6 2>&1 >> "$pChrootDir/darkcontainer-chroot-apt-stage0_libc6.log" # chroot_apt_stage0 $pChrootDir gawk 2>&1 >> "$pChrootDir/darkcontainer-chroot-apt-stage0_gawk.log" # exit 0 # aptNoDeps="1" chroot_apt_stage0 $pChrootDir usrmerge 2>&1 | tee "$pChrootDir/chroot_0stage_install_first_usrmerge.log" # shDebug 1 "find ------ $pChrootDir/usr/lib" # chroot "$pChrootDir" find "/usr/lib/" # aptNoTryInst="1" aptNoDeps="1" chroot_apt_install $pChrootDir usrmerge 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_usrmerge.log" # # chroot_apt_install_manual $pChrootDir "usrmerge" 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_second_usermerge.log" # exit 0 # exit 0 # # ============= ************************ ------------------------- # chroot_apt_install $pChrootDir debconf 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_debconf.log" # chroot_apt_install $pChrootDir libbz2-1.0 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_libbz2-1.0.log" # forceDeps="1" chroot_apt_install $pChrootDir tar 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_dpkg.log" # forceDeps="1" chroot_apt_install $pChrootDir dpkg 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_dpkg.log" # forceDeps="1" chroot_apt_install $pChrootDir libc6 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_libc6.log" # chroot_apt_install $pChrootDir gawk 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_gawk.log" # chroot_apt_install $pChrootDir locales 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_locales.log" # forceDeps="1" chroot_apt_install $pChrootDir dialog 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_dialog.log" # forceDeps="1" chroot_apt_install $pChrootDir coreutils 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_coreutils.log" # forceDeps="1" chroot_apt_install $pChrootDir multiarch-support 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-substage0_multiarch-support.log" for subPerl in $packagesPerl;do forceDeps="1" chroot_apt_install $pChrootDir $subPerl 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_first_perl.log" # chroot_apt_install $pChrootDir $subPerl 2>&1 | tee "$pChrootDir/darkcontainer-chroot-apt-install_first_perl.log" done rm "$pChrootDir/chroot_apt.lst" shDebug 1 "================================== first passe install apt done." shDebug 1 "apt-essential initied for:$pChrootDir" $cmdChroot $pChrootDir perl -MFile::stat -e 'exit 0' && touch $pChrootDir/perl.certified || shDebug 0 "PERL_CORE_MISSING in $pChrootDir" chroot_umount $pChrootDir } chroot_apt_install_withdeps() { local shLog="chroot_apt_install_withdeps" local pChrootDir="$1" local aptToInstall="$2" local aptInstalledList="$pChrootDir/chroot_apt.lst" # local allPaths="$( apt_getDebName "${aptToInstall}" ).deb" local allPaths="" local allDepsApt="" for aptDeps in $( aptDepsListGetDepsInOne="" apt_getDepsInOne "${aptToInstall}" | tr ' ' '\n' | awk '!seen[$0]++' | tr '\n' ' ' );do chroot_apt_install_withdeps $aptDeps allDepsApt="${allDepsApt} $( apt_getDebName "${aptDeps}" )" done # if [ -z "$forceDeps" ];then # allDepsApt="$( aptDepsListGetalldepsInOne="" apt_getmissingdepsInOne "${aptToInstall}" | tr ' ' '\n' | awk '!seen[$0]++' | tr '\n' ' ' )" # else # allDepsApt="$( aptDepsListGetalldepsInOne="" apt_getalldepsInOne "${aptToInstall}" | tr ' ' '\n' | awk '!seen[$0]++' | tr '\n' ' ' )" # fi # for depdsApt in $( aptDepsListGetalldepsInOne="" apt_getmissingdepsInOne "${aptToInstall}" );do # for depdsApt in $( aptDepsListGetalldepsInOne="" apt_getalldepsInOne "${aptToInstall}" | tr ' ' '\n' | awk '!seen[$0]++' | tr '\n' ' ' );do for depdsApt in ${allDepsApt};do [ -z "$depdsApt" ] && continue shDebug 1 "[${aptToInstall}] depdsApt:$depdsApt" local aptDepFound="" [ -z "$forceDeps" ] && for pkgLongInstalled in $( cat "$aptInstalledList" | tr '\n' ' ');do [ "${pkgLongInstalled}" = "${depdsApt}" ] && aptDepFound="1" && break; done if [ -z "${aptDepFound}" ];then shDebug 1 "[${aptToInstall}] add missing dep $depdsApt" allPaths="${depdsApt}.deb $allPaths" # shDebug 1 "add $depdsApt" # echo "${depdsApt}" >> "$aptInstalledList" ## shDebug 1 dpkg-reconfigure ${depdsApt} ## $cmdChroot $pChrootDir ${cmdDpkgReconfigure} ${depdsApt} 2>&1 >> /dev/null fi done if [ -n "$allPaths" ];then # echo all:$allPaths # local oldPwd="$(pwd)" shDebug 2 dpkg -i \$allPaths shDebug 2 "dpkg -i $allPaths" | tee "$pChrootDir/chroot_deps_${aptToInstall}_install.log" $cmdChroot $pChrootDir sh -c "cd /var/cache/apt/archives && dpkg -i $allPaths" 2>&1 | tee "$pChrootDir/chroot_deps_${aptToInstall}_install.log" # cd $oldPwd fi } #chroot_apt_install $pChrootDir $apt chroot_apt_install() { local shLog="chroot_apt_install" local pChrootDir="$1" local aptToInstall="$2" local aptFound="" local aptInstalledFileList="$pChrootDir/darkcontainer-chroot-apt-files.log" local aptInstalledList="$pChrootDir/chroot_apt.lst" local aptInstalledDeps="$pChrootDir/chroot_apt-depends.log" local aptRenstalledList="$pChrootDir/darkcontainer-chroot-apt-reinstall.log" local aptManualLogs="$pChrootDir/logAptManuals" [ ! -d "${aptManualLogs}" ] && mkdir "${aptManualLogs}" [ ! -f "${aptInstalledList}" ] && echo "======= [INIT] =========" >> $aptInstalledList local aptFound="" for pkgLongInstalled in $( cat "$aptInstalledList" | tr '\n' ' ');do [ "${pkgLongInstalled}" = "${aptToInstall}" ] && aptFound="1" && break; done [ -z "${aptFound}" ] && shDebug 1 "add $aptToInstall" && echo "${aptToInstall}" >> "$aptInstalledList" if [ -z "${aptFound}" ] || [ -n "${aptForce}" ];then shDebug 1 "$pChrootDir $aptToInstall" chroot_apt_download "$pChrootDir" "$aptToInstall" [ -z "${aptNoDeps}" ] && for dep in $( apt-cache depends --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances "$aptToInstall" \ | grep -E '^\s*(Dépend:|Depends:|Pré-Dépend:|Pre-Depends:)' | cut -d: -f2 | tr -d ' ' | tr -d '<' | tr -d '>' \ ); do [ -z "${dep}" ] && continue # aptForce="" aptDepsListInstall="${aptDepsListInstall}" chroot_apt_install "$pChrootDir" "$dep" shDebug 1 "install deps for [$aptToInstall]:$dep" chroot_apt_install "$pChrootDir" "$dep" # aptDepsListInstall="${aptDepsListInstall} ${dep}" done [ ! -d "$pChrootDir/debPKG" ] && mkdir "$pChrootDir/debPKG" [ ! -d "$pChrootDir/debPKG/${aptToInstall}" ] && mkdir "$pChrootDir/debPKG/${aptToInstall}" # chroot_install "$pChrootDir" "/usr/bin/which" cp "/bin/which" "$pChrootDir/usr/bin/which" cp "/bin/touch" "$pChrootDir/usr/bin/touch" # 1. Toujours conserver le PATH complet pour les maintainer scripts. #CHROOT_PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' # 2. Tests avant toute configuration de paquet. #$cmdChroot $pChrootDir /usr/bin/sh -c "LIBRARY_PATH=/usr/lib64:/usr/lib:/usr/lib32;export LIBRARY_PATH;PATH=${CHROOT_PATH};export PATH;command -V sh;command -V rmdir;command -V rm;command -V ln;command -V cp;/usr/bin/dpkg --version" || exit 1 debFileName="$( apt_getDebName ${aptToInstall} )" pkgName="$( apt_getPkgName ${aptToInstall} )" if [ -n "${debFileName}" ];then shDebug 0 "[${pkgName}] found for $aptToInstall." $cmdChroot $pChrootDir sh -c "cd /var/cache/apt/archives && dpkg -i ${debFileName}.deb" 2>&1 | tee "$pChrootDir/chroot_dpkg_${aptToInstall}_install.log" fi shDebug 1 "=== configure:dpkg --configure ${aptToInstall}/${pkgName}" # $cmdChroot $pChrootDir /usr/bin/sh -c "LIBRARY_PATH=/usr/lib64:/usr/lib:/usr/lib32;export LIBRARY_PATH;PATH=${CHROOT_PATH};export PATH;exec /usr/bin/dpkg --configure ${aptToInstall}" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-configure" if [ -n "${forceDeps}" ];then $cmdChroot $pChrootDir dpkg --force-depends --configure "${aptToInstall}" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-configure" else $cmdChroot $pChrootDir dpkg --configure "${aptToInstall}" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-configure" fi ## elif [ -z "${aptNoTryInst}" ];then ## shDebug 1 chroot $pChrootDir "${cmdDpkg}" -i /var/cache/apt/archives/${debFileName}.deb 2>&1 >> "$pChrootDir/debPKG/${aptToInstall}.log-inst" ## $cmdChroot $pChrootDir "${cmdDpkg}" -i /var/cache/apt/archives/${debFileName}.deb 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-inst" #$cmdChroot $pChrootDir /usr/bin/sh -c "LIBRARY_PATH=/usr/lib64:/usr/lib:/usr/lib32;export LIBRARY_PATH;PATH=${CHROOT_PATH};export PATH;exec /usr/bin/dpkg -i /var/cache/apt/archives/${debFileName}*.deb" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-dpkginst" # shDebug 1 chroot $pChrootDir /usr/bin/sh -c "LD_LIBRARY_PATH=/usr/lib64:/usr/lib:/usr/lib32; PATH=/usr/sbin:/usr/bin "${cmdDpkg}" --force-depends --configure ${pkgName}" 2>&1 >> "$pChrootDir/debPKG/${aptToInstall}.log-configure" # shDebug 1 "$cmdChroot $pChrootDir dpkg --force-depends --configure ${pkgName}" # 3. Seulement ensuite. #$cmdChroot $pChrootDir /usr/bin/sh -c "LIBRARY_PATH=/usr/lib64:/usr/lib:/usr/lib32;export LIBRARY_PATH;PATH=${CHROOT_PATH};export PATH;exec /usr/bin/dpkg --force-depends --configure ${pkgName}" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-configure" #$cmdChroot $pChrootDir /usr/bin/sh -c "LIBRARY_PATH=/usr/lib64:/usr/lib:/usr/lib32;export LIBRARY_PATH;PATH=${CHROOT_PATH};export PATH;exec /usr/bin/dpkg -i /var/cache/apt/archives/$( apt_getDebName ${aptToInstall} ).deb" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-dpkginst" #$cmdChroot $pChrootDir /usr/bin/sh -c "LIBRARY_PATH=/usr/lib64:/usr/lib:/usr/lib32;export LIBRARY_PATH;PATH=${CHROOT_PATH};export PATH;exec /usr/bin/dpkg --configure ${pkgName}" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-configure" ## $cmdChroot $pChrootDir /usr/bin/sh -c "PATH=/usr/sbin:/usr/bin "${cmdDpkg}" --force-depends --configure ${pkgName}" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-configure" fi chroot_apt_install_withdeps "${pChrootDir}" "${aptToInstall}" previousPwd="$( pwd )" [ -d "$pChrootDir/usr/bin/lib" ] && cd "$pChrootDir/usr/bin/lib" && for badPathFile in $( find "." );do [ -d "$pChrootDir/usr/bin/lib/$badPathFile" ] && continue shDebug 2 correction of "$pChrootDir/usr/bin/lib/$badPathFile" badPathFileFolder="$(echo "$badPathFile" | rev | cut -d/ -f2- | rev )" [ ! -d "$pChrootDir/usr/lib/$badPathFileFolder" ] && echo "-----create dir :$badPathFileFolder" && mkdir -p "$pChrootDir/usr/lib/$badPathFileFolder" #[ -f "$pChrootDir/usr/lib/$badPathFile" ] && rm "$pChrootDir/usr/lib/$badPathFile" mv "$pChrootDir/usr/bin/lib/$badPathFile" "$pChrootDir/usr/lib/$badPathFile" done && rm -R "$pChrootDir/usr/bin/lib" cd "$previousPwd" shDebug 1 dpkg-reconfigure ${aptToInstall} $cmdChroot "$pChrootDir" "${cmdDpkgReconfigure}" ${aptToInstall} 2>&1 | tee "$pChrootDir/chroot_dpkg_${aptToInstall}_reconf.log" } #chroot_apt_stage0 $pChrootDir $apt chroot_apt_stage0() { local shLog="chroot_apt_stage0" local pChrootDir="$1" local aptToInstall="$2" for pkgLongInstalled in $( echo $aptDepsListStage0 | tr 'µ' ' ' | tr '\n' ' ');do [ "$( echo $pkgLongInstalled | tr 'µ' ' ' )" = "${aptToInstall}" ] && aptFound="1" && break; done shDebug 1 "$pChrootDir $aptToInstall" aptDepsListStage0="$aptDepsListStage0 $aptToInstall" # [ -n "$aptFound" ] && return 0 if [ -z "${aptFound}" ] || [ -n "${aptForce}" ];then # if [ -n "${aptFound}" ];then # $cmdEcho "PKG:$aptToInstall ! ever present" # else [ -z "${aptNoDeps}" ] && for dep in $( apt-cache depends --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances "$aptToInstall" \ | grep -E '^\s*(Dépend:|Depends:|Pré-Dépend:|Pre-Depends:)' | cut -d: -f2 | tr -d ' ' | tr -d '<' | tr -d '>' \ ); do aptDepsListStage0="$aptDepsListStage0" aptForce="" chroot_apt_stage0 "$pChrootDir" "$dep" aptDepsListStage0="$aptDepsListStage0 $dep" done [ ! -d "$pChrootDir/debPKG" ] && mkdir "$pChrootDir/debPKG" [ ! -d "$pChrootDir/debPKG/${aptToInstall}" ] && mkdir "$pChrootDir/debPKG/${aptToInstall}" apt_download "$pChrootDir" "$aptToInstall" # echo chroot $pChrootDir "${cmdDpkg}" --force-depends --unpack /var/cache/apt/archives/${debFileName}.deb 2>&1 >> "$pChrootDir/debPKG/${aptToInstall}.log-unpack" $cmdChroot $pChrootDir "${cmdDpkg}" --force-depends --unpack /var/cache/apt/archives/${debFileName}.deb 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-unpack" dpkg-deb -x "$pChrootDir/var/cache/apt/archives/${debFileName}.deb" "$pChrootDir" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log-unpack" fi } chroot_apt_install_manual() { local pChrootDir="$1" local aptToInstall="$2" local aptInstalledFileList="$pChrootDir/darkcontainer-chroot-apt-manual_files.log" local aptInstalledList="$pChrootDir/chroot_apt_manual.lst" local aptInstalledDeps="$pChrootDir/chroot_apt_manual-depends.log" local aptRenstalledList="$pChrootDir/darkcontainer-chroot-apt-reinstall.log" local aptManualLogs="$pChrootDir/logAptManuals" [ ! -d "${aptManualLogs}" ] && mkdir "${aptManualLogs}" [ ! -f "${aptInstalledList}" ] && echo "======= [INIT] =========" >> $aptInstalledList local aptFound="" for pkgLongInstalled in $( cat $aptInstalledList | tr 'µ' ' ' | tr '\n' ' ');do [ "$( echo $pkgLongInstalled | tr 'µ' ' ' )" = "${aptToInstall}" ] && aptFound="1" && break; done if [ -z "${aptFound}" ];then # if [ -n "${aptFound}" ];then # $cmdEcho "PKG:$aptToInstall ! ever present" # else # if [ -z "$( cat $aptInstalledList | grep \"^${aptToInstall}$\" )" ];then echo "$aptToInstall" >> $aptInstalledList for dep in $( apt-cache depends --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances "$aptToInstall" \ | grep -E '^\s*(Dépend:|Depends:|Pré-Dépend:|Pre-Depends:)' | cut -d: -f2 | tr -d ' ' | tr -d '<' | tr -d '>' \ ); do echo "$dep" >> "${aptInstalledList}-dep" chroot_apt_install_manual "$pChrootDir" "$dep" done # sh $rootDarkMake/pkg/bin/aptCheck $packageToInstall >> $aptRenstalledList 2>&1 ## apt-get --allow-unauthenticated --assume-yes --reinstall install $aptToInstall >> $aptRenstalledList 2>&1 ## for packageDep in $( apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances $aptToInstall | grep "^\w" | tr ' ' 'µ' );do ## chroot_apt_install $pChrootDir $(echo $packageDep | tr 'µ' ' ' ) ## done echo "=== manual $aptToInstall" | tee $aptInstalledFileList [ ! -d "$pChrootDir/debPKG" ] && mkdir "$pChrootDir/debPKG" [ ! -d "$pChrootDir/debPKG/${aptToInstall}" ] && mkdir "$pChrootDir/debPKG/${aptToInstall}" [ ! -d "$pChrootDir/var/cache/apt/archives" ] && mkdir -p "$pChrootDir/var/cache/apt/archives" debFileName="$(apt_getDebName "$aptToInstall")" # HERE DOWNLOAD echo chroot_root_execute $pChrootDir "dpkg --unpack /var/cache/apt/archives/${debFileName}.deb 2>&1" >> "$pChrootDir/debPKG/${aptToInstall}.log-unpack" chroot_root_execute $pChrootDir "dpkg --unpack /var/cache/apt/archives/${debFileName}.deb 2>&1" >> "$pChrootDir/debPKG/${aptToInstall}.log-unpack" # apt-file list "$aptToInstall" | cut -d: -f2- | while read -r fileToInstall; do # # ignorer lignes vides # [ -z "$fileToInstall" ] && continue # echo "${fileToInstall}" >> "${aptManualLogs}/${aptToInstall}.log" # # tout le reste : ta logique actuelle # if [ ! -f "${pChrootDir}/${fileToInstall}" ] && [ ! -L "${pChrootDir}/${fileToInstall}" ] && ( [ -f "$fileToInstall" ] || [ -L "$fileToInstall" ] ) ; then # chroot_install "$pChrootDir" "$fileToInstall" # else # [ ! -f "$fileToInstall" ] && [ ! -d "$fileToInstall" ] && [ ! -L "$fileToInstall" ] && $cmdEcho "missing:${fileToInstall}" >> "${aptManualLogs}/${aptToInstall}.log" # fi # done fi } #chroot_apt_download $pChrootDir $apt chroot_apt_download() { local pChrootDir="$1" local aptToInstall="$2" [ -z "${aptToInstall}" ] && return ; [ ! -d "$pChrootDir/var/cache/apt/archives" ] && mkdir -p "$pChrootDir/var/cache/apt/archives" cd "$pChrootDir/var/cache/apt/archives" debFileName="$( apt_getDebName ${aptToInstall} )" if [ -f "/var/cache/apt/archives/${debFileName}.deb" ];then shDebug 1 "=== cp "${debFileName}.deb"" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log" cp "/var/cache/apt/archives/${debFileName}.deb" "$pChrootDir/var/cache/apt/archives" elif [ -f "/var/cache/apt/archives/$(echo ${debFileName} | sed 's/:/%3a/g').deb" ];then shDebug 1 "=== cp convert ':' to '%3a' "$(echo ${debFileName} | sed 's/:/%3a/g').deb"" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log" cp "/var/cache/apt/archives/$(echo ${debFileName} | sed 's/:/%3a/g').deb" "$pChrootDir/var/cache/apt/archives" else shDebug 1 "=== download "${debFileName}.deb"" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log" apt_download "$aptToInstall" 2>&1 >> "$pChrootDir/debPKG/${aptToInstall}.log-download" # [ -f "$pChrootDir/var/cache/apt/archives/${debFileName}.deb" ] && cp "$pChrootDir/var/cache/apt/archives/${debFileName}.deb" "/var/cache/apt/archives/" shDebug 1 "=== cp "${debFileName}.deb"" 2>&1 | tee "$pChrootDir/debPKG/${aptToInstall}.log" fi # chown -R _apt "$pChrootDir/var/cache/apt/archives" # chown -R _apt "/var/cache/apt/archives" #$cmdChroot $pChrootDir $cmdChown -R _apt:nogroup "/var/cache/apt/archives" }