11 EXIT_COMMAND_NOT_FOUND
=127
26 echo "[${level}] ${message}"
33 log DEBUG
"Running command: ${cmd}"
43 log DEBUG
"Returned with code '${ret}'"
52 umount
${IMAGE_MOUNT_DIR}
54 # Remove partition from the kernel table.
57 # Remove loopback device
62 # Cleanup Config file for the local repo
63 if [ -f "${LOCAL_REPO_FILE}" ]; then
64 rm -f "${LOCAL_REPO_FILE}"
71 if [ -d "${WORKING_DIR}" ]; then
72 rm -dfR "${WORKING_DIR}"
81 generate_image_filename
() {
86 echo "${distro}-${version}-${arch}"
93 # Check that pakfire-server binary is available
94 # Check that pakfire binary is available
96 # Check that repo files are installed. (pakfire need to know which repos exist)
97 local repo_dir
="/etc/pakfire/repos"
99 if [ ! -d "${repo_dir}" ]; then
100 log ERROR
"Could not find respository directory ${repo_dir}"
104 return ${return_value}
108 local compression
=${1}
109 local image_file
=${2}
112 log debug
"Compressing ${image_file} with ${compression}"
114 case "${compression}" in
116 # Check that the file does not exist yet
117 if [ -f "${image_file}.xz" ]; then
118 log ERROR
"Failed to compress the image. The file already exists"
121 cmd xz
"-${level}" "${image_file}"
124 # Check that the file does not exist yet
125 if [ -f "${image_file}.zip" ]; then
126 log ERROR
"Failed to compress the image. The file already exists"
130 cmd
zip "-${level}" "${image_file}.zip" "${image_file}"
131 # Remove the file which we compressed+
132 rm -f "${image_file}"
138 reset_root_password
() {
141 cp -avf ${root_dir}/etc
/passwd
${root_dir}/etc
/passwd.orig
143 # Drop root password.
144 sed -e "s/^\(root:\)[^:]*:/\1:/" ${root_dir}/etc
/passwd.orig
> ${root_dir}/etc
/passwd
146 # Remove passwd backup file.
147 rm -rvf ${root_dir}/etc
/passwd.orig
151 # Dir where the repos should be located
162 # Clone git repositories.
163 for repo
in ${repos}; do
169 # This function is used to publish the produced images
173 # The image we created usually a img. file
174 local image_base_file
=${2}
176 local image_name_final
="$(generate_image_filename "${DISTRO}" "${VERSION}" "${ARCH}")"
179 # Do these steps for every image format we like to publish
180 for image_type
in ${IMAGE_TYPES_PUBLISH}; do
181 # Convert images to the type specified in IMAGE_TYPES_PUBLISH
182 convert_image
"${image_type}" "${image_base_file}" "${image_name_final}"
185 if [[ ${IMAGE_RELEASE} -eq ${TRUE} ]]; then
186 local compression_type
187 local compression_level
190 # Get compressioon type
191 compression_type
="$(get_compression_type ${image_type})"
194 compress_image
"${compression_type}" "${image_name_final}.${image_type}" ${compression_level}
196 # Move images to this path
197 mv -f "${image_name_final}.${image_type}.${compression_type}" ${path}
199 # point the latest links to these images
200 ln -s -f "${path}/${image_name_final}.${image_type}.${compression_type}" \
201 "${path}/$(generate_image_filename "${DISTRO}" "latest" "${ARCH}").${image_type}.${compression_type}"
204 # Move images to this path
205 mv -f "${image_name_final}.${image_type}" ${path}
216 if [[ ${type} = "img
" ]]; then
217 # We do not need to convert the image here but we need to rename
218 mv -f ${from} ${to}.${type}
222 if [[ ${type} = "qcow2
" ]]; then
223 local command="qemu-img convert
-c -O ${type} ${from} ${to}.${type}"
225 local command="qemu-img convert
-O ${type} ${from} ${to}.${type}"
231 get_compression_type() {
232 local image_type=${1}
234 case "${image_type}" in
236 # These types can be used only under Unix so we use xz as compression
240 # These types can be also under Windows so we use zip as compression
247 check_for_free_space() {
250 local space_in_path=0
252 space_in_path=$(df -h -B MB --output=avail ${path} | tail -n 1)
253 space_in_path=${space_in_path%MB}
254 log debug ${space_in_path}
257 if [ ${space_in_path} -lt ${space} ]; then
258 log error "Not enough free space available under
${path}"
259 log error "Free space is
${space_in_path}MB but we need
at least
${space}MB
"
265 while [ $# -gt 0 ]; do
268 IMAGE_RELEASE=${TRUE}
272 error "Invalid argument
: ${1}"
273 return ${EXIT_CONF_ERROR}