raspberrypi-ui / piclone

Utility to back up Pi to an SD card reader
260 stars 62 forks source link

CLI-only/headless variant of piclone? #48

Closed fonix232 closed 3 months ago

fonix232 commented 3 months ago

With the Pi5 introduced with PCIe SSD support, and a bunch of cases utilising various mounting strategies that make it hard to access the M.2 drives, there's now a need to be able to re-image those SSDs from an SD card easily.

The easiest approach would be using the logic of piclone, however... It's a GTK app. Many of us are running Pis in headless mode, using the Lite Debian images, generally accessed over SSH, without any desktop/GUI. This means that one needs to manually do the cloning process, which is quite tedious.

I think it would be great if the core of piclone could be broken out into a CLI tool, allowing these headless units to utilise the cloning, and even automate it (by setting the boot order to SD-NVMe-USB, and inserting/removing a prepared SD card, one could run a service which does the usual APT upgrade, then detects the NVMe drive, and clones the contents of the SD card to it, essentially automating the process of getting the latest Debian, completely clean, onto the SSD without disassembly).

Since the code is relatively well separated already, I think this could be done by moving the handful of methods into a separate C/H fileset (say, piclone-core.[c|h]), and adding a piclone-cli.[c|h] wrapper that exposes the GTK options as CLI flags, allowing to run the core functions easily, without installing nearly 800MB of unnecessary desktop libraries.

Right now, trying to install piclone on a Lite Debian image pulls in these dependencies:

adwaita-icon-theme aspell aspell-en at-spi2-common at-spi2-core bubblewrap dbus-x11 dconf-gsettings-backend dconf-service dictionaries-common emacsen-common enchant-2 fontconfig fonts-droid-fallback
  fonts-noto-mono fonts-urw-base35 ghostscript glib-networking glib-networking-common glib-networking-services gsettings-desktop-schemas gsfonts gstreamer1.0-gl gstreamer1.0-libav gstreamer1.0-plugins-bad
  gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-x gtk-update-icon-cache hicolor-icon-theme hunspell-en-us imagemagick-6-common libaa1 libaacs0 libaspell15 libass9 libasyncns0 libatk-bridge2.0-0
  libatk1.0-0 libatspi2.0-0 libavahi-client3 libavc1394-0 libavcodec59 libavfilter8 libavformat59 libavutil57 libbdplus0 libblas3 libbluray2 libbs2b0 libcaca0 libcairo-gobject2 libcairo2 libcdparanoia0
  libchromaprint1 libcjson1 libcodec2-1.0 libcolord2 libcups2 libdatrie1 libdc1394-25 libdca0 libdconf1 libdecor-0-0 libdecor-0-plugin-1-cairo libdirectfb-1.7-7 libdjvulibre-text libdjvulibre21 libdrm-amdgpu1
  libdrm-nouveau2 libdrm-radeon1 libdv4 libdvdnav4 libegl-mesa0 libegl1 libenchant-2-2 libepoxy0 libevdev2 libfaad2 libfftw3-double3 libflite1 libfluidsynth3 libfontenc1 libfreeaptx0 libfribidi0 libgbm1
  libgdk-pixbuf-2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common libgfortran5 libgl1 libgl1-mesa-dri libglapi-mesa libgles2 libglvnd0 libglx-mesa0 libglx0 libgme0 libgpm2 libgraphene-1.0-0 libgraphite2-3
  libgs-common libgs10 libgs10-common libgsm1 libgssdp-1.6-0 libgstreamer-gl1.0-0 libgstreamer-plugins-bad1.0-0 libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 libgtk-3-0 libgtk-3-bin libgtk-3-common libgupnp-1.6-0
  libgupnp-igd-1.0-4 libharfbuzz-icu0 libharfbuzz0b libhunspell-1.7-0 libhwy1 libhyphen0 libice6 libidn12 libiec61883-0 libijs-0.35 libimath-3-1-29 libinstpatch-1.0-2 libjack-jackd2-0 libjavascriptcoregtk-4.1-0
  libjbig2dec0 libjson-glib-1.0-0 libjson-glib-1.0-common libjxl0.7 libjxr-tools libjxr0 libkate1 liblapack3 liblcms2-2 libldacbt-enc2 liblilv-0-0 libllvm15 liblqr-1-0 liblrdf0 libltc11 libltdl7
  libmagickcore-6.q16-6 libmagickcore-6.q16-6-extra libmagickwand-6.q16-6 libmanette-0.2-0 libmbedcrypto7 libmjpegutils-2.1-0 libmodplug1 libmp3lame0 libmpcdec6 libmpeg2encpp-2.1-0 libmpg123-0 libmplex2-2.1-0
  libmysofa1 libncurses6 libneon27 libnice10 libnorm1 libnotify4 libopenal-data libopenal1 libopenexr-3-1-30 libopenh264-7 libopenjp2-7 libopenmpt0 libopenni2-0 libopus0 liborc-0.4-0 libpango-1.0-0
  libpangocairo-1.0-0 libpangoft2-1.0-0 libpaper-utils libpaper1 libpgm-5.3-0 libpipewire-0.3-0 libpipewire-0.3-common libpixman-1-0 libplacebo208 libpocketsphinx3 libpostproc56 libproxy1v5 libpulse0 libqrencode4
  librabbitmq4 libraptor2-0 libraw1394-11 librist4 librsvg2-2 librsvg2-common librubberband2 libsbc1 libsdl2-2.0-0 libsecret-1-0 libsecret-common libsensors-config libsensors5 libserd-0-0 libshine3 libshout3 libsm6
  libsnappy1v5 libsndfile1 libsndio7.0 libsodium23 libsord-0-0 libsoundtouch1 libsoup-3.0-0 libsoup-3.0-common libsoup2.4-1 libsoup2.4-common libsoxr0 libspa-0.2-modules libspandsp2 libspeex1 libsphinxbase3
  libsratom-0-0 libsrt1.5-gnutls libsrtp2-1 libssh-gcrypt-4 libswresample4 libswscale6 libtag1v5 libtag1v5-vanilla libthai-data libthai0 libtheora0 libtwolame0 libudfread0 libva-drm2 libva-x11-2 libva2
  libvdpau-va-gl1 libvdpau1 libvidstab1.1 libvisual-0.4-0 libvo-aacenc0 libvo-amrwbenc0 libvorbisenc2 libvorbisfile3 libvpx7 libvulkan1 libwavpack1 libwayland-client0 libwayland-cursor0 libwayland-egl1
  libwayland-server0 libwebkit2gtk-4.1-0 libwebpdemux2 libwebpmux3 libwebrtc-audio-processing1 libwildmidi2 libwmflite-0.2-7 libwoff1 libx11-xcb1 libx264-164 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0
  libxcb-randr0 libxcb-render0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcb-xkb1 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxinerama1 libxkbcommon-x11-0 libxkbcommon0 libxrandr2 libxrender1
  libxshmfence1 libxslt1.1 libxss1 libxt6 libxtst6 libxv1 libxvidcore4 libxxf86vm1 libyajl2 libz3-4 libzbar0 libzimg2 libzmq5 libzvbi-common libzvbi0 libzxing2 mesa-va-drivers mesa-vdpau-drivers mesa-vulkan-drivers
  ocl-icd-libopencl1 pocketsphinx-en-us poppler-data timgm6mb-soundfont va-driver-all vdpau-driver-all x11-common xdg-dbus-proxy xdg-desktop-portal xdg-desktop-portal-gtk xfonts-encodings xfonts-utils zenity
  zenity-common

Totalling a 219MB download and 784MB disk space after install.

I think I could be up for the task of separating the core functions, and adding the CLI wrapper, however I'm not familiar with the autogen/automake framework enough to confidently change the script to build the CLI and GUI binaries separately.

Would this be a welcome addition to this project, or should I just fork the repo and DIY it?

spl237 commented 3 months ago

I don't think this is something we would particularly want, but FYI, before I wrote the GUI version, the prototype was just a shell script which ran from the command-line and did pretty much all the same operations. That script is still in the project - look for "backup" in the src subdirectory. You might find with a few tweaks that does what you want - it's not been maintained, but most of the core functionality should be in there.

I don't think there is anything in the application that can't be done from a shell script command - if you did want to work on a pure CLI version, then I'd recommend that rather than trying to reverse the GUI version into a CLI binary.

fonix232 commented 3 months ago

Ah true, makes sense. I was thinking that an officially published package would be easier to maintain (at least locally, for installs) than copying a script manually.