Categories
Uncategorized

Scripting Ubuntu 18.04 Upgrade for WSL

If you have been running Ubuntu 16.04 on Windows Subsystem for Linux (WSL), you may need to modify your scripts to automate future upgrades on 18.04. There are differences in Ubuntu 18.04 that may require our attention if we want the upgrade to be completely unattended.

If you have been running Ubuntu 16.04 on Windows Subsystem for Linux (WSL), you may need to modify your scripts to automate future upgrades on 18.04. There are differences in Ubuntu 18.04 that may require our attention if we want the upgrade to be completely unattended.

TL;DR

In the content below, I will be describing the how I ended up automating Ubuntu 18.04 upgrade on WSL. However, here’s the simplified Bash script that I ended up with.

#!/bin/bash
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y upgrade

Where I Started

I found this great article that walks though the setup of WordPress on WSL by Jason Cross. What I didn’t realize when I started is that his article assumes you are using Ubuntu 16.04 and so the instructions are a little different in 18.04. Since I was trying to automate the process these differences resulted in unexpected prompts and permission issues.

Based on his article and other documentation that I came across here was my initial Bash script.

#!/bin/bash
sudo apt update && sudo apt -y upgrade

The Problem: The libssl1.1:amd Prompt During Upgrade

The update command worked as expected, but when the upgrade command reached 75% the following prompt appeared.

Configuring libssl1.1:amd64 prompt received on Ubuntu 18.04 for WSL

While this prompt is not technically a problem, it does block a full unattended process.

Thankfully, I received guidance through the Twitter community that helped steer me in the right direction. It was through that feedback that I better understood the differences between the versions and how to better construct my Bash script.

The solution provided was to use export DEBIAN_FRONTEND=noninteractive in the preceding line. Here’s what that modified version looked like based on that recommendation.

#!/bin/bash
sudo apt update
export DEBIAN_FRONTEND=noninteractive
sudo apt -y upgrade

Unfortunately, that didn’t work either. The prompt still appeared.

The Solution

After multiple tests—made easier by using a script—I found the syntax to remove the prompt. Basically, the noninteractive had to be set within the same command rather than separately.

#!/bin/bash
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y upgrade

I also went ahead and changed from apt to apt-get based on the examples I was seeing as well. The only difference I noticed by using apt-get was the loss of the progress notification at the bottom of my terminal.

Is This a Bug?

So this appears to be a bug given the change in behavior and it has even been reported as a bug. If you review the thread however, it is not being considered a bug as the -y sets the apt-get as noninteractive rather than the package to be upgraded or installed. Essentially, there is not a clearly defined, unified “way of achieving non-interactivity” and the implication is that it is the responsibility of the package creator to correctly request the non-interactivity status.

What was especially interesting is that when I tested the same procedure on a Ubuntu Server 18.04.3 virtual machine I did not receive the prompt. The only thing I can attribute that difference to is the difference in the Ubuntu installers.

If you come across this issue with other packages, here is the full recommended command that you can test with that includes all possible parameters to set non-interactivity.

UCF_FORCE_CONFOLD=1 DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -qq -y install [packagename]

Conclusion

There are some additional differences that affect MySQL installation and configuration, but I will cover that in a future article. However, this first adjustment helped move me forward in creating a WordPress installation script for WSL.

Thanks go out to Hayden Barnes for helping guide me through the troubleshooting process. His feedback was invaluable.

One reply on “Scripting Ubuntu 18.04 Upgrade for WSL”

Comments are closed.