#!/usr/bin/env python3
from subprocess import run
from sys import modules
def main():
doas()
def doas():
ch = input("Ready to proceed with setting up doas?[Y/n]?")
if ch == 'y':
run("sudo passwd", shell=True)#If you would prefer to access the root account with su or by logging in directly, you must set a root password with "sudo passwd".
run("sudo apt install -y doas", shell=True)
run("""echo -e "permit $(whoami) as root
permit root as $(whoami)
permit nopass root as $(whoami)"|sudo tee /etc/doas.conf""", shell=True) and run("doas apt -y purge sudo", shell=True)
print("doas set up.")
else:
print("Run me again when you are ready.")
The problem with this code is that it places the option -e
in doas.conf
, like so:
-e permit jim as root
permit root as jim
permit nopass root as jim
while I need doas.conf
to look like so:
permit jim as root
permit root as jim
permit nopass root as jim
I know that the easiest quick fix is simply not to use -e
with echo
. Is there any other way I can resolve this issue?
Why does -e
end up written into doas.conf
if it is not enclosed within double quotes?
When I run
echo -e "permit $(whoami) as root
permit root as $(whoami)
permit nopass root as $(whoami)"|tee doas.conf
from my shell (Bash), then all works fine and I get the desired result. Why is it different from Python? I'm on Ubuntu 22.04 LTS, and my echo seems to support -e, e.g. echo -e "a\nb\nc" it prints them letters with newlines.
/bin/echo -e hello
output on your system? – Kusalananda May 22 '23 at 07:42hello
. – John Smith May 22 '23 at 08:21