Skip to content

Commit 414db71

Browse files
committed
feat: add Manifest module, re-sort directory
1 parent 0f29b40 commit 414db71

16 files changed

+51
-30
lines changed

lib/rootfs/manifest.rb

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
module RootFS
4+
# Ubuntu mainfest style
5+
module Manifest
6+
def manifest_readlines(any, &block)
7+
if File.file?(any)
8+
IO.readlines(any, &block)
9+
else
10+
String(any).readlines(&block)
11+
end
12+
end
13+
14+
def manifest_each_line(any, &block)
15+
if File.file?(any)
16+
IO.readlines(any, &block).each(&block)
17+
else
18+
String(any).readlines(&block)
19+
end
20+
end
21+
22+
def manifest_package(any)
23+
lines = if File.file?(any)
24+
IO.readlines(any)
25+
else
26+
String(any).readlines
27+
end
28+
list = []
29+
lines.each do |line|
30+
pkg = line.include?("\t") ? line.split("\t")[0] : line.split(" ")[0]
31+
list.push(pkg)
32+
end
33+
list
34+
end
35+
end
36+
end

lib/rootfs/package/dpkg.rb

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# frozen_string_literal: true
22

33
require "libexec"
4+
require_relative "../manifest"
45

56
module RootFS
67
module Package
78
module Dpkg
9+
extend RootFS::Manifest
10+
include RootFS::Manifest
11+
812
# https://manpages.ubuntu.com/manpages/jammy/man1/dpkg-query.1.html
913
def installed
1014
list = []
@@ -30,20 +34,9 @@ def generate_manifest(file = nil)
3034
end
3135
end
3236

33-
def parse_manifest(file, &block)
34-
IO.readlines(file, &block)
35-
end
37+
def can_install(any)
38+
pkgs = any.instance_of?(Array) ? any : manifest_package(any)
3639

37-
def manifest_package(file)
38-
list = []
39-
IO.readlines(file).each do |line|
40-
pkg = line.include?("\t") ? line.split("\t")[0] : line.split(" ")[0]
41-
list.push(pkg)
42-
end
43-
list
44-
end
45-
46-
def can_install(pkgs)
4740
ignores = []
4841
Libexec.each_line("apt-get install #{pkgs.join(" ")} 2>&1") do |line|
4942
err_pre = "E: Unable to locate package "
@@ -57,14 +50,6 @@ def can_install(pkgs)
5750
pkgs -= ignores
5851
can_install(pkgs)
5952
end
60-
61-
def can_from_file(file)
62-
pkgs = []
63-
IO.readlines(file).each do |line|
64-
pkgs.push(line.chomp)
65-
end
66-
can_install(pkgs)
67-
end
6853
end
6954
end
7055
end

lib/rootfs/package/dpkg_test.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ class MyClass
1212
# pp u.installed
1313
# u.generate_manifest
1414
# u.generate_manifest(".rspec_status")
15-
# u.parse_manifest(".rspec_status").each do |line|
15+
# u.manifest_readlines(".rspec_status").each do |line|
1616
# puts line.split("\t").first
1717
# end
1818
# puts u.manifest_package(".rspec_status") - u.installed_by_user
1919

20-
# raspi_server_pkgs = u.manifest_package("manifest/rel/ubuntu-22.04.1-preinstalled-server-arm64+raspi.manifest")
21-
# raspi_desktop_pkgs = u.manifest_package("manifest/rel/ubuntu-22.04.1-preinstalled-desktop-arm64+raspi.manifest")
20+
# raspi_server_pkgs = u.manifest_package("../manifest/ubuntu/rel/ubuntu-22.04.1-preinstalled-server-arm64+raspi.manifest")
21+
# raspi_desktop_pkgs = u.manifest_package("../manifest/ubuntu/rel/ubuntu-22.04.1-preinstalled-desktop-arm64+raspi.manifest")
2222

2323
# raspi_desktop = raspi_desktop_pkgs - raspi_server_pkgs
2424
# puts raspi_desktop
25-
# puts server_pkgs - desktop_pkgs
25+
# puts raspi_server_pkgs - raspi_desktop_pkgs
2626

2727
# comm_desktop = raspi_desktop.filter do |pkg|
2828
# pkg != "pi-bluetooth" &&
@@ -32,15 +32,15 @@ class MyClass
3232
# end
3333
# puts comm_desktop
3434

35-
base_pkg = u.manifest_package("manifest/jammy-base-arm64.manifest")
36-
live_server_pkgs = u.manifest_package("manifest/jammy-live-server-arm64.manifest")
37-
live_desktop_pkgs = u.manifest_package("manifest/jammy-desktop-arm64.manifest")
35+
base_pkg = u.manifest_package("../manifest/ubuntu/jammy-base-arm64.manifest")
36+
live_server_pkgs = u.manifest_package("../manifest/ubuntu/jammy-live-server-arm64.manifest")
37+
live_desktop_pkgs = u.manifest_package("../manifest/ubuntu/jammy-desktop-arm64.manifest")
3838

3939
server = live_server_pkgs - base_pkg
4040
desktop = live_desktop_pkgs - base_pkg
4141

4242
# puts server
4343
# puts desktop
4444

45-
puts u.can_install(desktop)
46-
# puts u.can_from_file("install.txt")
45+
# puts u.can_install(desktop)
46+
puts u.can_install("install.txt")

0 commit comments

Comments
 (0)