Can't get proxy to connect in a template install script?

I’m having trouble getting the proxy to connect in this script.

Can you see anything wrong with the way proxy is setup and used?:

Edit: Additional info: Script works when used on a network connected qube, but not an offline template qube.

Ref:

# Setup proxy
qvm-run --pass-io -u root $TARGET_TEMPLATE "export https_proxy=127.0.0.1:8082"

Script in full context:

#!/bin/bash
# Installs Opera in target qube.
# Run from dom0 & pass qube name as parameter

# Assign the qube name to TARGET_TEMPLATE
TARGET_TEMPLATE=$1

# Install dependencies
qvm-run --pass-io -u root $TARGET_TEMPLATE \
  "sudo apt-get update && sudo apt-get install -y qubes-core-agent-networking curl"

# Setup proxy
qvm-run --pass-io -u root $TARGET_TEMPLATE "export https_proxy=127.0.0.1:8082"

# Remove existing Opera repository, if any
qvm-run --pass-io -u root $TARGET_TEMPLATE \
  "sudo rm /etc/apt/sources.list.d/opera-stable.list"

# Add Opera repository to apt sources
qvm-run --pass-io -u root $TARGET_TEMPLATE \
  'echo "deb https://deb.opera.com/opera-stable/ stable non-free" | sudo tee /etc/apt/sources.list.d/opera-stable.list'

# Add Opera GPG key to trusted keys
qvm-run --pass-io -u root $TARGET_TEMPLATE \
  "curl -fsSL https://deb.opera.com/archive.key | sudo apt-key add -"

# Update available packages
qvm-run --pass-io -u root $TARGET_TEMPLATE \
  "sudo apt-get update"

# Install latest Opera stable version (auto-answer yes)
qvm-run --pass-io -u root $TARGET_TEMPLATE \
  "sudo apt-get install -y opera-stable"

# Shutdown the target qube, if desired
# qvm-shutdown --wait $TARGET_TEMPLATE


Each call of qvm-run is independant, like a new terminal session.

You need to export the https_proxy in this session.
You don’t need sudo as you execute a root session.
I don’t think you need sh -c either.

Personnaly, I would use only a single qvm-run call.

qvm-run --pass-io -u root $TARGET_TEMPLATE "
    command 1
    command 2
    ...
    command N"
2 Likes

Refactored. Still the same error. Cant connect to network:

Ref:

#!/bin/bash
# Installs Opera in target qube.
# Run from dom0 & pass qube name as parameter

# Assign the qube name to TARGET_TEMPLATE
TARGET_TEMPLATE=$1

# Install dependencies, setup proxy, remove existing Opera repository (if it exists), add Opera repository to apt sources,
# add Opera GPG key to trusted keys, update available packages, and install latest Opera stable version
qvm-run --pass-io -u root $TARGET_TEMPLATE \
  "sudo apt-get update && sudo apt-get install -y qubes-core-agent-networking curl && \
   export https_proxy=127.0.0.1:8082 && \
   test -d /etc/apt/sources.list.d/opera-stable.list && sudo rm /etc/apt/sources.list.d/opera-stable.list && \
   echo 'deb https://deb.opera.com/opera-stable/ stable non-free' | sudo tee /etc/apt/sources.list.d/opera-stable.list && \
   curl -fsSL https://deb.opera.com/archive.key | sudo apt-key add - && \
   sudo apt-get update && \
   sudo apt-get install -y opera-stable"

# Shutdown the target qube, if desired
# qvm-shutdown --wait $TARGET_TEMPLATE

Ah… missed comment on proxy export… refactoring.

dunno…still the same problem.

Sidelining for now.
If anyone has a working Opera install script for min templates, please post.

from man test

-d FILE: FILE exists and is a directory

opera-stable.list is a regular file, therefore, the script just stop there.
If the file doesn’t exist, the script stop there too.

You don’t need rm or test if the file exist, you are root, just erase the file.

qvm-run --pass-io -u root $TARGET_TEMPLATE \
   "apt update && \
    apt install -y qubes-core-agent-networking curl && \
    echo 'deb https://deb.opera.com/opera-stable/ stable non-free' \
        > /etc/apt/sources.list.d/opera-stable.list && \
    export https_proxy=127.0.0.1:8082 && \
    curl -fsSL https://deb.opera.com/archive.key | apt-key add - && \
    apt update && \
    apt install -y opera-stable"

If it doesn’t work, it is not related to the syntax.
Try with a fresh unmodified template.

1 Like

https_proxy=http://127.0.0.1:8082/ http_proxy=http://127.0.0.1:8082/ wget --secure-protocol=TLSv1_2 -O- http://repo.vivaldi.com/archive/linux_signing_key.pub | gpg --dearmor | tee /etc/apt/trusted.gpg.d/vivaldi.gpg
This command works for me with vivaldi. Maybe it help.

1 Like

Thanks.
Without the test, this is the error I’m getting:
rm: cannot remove '/etc/apt/sources.list.d/opera-stable.list': No such file or directory

You do not need rm or test.
When I said “just erase the file”, it is done with echo "text" > file.

Just use the version I posted, It’s the clean version of yours.
If it still can’t connect via the proxy, there is maybe a problem
with the policies rules.