mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-11-14 23:43:56 +01:00
tests: cleanup image cleanup script.
This commit is contained in:
parent
7bd500b979
commit
a1ce144e1c
@ -6,7 +6,10 @@
|
|||||||
set -u
|
set -u
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
_lsb_release() { . /etc/os-release || exit 1; echo "$ID"; }
|
_lsb_release() {
|
||||||
|
. /etc/os-release || exit 1
|
||||||
|
echo "$ID"
|
||||||
|
}
|
||||||
DISTRIBUTION="$(_lsb_release)"
|
DISTRIBUTION="$(_lsb_release)"
|
||||||
readonly SELF="$0"
|
readonly SELF="$0"
|
||||||
readonly DISTRIBUTION
|
readonly DISTRIBUTION
|
||||||
@ -127,12 +130,9 @@ impersonalize() {
|
|||||||
rm -rf "${remove[@]}"
|
rm -rf "${remove[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Free all unused storage block.
|
# Free all unused storage block.
|
||||||
trim() {
|
trim() {
|
||||||
local swapuuid swappart max size
|
local swapuuid swappart
|
||||||
max=11811160064 # Maximum size to reduce filesystem in RAM (11G)
|
|
||||||
size=$(_disksize)
|
|
||||||
|
|
||||||
if swapuuid=$(blkid -o value -l -s UUID -t TYPE=swap); then
|
if swapuuid=$(blkid -o value -l -s UUID -t TYPE=swap); then
|
||||||
swappart=$(readlink -f /dev/disk/by-uuid/"$swapuuid")
|
swappart=$(readlink -f /dev/disk/by-uuid/"$swapuuid")
|
||||||
@ -140,16 +140,14 @@ trim() {
|
|||||||
swapoff "$swappart"
|
swapoff "$swappart"
|
||||||
dd if=/dev/zero of="$swappart" bs=1M || true
|
dd if=/dev/zero of="$swappart" bs=1M || true
|
||||||
mkswap -U "$swapuuid" "$swappart"
|
mkswap -U "$swapuuid" "$swappart"
|
||||||
elif [[ -f /swap/swapfile ]];then
|
elif [[ -f /swap/swapfile ]]; then
|
||||||
swapoff /swap/swapfile
|
swapoff /swap/swapfile
|
||||||
truncate --size=0 /swap/swapfile
|
truncate --size=0 /swap/swapfile
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$size" -lt "$max" ]]; then
|
_msg "Fill root filesystem with 0 to reduce box size"
|
||||||
_msg "Fill root filesystem with 0 to reduce box size"
|
dd if=/dev/zero of=/EMPTY bs=1M || true
|
||||||
dd if=/dev/zero of=/EMPTY bs=1M || true
|
rm -f /EMPTY
|
||||||
rm -f /EMPTY
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Block until the empty file has been removed, otherwise, Packer will
|
# Block until the empty file has been removed, otherwise, Packer will
|
||||||
# try to kill the box while the disk is still full and that is bad.
|
# try to kill the box while the disk is still full and that is bad.
|
||||||
@ -160,7 +158,7 @@ main() {
|
|||||||
local begin end
|
local begin end
|
||||||
begin=$(_diskused)
|
begin=$(_diskused)
|
||||||
case "$DISTRIBUTION" in
|
case "$DISTRIBUTION" in
|
||||||
debian | ubuntu )
|
debian | ubuntu)
|
||||||
clean_debian
|
clean_debian
|
||||||
_sshdgenkeys
|
_sshdgenkeys
|
||||||
;;
|
;;
|
||||||
|
@ -4,10 +4,6 @@
|
|||||||
|
|
||||||
packer {
|
packer {
|
||||||
required_plugins {
|
required_plugins {
|
||||||
ansible = {
|
|
||||||
source = "github.com/hashicorp/ansible"
|
|
||||||
version = "~> 1"
|
|
||||||
}
|
|
||||||
qemu = {
|
qemu = {
|
||||||
source = "github.com/hashicorp/qemu"
|
source = "github.com/hashicorp/qemu"
|
||||||
version = "~> 1"
|
version = "~> 1"
|
||||||
|
Loading…
Reference in New Issue
Block a user