Created
August 22, 2025 02:07
-
-
Save rowland007/9bebf655afbf5455ce605b65913c4998 to your computer and use it in GitHub Desktop.
This script will setup Docker, download the Windows image, and install the WinApp applications for Ubuntu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to handle errors | |
handle_error() { | |
echo "Error: $1" | |
exit 1 | |
} | |
# Check if the script is run as root | |
if [ "$EUID" -ne 0 ]; then | |
echo "Please run this script as root or with sudo." | |
exit 1 | |
fi | |
## Install required software | |
echo "Updating package list..." | |
sudo apt update || handle_error "Failed to update package list." | |
echo "Installing required packages..." | |
sudo apt install -y ufw curl wget dialog freerdp3-x11 git iproute2 libnotify-bin netcat-openbsd ca-certificates yad || handle_error "Failed to install required packages." | |
## Install Docker GPG key | |
echo "Installing Docker GPG key..." | |
sudo install -m 0755 -d /etc/apt/keyrings | |
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc || handle_error "Failed to download Docker GPG key." | |
sudo chmod a+r /etc/apt/keyrings/docker.asc | |
## Add Docker repository to APT sources | |
echo "Adding Docker repository..." | |
echo \ | |
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ | |
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
## Install Docker | |
echo "Installing Docker..." | |
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin || handle_error "Failed to install Docker." | |
## Update Ubuntu and remove unneeded packages | |
echo "Upgrading packages and cleaning up..." | |
sudo apt upgrade -y || handle_error "Failed to upgrade packages." | |
sudo apt autoclean -y | |
sudo apt autoremove -y | |
## Add user to Docker group | |
echo "Adding user to Docker group..." | |
sudo usermod -aG docker ${USER} || handle_error "Failed to add user to Docker group." | |
# Check for required commands | |
echo "Checking for required commands..." | |
for cmd in apt wget curl docker; do | |
if ! command -v $cmd &> /dev/null; then | |
handle_error "$cmd is not installed. Please install it and try again." | |
fi | |
done | |
## Confirm Docker is installed and working | |
echo "Testing Docker installation..." | |
docker run hello-world || handle_error "Docker is not working correctly." | |
echo "Docker should now be installed. Please read above to ensure it is. When ready, press any key to continue..." | |
read -n 1 -s | |
## Configure Firewall to deny external communication to your Windows Docker | |
echo "Configuring firewall..." | |
sudo ufw deny 3389 || handle_error "Failed to deny port 3389." | |
sudo ufw deny 8006 || handle_error "Failed to deny port 8006." | |
## Create the WinApps Configuration File | |
mkdir -p ~/.config/winapps | |
echo "Downloading WinApps configuration file..." | |
wget -O ~/.config/winapps/winapps.conf https://gist.githubusercontent.com/rowland007/34f9be2103a0cebe2476d393ffc58094/raw/11a75193acfac7a73f6134a5f833e4c8dfb4ab02/winapps.conf || handle_error "Failed to download the configuration file." | |
chmod 600 ~/.config/winapps/winapps.conf | |
echo "Configuration file downloaded successfully." | |
## Create the Docker Compose | |
echo "Downloading Docker Compose file..." | |
wget -O ~/.config/winapps/docker-compose.yml https://raw.githubusercontent.com/winapps-org/winapps/refs/heads/main/compose.yaml || handle_error "Failed to download the Docker Compose file." | |
echo "Compose file downloaded successfully." | |
# Run docker compose pull | |
DOCKER_COMPOSE_FILE=~/.config/winapps/docker-compose.yml | |
if [ -f "$DOCKER_COMPOSE_FILE" ]; then | |
echo "Pulling Docker images..." | |
docker compose --file "$DOCKER_COMPOSE_FILE" pull || handle_error "Failed to pull Docker images." | |
echo "Starting Docker containers..." | |
docker compose --file "$DOCKER_COMPOSE_FILE" up -d || handle_error "Failed to start Docker containers." | |
else | |
handle_error "Docker Compose file not found!" | |
fi | |
## Start Firefox to watch Windows installation | |
echo "Opening Firefox to watch the Windows installation..." | |
firefox http://127.0.0.1:8006 & | |
# Prompt the user to press 'w' to continue | |
while true; do | |
echo "Watch the installation of Windows in Firefox. Once you see the desktop, come back to this script and press 'w' to continue." | |
read -n 1 -s key # Read a single character silently | |
if [[ "$key" == "w" ]]; then | |
echo "Thank you for waiting..." | |
break # Exit the loop if 'w' is pressed | |
else | |
echo "Please read the warning again." | |
fi | |
done | |
while true; do | |
echo "When you see the Windows desktop in Firefox, press 'c' to continue here." | |
read -n 1 -s key | |
if [[ "$key" == "c" ]]; then | |
echo "Testing RDP connection..." | |
break # Exit the loop if 'c' is pressed | |
else | |
echo "You pressed a key; this safeguard is here to prevent accidents." | |
fi | |
done | |
# Start RDP | |
echo "Starting RDP connection..." | |
xfreerdp3 /u:"MyWindowsUser" /p:"MyWindowsPassword" /v:127.0.0.1 /cert:tofu | |
# Run the WinApps Installer | |
echo "If you successfully saw the Windows desktop in the pop-up window, you can close that and install the applications." | |
while true; do | |
echo "Did you see Windows in the popup and do you want to install the applications? [y/n]" | |
read -n 1 -s key | |
if [[ "$key" == "y" ]]; then | |
echo "Running the WinApps installer..." | |
bash <(curl -s https://raw.githubusercontent.com/winapps-org/winapps/main/setup.sh) || handle_error "Failed to run the WinApps installer." | |
break # Exit the loop if 'y' is pressed | |
else | |
echo "Exiting script. If you need to start over, run the following command. It will delete everything." | |
echo "docker compose --file ~/.config/winapps/docker-compose.yml down --rmi=all --volumes" | |
exit 1 | |
fi | |
done | |
echo "Script completed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment