Merge branch 'bash_history' into 'main'

support configuring the content of the bash_history in the YAML config

See merge request systemrescue/systemrescue-sources!250
This commit is contained in:
Gerd v. Egidy 2022-12-11 18:36:20 +00:00
commit f84d4aa6a1
3 changed files with 25 additions and 1 deletions

View file

@ -364,6 +364,27 @@ if 'sysconfig' in config and 'authorized_keys' in config['sysconfig'] and \
print(e)
errcnt+=1
# ==============================================================================
# configure bash_history
# do this after late-loading SRMs because we want to add to what is contained in a SRM
# ==============================================================================
if 'sysconfig' in config and 'bash_history' in config['sysconfig'] and \
config['sysconfig']['bash_history'] and isinstance(config['sysconfig']['bash_history'], dict):
print(f"====> Configuring bash_history ...")
try:
# append all our entries in case the file already exists
with open("/root/.bash_history", "a") as historyfile:
# iterate reverse sorted, the first key is written last and will appear first when pressing the up key
for key, command in sorted(config['sysconfig']['bash_history'].items(),reverse=True):
historyfile.write(f"{command}\n")
historyfile.close()
except Exception as e:
print(e)
errcnt+=1
# ==============================================================================
# autoterminal: programs that take over a virtual terminal for user interaction
# ==============================================================================

View file

@ -1 +0,0 @@
setkmap

View file

@ -15,3 +15,7 @@ autorun:
ar_attempts: 1
ar_ignorefail: false
ar_suffixes: "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F"
sysconfig:
bash_history:
100: "setkmap"