apt: add a script to manage packages with "hold" mark
parent
e40aefb4e0
commit
7cc1777cf5
@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
is_held() {
|
||||
package=$1
|
||||
|
||||
apt-mark showhold ${package} | grep --silent ${package}
|
||||
}
|
||||
|
||||
config_file="/etc/evolinux/apt_hold_packages.cf"
|
||||
return_code=0
|
||||
|
||||
if [ -f ${config_file} ]; then
|
||||
packages="$(cat ${config_file})"
|
||||
|
||||
if [ -n "${packages}" ]; then
|
||||
for package in ${packages}; do
|
||||
if [ -n "${package}" ]; then
|
||||
if ! is_held ${package}; then
|
||||
apt-mark hold ${package}
|
||||
>&2 echo "Package \`${package}' has been marked \`hold'."
|
||||
return_code=1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
exit ${return_code}
|
@ -0,0 +1,49 @@
|
||||
---
|
||||
|
||||
- name: "hold packages (apt)"
|
||||
shell: "(apt-mark showhold | grep --quiet {{ item }}) || apt-mark hold {{ item }}"
|
||||
register: apt_mark
|
||||
changed_when: "'{{ item }} set on hold.' in apt_mark.stdout"
|
||||
with_items: "{{ apt_hold_packages }}"
|
||||
|
||||
- name: "hold packages (config)"
|
||||
lineinfile:
|
||||
dest: /etc/evolinux/apt_hold_packages.cf
|
||||
line: "{{ item }}"
|
||||
create: True
|
||||
state: present
|
||||
with_items: "{{ apt_hold_packages }}"
|
||||
|
||||
- name: "unhold packages (apt)"
|
||||
shell: "(apt-mark showhold | grep --quiet {{ item }}) && apt-mark unhold {{ item }}"
|
||||
register: apt_mark
|
||||
changed_when: "'Canceled hold on {{ item }}.' in apt_mark.stdout"
|
||||
with_items: "{{ apt_unhold_packages }}"
|
||||
|
||||
- name: "unhold packages (config)"
|
||||
lineinfile:
|
||||
dest: /etc/evolinux/apt_hold_packages.cf
|
||||
line: "{{ item }}"
|
||||
create: True
|
||||
state: absent
|
||||
with_items: "{{ apt_unhold_packages }}"
|
||||
|
||||
- name: Check scripts is installed
|
||||
copy:
|
||||
src: check_held_packages.sh
|
||||
dest: /usr/share/scripts/check_held_packages.sh
|
||||
force: yes
|
||||
mode: "0755"
|
||||
|
||||
- name: Check for held packages (script)
|
||||
cron:
|
||||
cron_file: apt-hold-packages
|
||||
name: check_held_packages
|
||||
job: "/usr/share/scripts/check_held_packages.sh"
|
||||
user: root
|
||||
minute: "{{ apt_check_hold_cron_minute }}"
|
||||
hour: "{{ apt_check_hold_cron_hour }}"
|
||||
weekday: "{{ apt_check_hold_cron_weekday }}"
|
||||
day: "{{ apt_check_hold_cron_day }}"
|
||||
month: "{{ apt_check_hold_cron_month }}"
|
||||
state: "present"
|
Loading…
Reference in New Issue