From ec622fdf959611c364c80857fe1b7658c7470776 Mon Sep 17 00:00:00 2001 From: iliajie Date: Sat, 12 Nov 2022 11:32:39 +0200 Subject: [PATCH] Add code comments --- xterm/shellserver.pl | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/xterm/shellserver.pl b/xterm/shellserver.pl index 635db2571..474cd32d2 100755 --- a/xterm/shellserver.pl +++ b/xterm/shellserver.pl @@ -75,27 +75,42 @@ if ($shinit) { } }; + # Does the current user shell have init + # files in our internal shell flavors if ($shfiles) { SHFILES: foreach my $shfile (@{$shfiles}) { + # Files that are sourced inside of standard + # shell init files can contain full path my $shfile_path = $shfile !~ /^\// ? "$uinfo[7]/$shfile" : $shfile; if (-r $shfile_path) { + # Read one of the standard shell init files my $shfile_ref = &read_file_lines($shfile_path, 1); foreach my $shfile_line (@$shfile_ref) { my $shfile_line_opt = &$shparse_opt($shfile_line); - # Check for an active PS1 option + # Check for an active (not commented) + # user-defined PS1 option if ($shfile_line_opt && $shfile_line_opt->{'PS1'}) { + # User already have PS1 set, skipping further checks + # and disabling internal (our own) PS1 customisations map { $_->{'ps1'} && delete($_->{'ps1'}) } @{$shcmds}; last SHFILES; } # Check for other sourced files else { + # Perhaps the standard shell init files source other, + # files if so we need to add them for a check up too if ($shfile_line =~ /\s*^(?!#)\s*(\.|source)(?.*)/) { my $sourced_file = "$+{sourced_file}"; $sourced_file =~ s/^\s+//; $sourced_file =~ s/\s+$//; $sourced_file =~ s/^\~\///; + + # A file that is being sourced is found, add it + # for a check up unless a file already exists in + # array and add only if found file us under user + # home directory push(@{$shfiles}, $sourced_file) if (!grep(/^$sourced_file$/, @{$shfiles}) && ($sourced_file !~ /^\// || @@ -109,8 +124,10 @@ if ($shinit) { } } -# User config enviromental variables +# User config environmental variables if ($config{'flavors_envs'}) { + # Admin added to the module config custom + # environmental variables, load them now my @flavors_envs = split(/\t+/, $config{'flavors_envs'}); foreach my $flavors_env (@flavors_envs) { my ($k, $v) = split(/=/, $flavors_env, 2); @@ -118,7 +135,9 @@ if ($config{'flavors_envs'}) { } } -# Add additional shell envs +# Add additional shell envs from internal +# shell flavors if defined for the +# current user shell if ($shinit && $shinit->{'envs'}) { foreach my $env (@{$shinit->{'envs'}}) { foreach my $shopt (keys %{$env}) { @@ -146,6 +165,8 @@ print STDERR "shell process is $pid\n"; # User config commands to run on shell login if ($config{'flavors_cmds'}) { + # Admin added to the module config custom + # commands to run on shell login, run now my @flavors_cmds = split(/\t+/, $config{'flavors_cmds'}); foreach my $flavors_cmd (@flavors_cmds) { my $cmd = " $flavors_cmd\r"; @@ -153,7 +174,9 @@ if ($config{'flavors_cmds'}) { } } -# Add additional shell init commands +# Run additional shell commands from internal +# shell flavors, if defined for the current +# user shell to run after initial login if ($shinit && $shinit->{'cmds'}) { foreach my $cmd (@{$shinit->{'cmds'}}) { foreach my $shopt (keys %{$cmd}) {