meanwhile this solution is far away from clone but does the job I needed, maybe someone else might find it useful.
It's basically what I actually needed/expected.

1. On source system gather the installed packages and source

$apt-show-versions | awk -F'[ ]' '{print $1}' | awk -F'[:/]' '{print $1 "\t" $3}' > pkg.list

I use that awkward awk since I have packages which didn't come from apt, have no release or have been removed and $apt-show-versions lists them as:

gnupg-agent:amd64 not installed
jailkit:amd64 2.19-1 installed: No available version in archive


2. On destination I prepare my apt-preferences aswell as my sources lists

and since I use https source I'll

$apt-get update
$apt-get install apt-transport-https
$apt-get update


3. On destination I run

$./setup_list.py -i pkg.list

and wait :)

Yes, since apt-clone is in python3, this script aswell requires python, I attached it, maybe it's not nice and I won't guarantee it works for anyone else soo... missing License aswell so ... do whatever t f u want with that :)

The generated pkg.list syntax is:

<packagename>\t<release>

or a translated example:

curl    stretch
#!/usr/bin/python3

import getopt, os, subprocess, sys

def printhelp():
  print("install_list.py -i <inputfile>")
  print("install_list.py --ifile=<inputfile>")
  print("")
  print("inputfile should contain lines with: packagename<tab>debversion")
  print("where debversion shall be stable,testing and so on")


def main(argv):
  try:
    opts, args = getopt.getopt(argv,"hi:",["ifile="])

  except getopt.GetoptError:
    printhelp()
    sys.exit(2)

  for opt, arg in opts:
    if opt == '-h':
      printhelp()
      sys.exit()

    elif opt in ("-i", "--ifile"):
      print ("reading "+arg+"...")
      lines = open(arg).read().splitlines()
      installList = {}
      with open(arg) as f:
          content = f.readlines()
          for x in content:
            y = x.split("\t")
            index = y[1].strip("\n")
            if(index in installList):
              oldvalue = installList[index]
            else:
              oldvalue = ""
            installList[index] = "%s %s" % (oldvalue,  y[0])
      for k, v in installList.items():
        if(k):
          command = "apt-get install -y -t {0} {1}".format(k, v)
          subprocess.run(command.split(), shell=False)


if __name__ == "__main__":
   main(sys.argv[1:])

Reply via email to