1- # ###########################################################################
2- # Installs OpenVnmrJ on Ubuntu using Windows Subsystem for Linux #
3- # #
4- # To run this script: #
5- # #
6- # * Right-click on this file and select Properties #
7- # * Check the Unblock box at the bottom if present and click OK #
8- # #
9- # * Right-click on this file and select Run with PowerShell #
10- # #
11- # Troubleshooting see: https://github.com/JessiBaughman/OpenVnmrJ_WSL #
12- # #
13- # ###########################################################################
1+ # #############################################################################
2+ # Installs OpenVnmrJ on Ubuntu or Alma using Windows Subsystem for Linux #
3+ # #
4+ # To run this script: #
5+ # #
6+ # * Right-click on this file and select Properties #
7+ # * Check the Unblock box at the bottom if present and click OK #
8+ # #
9+ # * Right-click on this file and select Run with PowerShell #
10+ # #
11+ # Troubleshooting see: https://github.com/JessiBaughman/OpenVnmrJ_WSL #
12+ # #
13+ # #############################################################################
1414
15- # Last update: September 12 , 2024
15+ # Last update: September 15 , 2024
1616
1717# ########################
1818# ## Configuration ###
@@ -22,7 +22,7 @@ $defaultWSL = "Ubuntu-24.04" # which WSL distro to use/install by default
2222$supportedWSL = " Ubuntu" , " Ubuntu-20.04" , " Ubuntu-22.04" , " Ubuntu-24.04" , " AlmaLinux-9" , " AlmaLinux-8"
2323$defaultWSLlink = " https://aka.ms/wslubuntu" # link to default distro (See: https://docs.microsoft.com/en-us/windows/wsl/install-manual)
2424$minDist = 20 # minimum int version of Ubuntu supported
25- $minRHEL = 8 # minimum int version of Alma/Oracle Linux supported
25+ $minAlma = 8 # minimum int version of Alma Linux supported
2626$wslgBuild = 19044 # First build of Windows to support WSLg
2727$ovjWSLfolder = " $ ( [Environment ]::GetFolderPath(' UserProfile' )) \Downloads\OpenVnmrJ_WSL_install" # working directory for downloads
2828
@@ -522,7 +522,7 @@ function getWinget {
522522 }
523523}
524524
525- # Install and configure Ubuntu or RHEL -based Linux in WSL
525+ # Install and configure Ubuntu or Alma -based Linux in WSL
526526function installUbuntu ([string ]$distribution ) {
527527
528528 $wslExe = $ (-join (($distribution -replace " -" -replace " \." -replace " _" ).ToLower(), " .exe" ))
@@ -618,7 +618,7 @@ function setupUbuntu([string]$distribution) {
618618 echo " " ;echo " Installing PDF viewer, Firefox, htop, unzip, and neofetch"
619619 wsl - d $distribution - u root / bin/ bash - lic " $pkgMan install -y okular firefox htop unzip neofetch;$pkgMan autoremove -y"
620620 echo " "
621-
621+
622622 echo " Set Okular as default PDF viewer"
623623 # Default user
624624 wsl - d $distribution -- cd ~ / bin/ bash - c " [ -d .config ] && echo || mkdir .config"
@@ -722,8 +722,18 @@ function setupUbuntu([string]$distribution) {
722722
723723 echo " Installing PDF printer"
724724 if ((echo $pkgMan | Select-String apt)) {$cupspdf = " printer-driver-cups-pdf" } else {$cupspdf = " cups-pdf" }
725- wsl - d $distribution - u root / bin/ bash - lic " systemctl start cups;$pkgMan install -y $cupspdf "
726- wsl -- shutdown # "reboot"
725+ wsl - d $distribution - u root / bin/ bash - lic " systemctl enable --now cups;$pkgMan install -y $cupspdf "
726+ wsl -- shutdown
727+ wsl - d $distribution / bin/ bash - lic " echo ' '"
728+ wsl - d $distribution - u root sed - i ' s/^Out.*/Out \$\{HOME\}\/PDF/' / etc/ cups/ cups- pdf.conf
729+ if ((echo $pkgMan | Select-String apt)) {
730+ wsl - d $distribution - u root / bin/ bash - lic " lpadmin -p cups-pdf -v cups-pdf:/ -E -P /usr/share/ppd/cups-pdf/CUPS-PDF_opt.ppd"
731+ } else {
732+ wsl - d $distribution - u root / bin/ bash - lic " lpadmin -p cups-pdf -v cups-pdf:/ -E -P /usr/share/cups/model/CUPS-PDF_opt.ppd"
733+ }
734+ wsl - d $distribution - u root / bin/ bash - lic " cupsaccept cups-pdf;cupsenable cups-pdf"
735+ # Need to enable/disable/enable with delays to get /etc/cups/printers.conf to be written from outside a WSL window
736+ wsl - d $distribution - u root / bin/ bash - lic " sleep 10;cupsdisable cups-pdf;cupsenable cups-pdf;sleep 10"
727737 echo " "
728738}
729739
@@ -787,11 +797,7 @@ function installOVJ([string]$distribution) {
787797 if ((wsl - d $distribution - u vnmr1 / bin/ bash - lic " grep -c 'Name PDF' /vnmr/devicenames" ) -eq 0 ) { # Don't add if already present
788798 wsl - d $distribution - u vnmr1 sed - i ' $ a\################################################' / vnmr/ devicenames
789799 wsl - d $distribution - u vnmr1 sed - i ' $ a\Name PDF' / vnmr/ devicenames
790- if ((echo $distribution | Select-String Ubuntu)) {
791- wsl - d $distribution - u vnmr1 sed - i ' $ a\Printer PDF' / vnmr/ devicenames
792- } else {
793- wsl - d $distribution - u vnmr1 sed - i ' $ a\Printer Cups-PDF' / vnmr/ devicenames
794- }
800+ wsl - d $distribution - u vnmr1 sed - i ' $ a\Printer cups-pdf' / vnmr/ devicenames
795801 wsl - d $distribution - u vnmr1 sed - i ' $ a\Use Both' / vnmr/ devicenames
796802 wsl - d $distribution - u vnmr1 sed - i ' $ a\Type PDF_layout' / vnmr/ devicenames
797803 wsl - d $distribution - u vnmr1 sed - i ' $ a\Host' / vnmr/ devicenames
@@ -800,11 +806,7 @@ function installOVJ([string]$distribution) {
800806 wsl - d $distribution - u vnmr1 sed - i ' $ a\Shared Yes' / vnmr/ devicenames
801807 wsl - d $distribution - u vnmr1 sed - i ' $ a\################################################' / vnmr/ devicenames
802808 wsl - d $distribution - u vnmr1 sed - i ' $ a\Name PDFbw' / vnmr/ devicenames
803- if ((echo $distribution | Select-String Ubuntu)) {
804- wsl - d $distribution - u vnmr1 sed - i ' $ a\Printer PDF' / vnmr/ devicenames
805- } else {
806- wsl - d $distribution - u vnmr1 sed - i ' $ a\Printer Cups-PDF' / vnmr/ devicenames
807- }
809+ wsl - d $distribution - u vnmr1 sed - i ' $ a\Printer cups-pdf' / vnmr/ devicenames
808810 wsl - d $distribution - u vnmr1 sed - i ' $ a\Use Both' / vnmr/ devicenames
809811 wsl - d $distribution - u vnmr1 sed - i ' $ a\Type PDFbw_layout' / vnmr/ devicenames
810812 wsl - d $distribution - u vnmr1 sed - i ' $ a\Host' / vnmr/ devicenames
@@ -877,16 +879,6 @@ function installOVJ([string]$distribution) {
877879 echo " ERROR: Expanded dvdimageOVJ directory not found."
878880 echo " - Please check installer and try again."
879881 }
880-
881- wsl -- shutdown
882- echo " Finalize PDF printer setup"
883- # Something in the OpenVnmrJ installpkgs script breaks the PDF printer. Reinstalling fixes it though.
884- if ((echo $pkgMan | Select-String apt)) {
885- wsl - d $distribution - u root / bin/ bash - lic " systemctl enable --now cups;/usr/bin/apt reinstall -y printer-driver-cups-pdf"
886- } else {
887- wsl - d $distribution - u root / bin/ bash - lic " systemctl enable --now cups;/usr/bin/dnf reinstall -y cups-pdf"
888- }
889- echo " "
890882}
891883
892884# Create Shortcuts
@@ -982,11 +974,11 @@ function installController {
982974 wsl -- update
983975 wsl -- shutdown
984976
985- # Determine if Ubuntu or Alma/Oracle Linux is already installed
977+ # Determine if Ubuntu or Alma Linux is already installed
986978 $instU = 1 # Install flag
987979 $ubuntus = @ ((wsl - l) -replace " `0 " | Select-String Ubuntu) # -replace "`0" due to wsl UTF-16LE-encoded output
988- $rhels = @ ((wsl - l) -replace " `0 " | Select-String - Pattern " (Alma|Oracle )" ) # -replace "`0" due to wsl UTF-16LE-encoded output
989- if ( $ubuntus -Or $rhels ) { # 1+ Ubuntu/Alma/Oracle distributions already installed
980+ $almas = @ ((wsl - l) -replace " `0 " | Select-String - Pattern " (Alma)" ) # -replace "`0" due to wsl UTF-16LE-encoded output
981+ if ( $ubuntus -Or $almas ) { # 1+ Ubuntu/Alma/Oracle distributions already installed
990982 $step = 0
991983 $validDistros = @ ()
992984 foreach ($dist in $ubuntus ) { # Remove older, unsupported Ubuntu versions from list
@@ -997,9 +989,9 @@ function installController {
997989 }
998990 else {$validDistros += $dist } # Plain Ubuntu (no version label) case
999991 }
1000- foreach ($dist in $rhels ) { # Remove older, unsupported Alma versions from list
1001- if ( $dist -match " -" -Or $dist -match " _ " ) {
1002- if (((( $dist -replace " Alma.*-" ) -replace " Oracle.*x_ " ) -replace " _.* " ) - ge $minRHEL ) {
992+ foreach ($dist in $almas ) { # Remove older, unsupported Alma versions from list
993+ if ( $dist -match " -" ) {
994+ if (($dist -replace " Alma.*-" ) -ge $minAlma ) {
1003995 $validDistros += $dist
1004996 }
1005997 }
0 commit comments