2020-11-21 01:52:02 +08:00
|
|
|
|
#!/usr/bin/env bash
|
2017-03-07 09:32:55 +08:00
|
|
|
|
set -e
|
2020-11-21 01:52:02 +08:00
|
|
|
|
set -x
|
2017-03-07 23:41:52 +08:00
|
|
|
|
: "[1m Build a temporary directory; make sure ocid is running.[0m"
|
2017-03-07 09:32:55 +08:00
|
|
|
|
export PATH=`pwd`:$PATH
|
|
|
|
|
d=`mktemp -d`
|
|
|
|
|
trap 'cd /;rm -fr "$d"' EXIT
|
|
|
|
|
cd "$d"
|
|
|
|
|
systemctl restart ocid
|
|
|
|
|
read
|
|
|
|
|
: "[1m Check if we have some images to work with.[0m"
|
2017-03-07 23:41:52 +08:00
|
|
|
|
read
|
2017-03-07 09:32:55 +08:00
|
|
|
|
ocic image list
|
|
|
|
|
read
|
|
|
|
|
: "[1m Create a working container, and capture its name [0m"
|
|
|
|
|
read
|
2017-03-28 23:23:43 +08:00
|
|
|
|
echo '[container1=`buildah from ${1:-alpine}`]'
|
|
|
|
|
container1=`buildah from ${1:-alpine}`
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
|
|
|
|
: "[1m Mount that working container, and capture the mountpoint [0m"
|
|
|
|
|
read
|
2017-03-25 00:49:22 +08:00
|
|
|
|
echo '[mountpoint1=`buildah mount $container1`]'
|
|
|
|
|
mountpoint1=`buildah mount $container1`
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
2017-03-07 23:41:52 +08:00
|
|
|
|
: "[1m List random files in the container [0m"
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
|
|
|
|
echo '[find $mountpoint1 -name "random*"]'
|
|
|
|
|
find $mountpoint1 -name "random*"
|
|
|
|
|
read
|
2017-03-07 23:41:52 +08:00
|
|
|
|
: "[1m Ensure the default destination for copying files is / [0m"
|
|
|
|
|
read
|
2017-03-25 00:49:22 +08:00
|
|
|
|
echo '[buildah config $container1 --workingdir /]'
|
|
|
|
|
buildah config $container1 --workingdir /
|
2017-03-07 23:41:52 +08:00
|
|
|
|
read
|
2017-03-07 09:32:55 +08:00
|
|
|
|
: "[1m Add a file to the container [0m"
|
|
|
|
|
read
|
|
|
|
|
echo '[dd if=/dev/urandom of=random1 bs=512 count=1]'
|
2017-03-25 00:49:22 +08:00
|
|
|
|
echo '[buildah copy $container1 random1]'
|
2017-03-07 23:41:52 +08:00
|
|
|
|
dd if=/dev/urandom of=random1 bs=512 count=1
|
2017-03-25 00:49:22 +08:00
|
|
|
|
buildah copy $container1 random1
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
|
|
|
|
: "[1m Change the default destination for copying files [0m"
|
|
|
|
|
read
|
2017-03-25 00:49:22 +08:00
|
|
|
|
echo '[buildah config $container1 --workingdir /tmp]'
|
|
|
|
|
buildah config $container1 --workingdir /tmp
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
|
|
|
|
: "[1m Add another new file to the container [0m"
|
|
|
|
|
read
|
|
|
|
|
echo '[dd if=/dev/urandom of=random2 bs=512 count=1]'
|
2017-03-25 00:49:22 +08:00
|
|
|
|
echo '[buildah copy $container1 random2]'
|
2017-03-07 23:41:52 +08:00
|
|
|
|
dd if=/dev/urandom of=random2 bs=512 count=1
|
2017-03-25 00:49:22 +08:00
|
|
|
|
buildah copy $container1 random2
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
2017-03-07 23:41:52 +08:00
|
|
|
|
: "[1m Copy a subdirectory with some files in it [0m"
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
|
|
|
|
echo '[mkdir -p randomsubdir]'
|
|
|
|
|
echo '[dd if=/dev/urandom of=randomsubdir/random3 bs=512 count=1]'
|
|
|
|
|
echo '[dd if=/dev/urandom of=randomsubdir/random4 bs=512 count=1]'
|
2017-03-25 00:49:22 +08:00
|
|
|
|
echo '[buildah copy $container1 randomsubdir]'
|
2017-03-07 09:32:55 +08:00
|
|
|
|
mkdir -p randomsubdir
|
|
|
|
|
dd if=/dev/urandom of=randomsubdir/random3 bs=512 count=1
|
|
|
|
|
dd if=/dev/urandom of=randomsubdir/random4 bs=512 count=1
|
2017-03-25 00:49:22 +08:00
|
|
|
|
buildah copy $container1 randomsubdir
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
|
|
|
|
: "[1m List some of the container's contents [0m"
|
|
|
|
|
read
|
|
|
|
|
echo '[find $mountpoint1 -name "random*"]'
|
|
|
|
|
find $mountpoint1 -name "random*"
|
|
|
|
|
read
|
2017-03-07 23:41:52 +08:00
|
|
|
|
: "[1m Download a tarball [0m"
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
|
|
|
|
echo '[wget -c https://releases.pagure.org/tmpwatch/tmpwatch-2.9.17.tar.bz2]'
|
|
|
|
|
wget -c https://releases.pagure.org/tmpwatch/tmpwatch-2.9.17.tar.bz2
|
|
|
|
|
read
|
2017-03-07 23:41:52 +08:00
|
|
|
|
: "[1m Copy that tarball to the container [0m"
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
|
|
|
|
echo '[mkdir -p $mountpoint1/tmpwatch]'
|
2017-03-25 00:49:22 +08:00
|
|
|
|
echo '[buildah copy $container1 --dest /tmpwatch tmpwatch-2.9.17.tar.bz2]'
|
2017-03-07 09:32:55 +08:00
|
|
|
|
mkdir -p $mountpoint1/tmpwatch
|
2017-03-25 00:49:22 +08:00
|
|
|
|
buildah copy $container1 --dest /tmpwatch tmpwatch-2.9.17.tar.bz2
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
2017-03-07 23:41:52 +08:00
|
|
|
|
: "[1m Download another tarball to the container [0m"
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
2017-03-25 00:49:22 +08:00
|
|
|
|
echo '[buildah copy $container1 --dest /tmpwatch https://releases.pagure.org/newt/newt-0.52.19.tar.gz]'
|
|
|
|
|
buildah copy $container1 --dest /tmpwatch https://releases.pagure.org/newt/newt-0.52.19.tar.gz
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
2017-03-07 23:41:52 +08:00
|
|
|
|
: "[1m List the contents of the target directory [0m"
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
|
|
|
|
echo '[find $mountpoint1/tmpwatch]'
|
|
|
|
|
find $mountpoint1/tmpwatch
|
|
|
|
|
read
|
2017-03-07 23:41:52 +08:00
|
|
|
|
: "[1m Now 'add' the downloaded tarball to the container [0m"
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
2017-03-25 00:49:22 +08:00
|
|
|
|
echo '[buildah add $container1 --dest /tmpwatch tmpwatch-2.9.17.tar.bz2]'
|
|
|
|
|
buildah add $container1 --dest /tmpwatch tmpwatch-2.9.17.tar.bz2
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
2017-03-07 23:41:52 +08:00
|
|
|
|
: "[1m List the contents of the target directory again [0m"
|
2017-03-07 09:32:55 +08:00
|
|
|
|
read
|
|
|
|
|
echo '[find $mountpoint1/tmpwatch]'
|
|
|
|
|
find $mountpoint1/tmpwatch
|
|
|
|
|
read
|
|
|
|
|
: "[1m Clean up, because I ran this like fifty times while testing [0m"
|
|
|
|
|
read
|
2017-03-25 00:49:22 +08:00
|
|
|
|
echo '[buildah delete $container1]'
|
2017-03-24 04:45:35 +08:00
|
|
|
|
buildah rm $container1
|