generated from NethServer/ns8-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store admin password in separate file
- Loading branch information
Showing
4 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2023 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
import sys | ||
import agent | ||
import os | ||
|
||
# Get the ADMIN_PASSWORD environment variable | ||
admin_password = os.getenv('ADMIN_PASSWORD') | ||
|
||
# Define the path for the password file | ||
password_file_path = os.path.expanduser('~/.config/state/password.env') | ||
|
||
if admin_password: | ||
# Write the ADMIN_PASSWORD to the file | ||
password = {"ADMIN_PASSWORD": admin_password} | ||
agent.write_envfile("password.env", password) | ||
|
||
# Set the file permissions to be readable and writable only by the user | ||
os.chmod(password_file_path, 0o600) | ||
|
||
# Check if the file is not empty | ||
if os.path.getsize(password_file_path) > 0: | ||
print("Password file of collabora created", file=sys.stderr) | ||
agent.unset_env("ADMIN_PASSWORD") | ||
else: | ||
print(agent.SD_WARNING + "Error Password file of collabora is empty", file=sys.stderr) | ||
exit(1) |