package net.danielostrowski.wiipackageget; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; public class WiiPackageGet { private static final String PACKAGES = "Packages"; private static final String INSTALLENDS = "installends"; private static final String URL_PREFIX = "http://archive.debian.org/debian/"; public static void main(String[] args) throws Exception { if (!Files.exists(Paths.get(PACKAGES))) { throw new Exception("Please download and extract http://archive.debian.org/debian/dists/jessie/main/" + "binary-powerpc/Packages.gz to a file named \"" + PACKAGES + "\" in this directory"); } List lines = Files.lines(Paths.get(PACKAGES)).collect(Collectors.toList()); if (!Files.exists(Paths.get(INSTALLENDS))) { throw new Exception("Please create a text file named \"" + INSTALLENDS + "\" in this directory with the " + "name of every package you want, perhaps copy-pasted from the output of apt"); } List installends = Files.lines(Paths.get(INSTALLENDS)). map(line -> Arrays.asList(line.split("(\\s|\\r|\\n)+"))). flatMap(Collection::stream).filter(installend -> !"".equals(installend)). collect(Collectors.toList()); String folderName = "packages_" + System.currentTimeMillis(); System.out.println("mkdir " + folderName); System.out.println("cd " + folderName); for (String installend : installends) { String url = getUrlForPackage(lines, installend); System.out.println("wget -q \"" + url + "\""); } } private static String getUrlForPackage(List lines, String packageName) throws Exception { int infoStart = lines.indexOf("Package: " + packageName); for (int i = infoStart; i < infoStart + 100 && i < lines.size(); i++) { String line = lines.get(i); if (line.startsWith("Filename: ")) { return URL_PREFIX + line.substring(10); } } throw new Exception("Couldn't find path to package " + packageName); } }