33import java .io .BufferedReader ;
44import java .io .IOException ;
55import java .io .InputStreamReader ;
6- import java .nio .charset .StandardCharsets ;
7- import java .nio .file .Files ;
8- import java .nio .file .Path ;
96import java .util .ArrayList ;
107import java .util .Arrays ;
118import java .util .HashSet ;
1613
1714public class PostInstallUpdater {
1815 private static final List <String > gpgKeys = List .of (
19- "https://rpmfusion.org/keys?action=AttachFile&do=get&target=RPM-GPG-KEY-rpmfusion-free-fedora-2020" ,
20- "https://rpmfusion.org/keys?action=AttachFile&do=get&target=RPM-GPG-KEY-rpmfusion-nonfree-fedora-2020"
16+ "https://rpmfusion.org/keys?action=AttachFile&do=get&target=RPM-GPG-KEY-rpmfusion-free-fedora-2020" ,
17+ "https://rpmfusion.org/keys?action=AttachFile&do=get&target=RPM-GPG-KEY-rpmfusion-nonfree-fedora-2020"
2118 );
2219 private static final List <String > rpmfusionRepos = List .of (
23- "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-42.noarch.rpm" ,
24- "https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-42.noarch.rpm"
20+ "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-42.noarch.rpm" ,
21+ "https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-42.noarch.rpm"
2522 );
2623
2724 private static final String flatpakRemoteName = "flathub" ;
2825 private static final String flatpakRemoteUrl = "https://dl.flathub.org/repo/flathub.flatpakrepo" ;
2926
3027 private static final List <String > groupList = List .of (
31- "docker" , "libvirt" , "vboxsf" , "vboxusers"
28+ "docker" , "libvirt" , "vboxsf" , "vboxusers"
3229 );
3330
34- private static final String CONFIG_DIR = "src/main/resources" ;
3531 private static final String DNF_INSTALL_FILE = "dnf-install.cf" ;
3632 private static final String DNF_REMOVE_FILE = "dnf-remove.cf" ;
3733 private static final String FLATPAK_INSTALL_FILE = "flatpak-install.cf" ;
@@ -48,9 +44,9 @@ public static void main(String[] args) {
4844 return ;
4945 }
5046
51- List <String > dnfInstallPackages = loadPackageNamesFrom (DNF_INSTALL_FILE );
52- List <String > dnfRemovePackages = loadPackageNamesFrom (DNF_REMOVE_FILE );
53- List <String > flatpakInstallPackages = loadPackageNamesFrom (FLATPAK_INSTALL_FILE );
47+ List <String > dnfInstallPackages = ConfigManager . loadPackageNamesFrom (DNF_INSTALL_FILE );
48+ List <String > dnfRemovePackages = ConfigManager . loadPackageNamesFrom (DNF_REMOVE_FILE );
49+ List <String > flatpakInstallPackages = ConfigManager . loadPackageNamesFrom (FLATPAK_INSTALL_FILE );
5450 Scanner scanner = new Scanner (System .in );
5551
5652 System .out .println ("Fedora Post Install Actions\n " );
@@ -59,7 +55,6 @@ public static void main(String[] args) {
5955 System .out .println ("---[Dry Run Mode] Shell Commands will not be executed.---\n " );
6056 }
6157
62- // 1. Install RPMFusion repos
6358 if (confirm (scanner , "Install RPMFusion repos?" )) {
6459 for (String key : gpgKeys ) {
6560 runCommand (new String []{"sudo" , "rpm" , "--import" , key });
@@ -76,7 +71,6 @@ public static void main(String[] args) {
7671 runCommand (cmd );
7772 }
7873
79- // 2. DNF install packages
8074 if (confirm (scanner , "Install additional packages with DNF?" )) {
8175 List <String > filtered = promptForExclusions (dnfInstallPackages , scanner );
8276 String [] cmd = new String [filtered .size () + 5 ];
@@ -91,7 +85,6 @@ public static void main(String[] args) {
9185 runCommand (cmd );
9286 }
9387
94- // 3. DNF remove packages
9588 if (confirm (scanner , "Remove all DNF packages marked for removal?" )) {
9689 List <String > filtered = promptForExclusions (dnfRemovePackages , scanner );
9790 String [] cmd = new String [filtered .size () + 4 ];
@@ -106,7 +99,6 @@ public static void main(String[] args) {
10699 runCommand (new String []{"sudo" , "dnf" , "autoremove" , "-y" });
107100 }
108101
109- // 4. Flatpak install apps
110102 if (confirm (scanner , "Install Flatpak apps?" )) {
111103 runCommand (new String []{"flatpak" , "remote-add" , "--if-not-exists" , flatpakRemoteName , flatpakRemoteUrl });
112104 List <String > filtered = promptForExclusions (flatpakInstallPackages , scanner );
@@ -121,7 +113,6 @@ public static void main(String[] args) {
121113 runCommand (cmd );
122114 }
123115
124- // 5. Ensure groups exist and add user to them
125116 if (confirm (scanner , "Ensure admin groups exist and add current user to them?" )) {
126117 String user = System .getProperty ("user.name" );
127118 for (String group : groupList ) {
@@ -135,7 +126,6 @@ public static void main(String[] args) {
135126 }
136127 }
137128
138- // 6. Enable and start Cockpit service
139129 if (confirm (scanner , "Enable and start cockpit.socket service?" )) {
140130 runCommand (new String []{"sudo" , "systemctl" , "enable" , "--now" , "cockpit.socket" });
141131 }
@@ -188,23 +178,6 @@ static int runCommand(String[] command) {
188178 return exitCode ;
189179 }
190180
191- static List <String > loadPackageNamesFrom (String filename ) {
192- List <String > packages = new ArrayList <>();
193- try {
194- List <String > lines = Files .readAllLines (Path .of (CONFIG_DIR , filename ), StandardCharsets .UTF_8 );
195- for (String line : lines ) {
196- String trimmed = line .trim ();
197- if (!trimmed .isEmpty () && !trimmed .startsWith ("#" )) {
198- packages .add (trimmed );
199- }
200- }
201- } catch (IOException e ) {
202- System .err .println ("Failed to read package list from " + filename + ": " + e .getMessage ());
203- }
204-
205- return packages ;
206- }
207-
208181 static List <String > promptForExclusions (List <String > packages , Scanner scanner ) {
209182 for (int i = 0 ; i < packages .size (); i ++) {
210183 System .out .printf ("%2d. %s\n " , i + 1 , packages .get (i ));
@@ -235,7 +208,7 @@ static List<String> promptForExclusions(List<String> packages, Scanner scanner)
235208
236209 static void printHelp () {
237210 try {
238- List <String > lines = Files . readAllLines ( Path . of ( CONFIG_DIR , HELP_FILE ), StandardCharsets . UTF_8 );
211+ List <String > lines = ConfigManager . readResourceLines ( HELP_FILE );
239212 System .out .println (String .join (System .lineSeparator (), lines ));
240213 } catch (IOException e ) {
241214 System .err .println ("Error reading help file: " + e .getMessage ());
0 commit comments