Skip to content
Snippets Groups Projects

Support importing factory from https and unrelated fix

Merged Michal Hrusecky requested to merge factory into master
4 unresolved threads

Contians fix for #15 (closed) and allows to import factory image from https with checksum verification.

Edited by Michal Hrusecky

Merge request reports

Merged by Michal HruseckyMichal Hrusecky 4 years ago (Oct 20, 2020 8:03am UTC)

Merge details

  • Changes merged into master with fadd4d93.
  • Did not delete the source branch.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Karel Koci
  • Karel Koci
  • 701 704 import_sn() {
    702 705 if [ "x-f" = "x$1" ]; then
    703 706 shift
    704 TAR="$1"
    707 if expr "$1" : "https://" > /dev/null; then
    • Contributor

      Do you need to use regexp? How about:

      Suggested change
      728 if expr "$1" : "https://" > /dev/null; then
      728 if [ "${1%%://*}" = "https" ]; then

      I would even think about supporting in such case other schemas as well

      Suggested change
      728 if expr "$1" : "https://" > /dev/null; then
      728 local source="$1"
      729 local schema="${source%%://*}"
      730 case "$schema"; in
      731 http|https|ftp)
      732 # Use wget here
      733 ;;
      734 file)
      735 TAR="${source#file://}"
      736 ;;
      737 *)
      738 die "Unsupported schema: $schema"
      739 ;;
      740 esac

      Note that wget support ftp as well.

    • Want to have some level of security so not supporting http and ftp on purpose.

    • And isn't the variable substitution bash specific?

    • Contributor

      No they are supported, not all of them that bash support but they are. Behold: https://pubs.opengroup.org/onlinepubs/9699919799/ and now please use it everywhere.

      Want to have some level of security so not supporting http and ftp on purpose.

      I still think that you should detect not only https but URLs in general and report that provided schema is not valid. If you plan on supporting schema then, I think, you should support also file://.

    • Ok, would still prefer expr for readability reasons - I'm matching regexp, while your suggestion is to use globs to modify variable and then compare it - somehow less straight forward although faster for computer (as those are builtins), I would argue that slower for average reader. But I can compromise on case.

    • changed this line in version 3 of the diff

    • Contributor

      I do not think that expr is more readable honestly. It matches regexp without you really using regexp. It is like doing grep vs. grep -F, both are correct but one of them is better, guess which one. Also my version is technically more correct as it really compares only schema, yours looks for it in whole string (well it would be easy fix but with regexp this is common error).

      Personally expr usage for me smells like obsolete code. It is probably because in bash it is fully replaced by [[ but when I can I am not using it. Maybe my problem but really here for me it on the other hand decreases readability as I am thinking what are you matching instead that you are looking for substring.

    • Please register or sign in to reply
  • 735 753 fi
    736 754 }
    737 755
    756 cleanup() {
    757 umount_root
    758 remote_unmount
    759 [ -z "$TO_DELETE" ] || rm -rf $TO_DELETE
  • Karel Koci
  • Karel Koci
  • 701 704 import_sn() {
    702 705 if [ "x-f" = "x$1" ]; then
    703 706 shift
    704 TAR="$1"
    707 if expr "$1" : "https://" > /dev/null; then
    708 local tmpdir="$(mktemp -d)"
    709 [ -d "$tmpdir" ] || die "Can't create a tmp directory"
    710 TO_DELETE="$TO_DELETE $tmpdir"
    711 TAR="$tmpdir/$(basename "$1")"
    712 wget -O "$TAR" "$1" || die "Can't donwload '$1'"
    713 for sum in md5 sha256; do
    714 if wget -O "$TAR"."$sum" "$1"."$sum"; then
    715 (cd "$tmpdir"; "$sum"sum -c "$TAR"."$sum" || die "Checksum doesn't match for '$1'")
    716 else
    717 rm -f "$TAR"."$sum"
    718 fi
  • Karel Koci assigned to @mhrusecky and unassigned @kkoci

    assigned to @mhrusecky and unassigned @kkoci

  • added 1 commit

    • d631aa16 - fixup! Import generic config before processing -d

    Compare with previous version

  • Michal Hrusecky marked as a Work In Progress from d631aa16

    marked as a Work In Progress from d631aa16

  • Michal Hrusecky assigned to @kkoci and unassigned @mhrusecky

    assigned to @kkoci and unassigned @mhrusecky

  • Karel Koci assigned to @mhrusecky and unassigned @kkoci

    assigned to @mhrusecky and unassigned @kkoci

  • added 1 commit

    • ed5e91d1 - fixup! fixup! Import generic config before processing -d

    Compare with previous version

  • Michal Hrusecky assigned to @kkoci and unassigned @mhrusecky

    assigned to @kkoci and unassigned @mhrusecky

  • Michal Hrusecky unmarked as a Work In Progress

    unmarked as a Work In Progress

  • Karel Koci approved this merge request

    approved this merge request

  • Contributor

    Just few comments but otherwise I am ok with the code now.

  • Karel Koci assigned to @mhrusecky and unassigned @kkoci

    assigned to @mhrusecky and unassigned @kkoci

  • Michal Hrusecky added 2 commits

    added 2 commits

    • 5b8bb9a2 - Support importing factory from https
    • fadd4d93 - Import generic config before processing -d

    Compare with previous version

  • mentioned in issue #15 (closed)

  • Please register or sign in to reply
    Loading