LINUX.ORG.RU
решено ФорумAdmin

Как исправить hook?

 , , ,


1

1

cat apt.conf.d/80upgradehook

DPkg::Post-Invoke {"/etc/apt/myhook/docker.sh";};

root@debian-home:/etc/apt# cat myhook/docker.sh

function update_docker(){
        local r="ExecStart=\/usr\/bin\/dockerd \-H fd:\/\/ --containerd=\/run\/containerd\/containerd.sock"  # old
        local u="ExecStart=\/usr\/bin\/dockerd -g \/home\/docker_containers -H unix:\/\/"   # new
        local f="/lib/systemd/system/docker.service" # config file
        local wrcmd="systemctl daemon-reload"    # restart services
        local prcmd1="if [[ -f /etc/init.d/docker ]];then /etc/init.d/docker restart;fi"
        local prcmd2="if [[ -f /var/run/docker.sock ]];then chmod 666 /var/run/docker.sock;fi"
        local prcmd3="if [[ -f ${f} ]];then sed -i -e \"s/${r}/${u}/g\";fi"
        # patch it
        echo "$0: Patching $f..."
        # sed -i "s/$r/$u/g" $f
        #if [[ -f ${f} ]];then sed -i -e "s/${r}/${u}/g" ${f};fi
        # restart it
        ${wrcmd}
        ${prcmd3}
        ${prcmd1}
        ${prcmd2}

}

#docker_install
update_docker

Пишет, что не может найти команду if. Запускается всё это через ansible

Ответ на: комментарий от constin

root@debian-home:/home/user# apt-get remove –purge -y docker-ce

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  cgroupfs-mount containerd.io docker-ce-cli
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  docker-ce* docker-ce-rootless-extras*
0 upgraded, 0 newly installed, 2 to remove and 1 not upgraded.
After this operation, 146 MB disk space will be freed.
(Reading database ... 115488 files and directories currently installed.)
Removing docker-ce-rootless-extras (5:20.10.2~3-0~debian-buster) ...
Removing docker-ce (5:20.10.2~3-0~debian-buster) ...
Warning: Stopping docker.service, but it can still be activated by:
  docker.socket
(Reading database ... 115474 files and directories currently installed.)
Purging configuration files for docker-ce (5:20.10.2~3-0~debian-buster) ...
Processing triggers for systemd (241-7~deb10u5) ...
/etc/apt/myhook/docker.sh: Patching /lib/systemd/system/docker.service...
/etc/apt/myhook/docker.sh: line 26: systemctl daemon-reload: command not found
/etc/apt/myhook/docker.sh: line 27: if [[ -f /lib/systemd/system/docker.service ]];then sed -i -e "s/ExecStart=\/usr\/bin\/dockerd \-H fd:\/\/ --containerd=\/run\/containerd\/containerd.sock/ExecStart=\/usr\/bin\/dockerd -g \/home\/docker_containers -H unix:\/\//g";fi: No such file or directory
/etc/apt/myhook/docker.sh: line 28: if [[ -f /etc/init.d/docker ]];then /etc/init.d/docker restart;fi: No such file or directory
/etc/apt/myhook/docker.sh: line 29: if [[ -f /var/run/docker.sock ]];then chmod 666 /var/run/docker.sock;fi: No such file or directory
E: Problem executing scripts DPkg::Post-Invoke '/etc/apt/myhook/docker.sh'
E: Sub-process returned an error code
serg002 ()
Ответ на: комментарий от serg002

тогда

eval $prcmd3

или


bash -c "$prcmd3"

это точно будет работать

но правильнее запихать эти команды в функции. или же вообще сразу там писать команды , вместо переменных

constin ★★★★ ()