Snap in antiX – an unofficial way

Forum Forums General Software Snap in antiX – an unofficial way

Tagged: 

  • This topic has 6 replies, 4 voices, and was last updated May 30-4:49 am by sybok.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #143861
    Member
    sybok

      Snap is not supported in antiX because installation of ‘snapd’ requires ‘systemd’ as a hard-dependency.
      See e.g. the thread https://www.antixforum.com/forums/topic/snapstore-installing-problem/

      On the other hand, I’ve read that a snap is essentially a squashed filesystem.
      If you manage to download the snap file, you may simply un-squash it, permanently.

      Based on the available information (web-search, manual pages), I’ve written a simple script that attempts to do the job.

      Tested on ‘skype[forlinux]’.
      The unsquashed application did start, did not test the functionality thoroughly.
      As always, since this is unofficial, use it at your own risk and if you get the name correctly, download the snap but the snap|app does not work (at all or not as expected), that’s outside of scope of this script.

      The alternative(s) I thought about but discarded in the end as too laborious or dangerous:
      Simulate installation of ‘systemd’ by providing ‘systemctl’ script only (that’s how people did it in the past when ‘systemd’ was not hard-required as I understood it); this would require:
      A) re-pack(ag)ing ‘snapd’ (to depend on a new package providing the script instead of ‘systemd’)
      OR
      B) (temporarily?) break antiX’s design by providing a faked ‘systemd’ package which would most likely lead to deterioration of this great Linux OS.

      #!/bin/bash
      ###############################################################################
      ## Download a SNAP package-file using the package name, unsquash it and ...
      ## ... see what happens when you attempt to run the corresponding binary
      ##
      ## Usage:
      ## bash <scriptname> [<package name>]
      ##
      ## Author: sybok (just a nick-name)
      ##
      ## Changelog:
      ##
      ## 2024-05-30:
      ## Unsquashing function - read user's input
      ##
      ## 2024-05-29:
      ## Initial version
      ###############################################################################
      pkg_name='skype'
      cli_name="$*"
      if [ -n "${cli_name}" ]; then
        pkg_name="${cli_name}"
      fi
      add_date="$(date +%Y-%m-%d)" # Time-stamp
      infofile="${pkg_name}.json"
      httpfile="${pkg_name}.tmp"
      out_path="${pkg_name}_squashfs-root_${add_date}" # Time-stamped output directory
      get_info(){
        # Acquire single-line JSON-like INFO file, see e.g. https://unix.stackexchange.com/questions/560065
        curl -H 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/"${pkg_name}" >> "${infofile}"
        echo "[$0] - snap [${pkg_name}]: info-file [${infofile}] acquired"
      } # get_info
      get_snap(){
        # (Clumsily) Parse download link '"url":"http[^"]*"' JSON-like file:
        local httplink
        #sed -u '{
        #  s/"url":"\(http[^"]\+.snap\)"/\n\1\n/
        #  /^http/!d
        #}' "${infofile}" > "${httpfile}" # Failed to make the deletion of non-http line(s) work :(
        sed -u '{s/"url":"\(http[^"]\+.snap\)"/\n\1\n/g}' "${infofile}" > "${httpfile}"
        # Acquire the snap package and store the file (slightly) renamed in order to distinguish it easily:
        httplink="$(grep '^http' "${httpfile}" 2>/dev/null | tail -1)"
        echo "[$0] - snap [${pkg_name}]: HTTP(S) link parsed from info file [${infofile}] = [${httplink}]"
        #echo "Forced exit [exit]"; exit
        if [ -z "${httplink}" ]; then
          echo "[$0] - snap [${pkg_name}]: no HTTP(S) link parsed from info file [${infofile}] [exit]"
          exit 1
        fi
        #snapfile="${pkg_name}_$(echo "${httplink}" | sed -u 's@^.*/\([^/]\+.snap\)@\1@')"
        snapfile="${add_date}_${pkg_name}_$(echo "${httplink}" | sed -u 's@^.*/\([^/]\+.snap\)@\1@')"
        wget --output-document="${snapfile}"  "${httplink}"
      } # get_snap
      unsquash(){
        # unsquashfs the snap to a dedicated directory (-d = -dest):
        local unsquash
        echo 'Unsquash permanently [Y/n]?'; read -r -N 1 -t 5 unsquash; echo '' # Dummy echo for a newline
        if [ -n "${unsquash}" ] && [[ "${unsquash}" =~ ^[Nn]$ ]]; then
          echo "[$0] - snap [${pkg_name}]: do not unsquash the loaded file [${snapfile}] [return]"
          return
        fi
        mkdir "${out_path}"
        unsquashfs -dest "${out_path}" "${snapfile}"
        echo "[$0] - snap [${pkg_name}]: consider putting similar line(s) to your [~/.bashrc] file"
        echo 'PATH=${PATH}:'${PWD} # Add the folder to PATH to ensure the binaries are found
        echo "alias ='${PWD}/${out_path}/<rest of the path to the binary file>/'" # Alias to run the binary
      } # unsquash
      main(){
        get_info
        get_snap
        unsquash
      } # main
      main
      • This topic was modified 2 weeks, 6 days ago by sybok. Reason: Wording improved in introduction of the alternatives
      • This topic was modified 2 weeks, 6 days ago by sybok. Reason: Update of the code
      #143862
      Moderator
      Brian Masinick

        @sybok
        While the idea is unconventional and may potentially break the true antiX “way”, I nevertheless like your creativity.

        This sounds like a good thing to try on a spare system just to experiment.

        If you do try this, do let us know how it goes.

        --
        Brian Masinick

        #143864
        Member
        sybok

          Dear Mr. Masinick, I have modified my original post slightly to clarify that I already aborted the alternatives (though I already managed to pack a faked ‘systemd’ package providing the ‘systemctl’ script only) and I simply created the script to download the snap file and un-squash it once and for all (i.e. no mounting and un-mounting).
          The binary to start is present in the target forlder to which the snap (essentially a squashedfs) was “unpacked” to.

          It works as it is.
          Without breaking the system or having to maintain one or two packages (faked ‘systemd’ or + ‘snapd’).

          #143865
          Moderator
          Brian Masinick

            Congratulations @sybok on your successful creation!

            --
            Brian Masinick

            #143870
            Member
            anti-apXos

              Rather than unsquash it, would it also work to just mount the snapfile and run the executable from within the mountpoint?

              #143875
              Member
              techore

                post to monitor thread.

                #143919
                Member
                sybok

                  @anti-apXos: Not tested; I guess it would work as well but somehow I prefer it to be always available, i.e. as if installed.
                  Of course, you can define an alias to “mount + run + unmount”.

                  EDIT:
                  1) Also, one may need to add the mount|”unsquash” directory to PATH to make sure all necessary binaries are avail. – hint already included in the script.
                  2) I’ve tested the mount + run and it works as well.
                  mount --type='squashfs' --options='loop' <snap file> /mnt/

                  • This reply was modified 2 weeks, 5 days ago by sybok.
                Viewing 7 posts - 1 through 7 (of 7 total)
                • You must be logged in to reply to this topic.