subiquity/system_setup/common/wsl_utils.py

36 lines
1.2 KiB
Python

#!/usr/bin/env python3
# Copyright 2015-2021 Canonical, Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
def is_reconfigure(is_dryrun):
if is_dryrun and os.getenv("DRYRUN_RECONFIG") == "true":
return True
if_normaluser = False
with open("/etc/passwd", "r") as f:
for line in f:
# check every normal user except nobody (65534)
if int(line.split(":")[2]) >= 1000 and int(line.split(":")[2]) != 65534:
if_normaluser = True
break
return not is_dryrun and if_normaluser
def convert_if_bool(value):
if value.lower() in ("true", "false"):
return value.lower() == "true"
return value