Skip to content

Commit

Permalink
Merge pull request mendersoftware#4 from lluiscampos/update_modules_r…
Browse files Browse the repository at this point in the history
…emove_jq_dep

Update Modules: remove jq dependency
  • Loading branch information
kacf authored Mar 4, 2019
2 parents 35f539c + 51b6712 commit 3d967d7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 28 deletions.
26 changes: 18 additions & 8 deletions support/modules-artifact-gen/docker-artifact-gen
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Usage: $0 [options] IMAGE [IMAGES...]
EOF
}

show_help_and_exit_error() {
show_help
exit 1
}

check_dependency() {
hash "$1" || exit 1
}
Expand All @@ -37,14 +42,23 @@ IMAGES=""
while (( "$#" )); do
case "$1" in
--device-type | -t)
if [ -z "$2" ]; then
show_help_and_exit_error
fi
device_type=$2
shift 2
;;
--artifact-name | -n)
if [ -z "$2" ]; then
show_help_and_exit_error
fi
artifact_name=$2
shift 2
;;
--output-path | -o)
if [ -z "$2" ]; then
show_help_and_exit_error
fi
output_path=$2
shift 2
;;
Expand All @@ -54,8 +68,7 @@ while (( "$#" )); do
;;
-*)
echo "Error: unsupported option $1"
show_help
exit 1
show_help_and_exit_error
;;
*)
IMAGES="$IMAGES $1"
Expand All @@ -66,20 +79,17 @@ done

if [ -z "${artifact_name}" ]; then
echo "Artifact name not specified. Aborting."
show_help
exit 1
show_help_and_exit_error
fi

if [ -z "${device_type}" ]; then
echo "Device type not specified. Aborting."
show_help
exit 1
show_help_and_exit_error
fi

if [ -z "${IMAGES}" ]; then
echo "At least one Docker image must be specified. Aborting."
show_help
exit 1
show_help_and_exit_error
fi

HASHES=""
Expand Down
46 changes: 28 additions & 18 deletions support/modules-artifact-gen/file-install-artifact-gen
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,52 @@ Usage: $0 [options] file-tree
EOF
}

show_help_and_exit_error() {
show_help
exit 1
}

check_dependency() {
hash "$1" || exit 1
}

check_dependency mender-artifact
check_dependency jq

device_type=""
artifact_name=""
dest_dir=""
output_path="file-install-artifact.mender"
meta_data_file="meta-data.json"
update_files_tar="update.tar"
dest_dir_file="dest_dir"
file_tree=""

while (( "$#" )); do
case "$1" in
--device-type | -t)
if [ -z "$2" ]; then
show_help_and_exit_error
fi
device_type=$2
shift 2
;;
--artifact-name | -n)
if [ -z "$2" ]; then
show_help_and_exit_error
fi
artifact_name=$2
shift 2
;;
--dest-dir | -d)
if [ -z "$2" ]; then
show_help_and_exit_error
fi
dest_dir=$2
shift 2
;;
--output-path | -o)
if [ -z "$2" ]; then
show_help_and_exit_error
fi
output_path=$2
shift 2
;;
Expand All @@ -60,14 +76,12 @@ while (( "$#" )); do
;;
-*)
echo "Error: unsupported option $1"
show_help
exit 1
show_help_and_exit_error
;;
*)
if [ -n "$file_tree" ]; then
echo "File tree already specified. Unrecognized argument \"$1\""
show_help
exit 1
show_help_and_exit_error
fi
file_tree="$1"
shift
Expand All @@ -77,26 +91,22 @@ done

if [ -z "${artifact_name}" ]; then
echo "Artifact name not specified. Aborting."
show_help
exit 1
show_help_and_exit_error
fi

if [ -z "${device_type}" ]; then
echo "Device type not specified. Aborting."
show_help
exit 1
show_help_and_exit_error
fi

if [ -z "${dest_dir}" ]; then
echo "Destination dir not specified. Aborting."
show_help
exit 1
show_help_and_exit_error
fi

if [ -z "${file_tree}" ]; then
echo "File tree not specified. Aborting."
show_help
exit 1
show_help_and_exit_error
fi

# Check dest-dir is an absolute path
Expand Down Expand Up @@ -125,19 +135,19 @@ else
fi


# Create meta-data
eval "jq -n --argjson d '\"$dest_dir\"' '{\"dest-dir\": \$d}'" > $meta_data_file
# Create dest_dir file in plain text
echo "$dest_dir" > $dest_dir_file

mender-artifact write module-image \
-T file-install \
-t $device_type \
-o $output_path \
-n $artifact_name \
-f $update_files_tar \
-m $meta_data_file
-f $dest_dir_file

rm $meta_data_file
rm $update_files_tar
rm $dest_dir_file

echo "Artifact $output_path generated successfully:"
mender-artifact read $output_path
Expand Down
5 changes: 3 additions & 2 deletions support/modules/file-install
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ FILES="$2"

prev_files_tar="$FILES"/tmp/prev_files.tar
update_files_tar="$FILES"/files/update.tar
dest_dir_file="$FILES"/files/dest_dir

case "$STATE" in

Expand All @@ -19,7 +20,7 @@ case "$STATE" in
;;

ArtifactInstall)
dest_dir=$(jq -r ".[]" "$FILES"/header/meta-data)
dest_dir=$(cat $dest_dir_file)
[[ -d $dest_dir ]] || install -d $dest_dir
echo tar -cf ${prev_files_tar} -C ${dest_dir} .
tar -cf ${prev_files_tar} -C ${dest_dir} .
Expand All @@ -30,7 +31,7 @@ case "$STATE" in
;;

ArtifactRollback)
dest_dir=$(jq -r ".[]" "$FILES"/header/meta-data)
dest_dir=$(cat $dest_dir_file)
[[ -f $prev_files_tar ]] || exit 1
[[ -n "$dest_dir" ]] || exit 1
rm -rf ${dest_dir}
Expand Down

0 comments on commit 3d967d7

Please sign in to comment.