ES | EN

Reinstalling Applications on Fedora

September 21, 2024

Before starting the game development, the first step was to prepare the desktop environment. I've chosen Fedora. This choice is based on several factors:

To start with a clean installation, I've developed two scripts that facilitate the process of backing up and reinstalling my applications. Here's the first script, which when executed generates a list of user-installed applications:


  #!/bin/bash
  # Name of the file where the applications will be saved
  OUTPUT_FILE="applications.txt"
  
  # Function to get applications installed by the user via DNF
  get_dnf_apps() {
      echo "Applications installed by the user (DNF):" > "$OUTPUT_FILE"
      dnf repoquery --userinstalled --queryformat '%{NAME}' | sort | uniq >> "$OUTPUT_FILE"
  }
  
  # Function to get applications installed by Flatpak
  get_flatpak_apps() {
      echo -e "\nApplications installed by Flatpak:" >> "$OUTPUT_FILE"
      flatpak list --app --columns=application | sort >> "$OUTPUT_FILE"
  }
  
  # Execute the functions to get the list of applications
  get_dnf_apps
  get_flatpak_apps
  
  echo "The list of applications installed by the user has been saved in $OUTPUT_FILE"
              

After obtaining the list of applications, I proceed to format and perform a clean installation of Fedora. Once the system is installed and updated, I copy the file generated by the first script into my $HOME directory and execute the second script to reinstall all the applications from the list:


  #!/bin/bash
  # Name of the file containing the list of applications
  INPUT_FILE="applications.txt"
  
  # Function to install DNF applications
  install_dnf() {
      echo "Installing DNF applications..."
      APPS_DNF=$(sed -n '/DNF:/,/Flatpak:/p' "$INPUT_FILE" | 
                 grep -v "DNF:" | grep -v "Flatpak:" | tr '\n' ' ')
      if [ -n "$APPS_DNF" ]; then
          sudo dnf install -y $APPS_DNF
      else
          echo "No DNF applications found to install."
      fi
  }
  
  # Function to install Flatpak applications
  install_flatpak() {
      echo "Installing Flatpak applications..."
      APPS_FLATPAK=$(sed -n '/Flatpak:/,$ p' "$INPUT_FILE" | 
                     grep -v "Flatpak:" | tr '\n' ' ')
      if [ -n "$APPS_FLATPAK" ]; then
          for app in $APPS_FLATPAK; do
              flatpak install -y flathub $app
          done
      else
          echo "No Flatpak applications found to install."
      fi
  }
  
  # Check if the input file exists
  if [ ! -f "$INPUT_FILE" ]; then
      echo "The file $INPUT_FILE does not exist. Please run the application listing script first."
      exit 1
  fi
  
  # Execute the installation functions
  install_dnf
  install_flatpak
  echo "The application installation has finished."
  

I hope this information is useful for those who wish to perform a similar process of reinstalling applications to get the system ready for immediate use.