cleanup_after_failure () {
cleanup
- if [ -f ${IMAGE_FILE_NAME} ]; then
- rm -f ${IMAGE_FILE_NAME}
+ if [ -f ${IMAGE_BASE_FILE} ]; then
+ rm -f ${IMAGE_BASE_FILE}
fi
}
generate_image_filename() {
local distro=${1}
local version=${2}
- local file_type=${3}
- local arch=${4}
+ local arch=${3}
- echo "${distro}-${version}-${arch}.${file_type}"
+ echo "${distro}-${version}-${arch}"
}
check_for_pakfire() {
publish() {
local path=${1}
# The image we created usually a img. file
- local base_image_file_name=${2}
+ local image_base_file=${2}
- #
- # TODO
- #
- # Maybe we should set the finally name here?
- local image_file_name=${base_image_file_name%.*}
+ local image_name_final="$(generate_image_filename "${DISTRO}" "${VERSION}" "${ARCH}")"
- local type
+ local image_type
local compression_type
# Do these steps for every image format we like to publish
- for type in ${IMAGE_TYPES_PUBLISH}; do
+ for image_type in ${IMAGE_TYPES_PUBLISH}; do
# Get compressioon type
- compression_type="$(get_compression_type ${type})"
+ compression_type="$(get_compression_type ${image_type})"
# Convert images to the type specified in IMAGE_TYPES_PUBLISH
- convert_image "${type}" "${base_image_file_name}" "${image_file_name}"
+ convert_image "${image_type}" "${image_base_file}" "${image_name_final}"
# compress image.
- compress_image "${compression_type}" "${image_file_name}.${type}" "1"
+ compress_image "${compression_type}" "${image_name_final}.${image_type}" "1"
# Move images to this path
- mv -f "${image_file_name}.${type}.${compression_type}" ${path}
+ mv -f "${image_name_final}.${image_type}.${compression_type}" ${path}
# point the latest links to these images
- ln -s -f "${path}/${image_file_name}.${type}.${compression_type}" "${path}/$(generate_image_filename "${DISTRO}" "latest" "${type}" "${ARCH}").${compression_type}"
+ ln -s -f "${path}/${image_name_final}.${image_type}.${compression_type}" \
+ "${path}/$(generate_image_filename "${DISTRO}" "latest" "${ARCH}").${image_type}.${compression_type}"
done
local to=${3}
if [[ ${type} = "img" ]]; then
- return 0
+ # We do not need to convert the image here but we need to rename
+ mv -f ${from} ${to}.${type}
fi
if [[ ${type} = "qcow2" ]]; then
ARCH="x86_64"
DISTRO="ipfire3"
VERSION="$(date +"%Y%m%d")"
+WORKING_DIR=$(mktemp -d /tmp/ipfire3_image.XXXXXXXX)
+
+log DEBUG "Working dir is ${WORKING_DIR}"
#
# Image
#
IMAGE_TYPE="img"
-IMAGE_FILE_NAME="$(generate_image_filename "${DISTRO}" "${VERSION}" "${IMAGE_TYPE}" "${ARCH}")"
+IMAGE_BASE_FILE="$(mktemp -u ${WORKING_DIR}/image_base_file.XXXXXXX.img)"
IMAGE_SIZE="8196"
-IMAGE_MOUNT_DIR="$(mktemp -d /tmp/image.XXXXXXX)"
+IMAGE_MOUNT_DIR="$(mktemp -d ${WORKING_DIR}/image.XXXXXXX)"
IMAGE_TYPES_PUBLISH="qcow2 vmdk vdi img"
LOCAL_REPO_SOURCE_PATH="/var/lib/pakfire/local/"
# Path were the local repo is created
-LOCAL_REPO_DIR="$(mktemp -d /tmp/ipfire-repo.XXXXXXX)"
+LOCAL_REPO_DIR="$(mktemp -d ${WORKING_DIR}/ipfire-repo.XXXXXXX)"
# Config file for the local repo
LOCAL_REPO_FILE="/etc/pakfire/repos/local.repo"
# Check that the image does not exist yet
-if [ -f ${IMAGE_FILE_NAME} ]; then
+if [ -f ${IMAGE_BASE_FILE} ]; then
log ERROR "Image file does already exists"
exit 1
fi
exit 1
fi
+# cd into working directory
+cd ${WORKING_DIR} || exit ${EXIT_ERROR}
+
#
## Create the disk image.
#
-dd if=/dev/zero of=${IMAGE_FILE_NAME} seek=${IMAGE_SIZE}MB count=1k bs=1
+dd if=/dev/zero of=${IMAGE_BASE_FILE} seek=${IMAGE_SIZE}MB count=1k bs=1
# Setup the loopback device.
-outlo=`losetup -f --show ${IMAGE_FILE_NAME}`
+outlo=`losetup -f --show ${IMAGE_BASE_FILE}`
log INFO "Create partions and filesystem"
# Cleanup
cleanup
-publish "/home/jschlag/public/ipfire3-images" "${IMAGE_FILE_NAME}"
+publish "/home/jschlag/public/ipfire3-images" "${IMAGE_BASE_FILE}"
-#compress_image "xz" "${IMAGE_FILE_NAME}"
+#compress_image "xz" "${IMAGE_BASE_FILE}"