From c298904d9d9a12281b368dd180f3e8b4f7aba898 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 8 Jul 2020 17:41:28 +0200 Subject: Tree update --- README.org | 4 +-- src/gitjoe/adduser.pl | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/gitjoe/newuser.pl | 77 --------------------------------------------------- src/vps-do.pl | 25 +++++++++++++++-- 4 files changed, 101 insertions(+), 82 deletions(-) create mode 100755 src/gitjoe/adduser.pl delete mode 100755 src/gitjoe/newuser.pl diff --git a/README.org b/README.org index 6ba54bb..20c81e2 100644 --- a/README.org +++ b/README.org @@ -17,10 +17,10 @@ The source tree is the following: └── src ├── gitjoe │   ├── addsshkey.pl + │   ├── adduser.pl │   ├── chdesc.pl │   ├── chowner.pl │   ├── newrepo.pl - │   ├── newuser.pl │   ├── rmrepo.pl │   └── rmuser.pl ├── other @@ -34,4 +34,4 @@ The source tree is the following: - ~gitjoe/~ scripts are meant to be run on the server directly. They are tools to add GitJoe users, repos, change descritpion, etc. - ~update/~ scripts are run via cron jobs. They update the GitJoe repositories front-end website via ~stagit~ and pull ~master~ branches of the websites via ~git~. - ~other/~ script is just a single line the start the ~git daemon~ to serve public repositories. -- The ~vps-do.pl~ script allows you to execute one of the distant scripts on your home terminal, opening and closing the ~ssh~ session for you. +- The ~vps-do.pl~ script allows you to execute one of the distant scripts from your home terminal, opening and closing the ~ssh~ session for you. You still need the ~dash~ shell as a dependency on your home terminal. diff --git a/src/gitjoe/adduser.pl b/src/gitjoe/adduser.pl new file mode 100755 index 0000000..a141277 --- /dev/null +++ b/src/gitjoe/adduser.pl @@ -0,0 +1,77 @@ +#!/usr/local/bin/perl + +use strict; +use warnings; +use Term::ANSIColor; + +sub main { + my $argc = $#ARGV + 1; + if ($argc < 3) { + print colored("Failed!\n", 'bold red') + . "Missing argument, 3 needed " + . colored("[user - password - ssh public key]", 'bold') + . "\n"; + exit 1; + } + my $usr = $ARGV[0]; + my $pass = $ARGV[1]; + my $sshkey = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty "; + $sshkey = $sshkey . $ARGV[2]; + my $home_dir = '/usr/home/' . $usr . '/'; + system( + '/usr/local/bin/dash', + '-c', + "adduser << EOF +" . $usr . " + + + + + +git-shell + + + + + +" . $pass . " +" . $pass . " + +yes +no +EOF" + ); + system( + '/usr/local/bin/dash', + '-c', + '/bin/mkdir -v ' . $home_dir . '.ssh/' + ); + system( + '/usr/local/bin/dash', + '-c', + '/usr/sbin/chown -v ' . $usr . ':' . $usr . ' ' . $home_dir . '.ssh/' + ); + system( + '/usr/local/bin/dash', + '-c', + '/bin/chmod -v 700 ' . $home_dir . '.ssh/' + ); + open(my $fh, '>:encoding(UTF-8)', $home_dir . '.ssh/authorized_keys'); + print $fh $sshkey . "\n"; + close($fh); + system( + '/usr/local/bin/dash', + '-c', + '/usr/sbin/chown -v ' . $usr . ':' . $usr . ' ' . $home_dir . '.ssh/authorized_keys' + ); + system( + '/usr/local/bin/dash', + '-c', + '/bin/chmod -v 600 ' . $home_dir . '.ssh/authorized_keys' + ); + exit; +} + +main(); + +__END__ diff --git a/src/gitjoe/newuser.pl b/src/gitjoe/newuser.pl deleted file mode 100755 index a141277..0000000 --- a/src/gitjoe/newuser.pl +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; - -sub main { - my $argc = $#ARGV + 1; - if ($argc < 3) { - print colored("Failed!\n", 'bold red') - . "Missing argument, 3 needed " - . colored("[user - password - ssh public key]", 'bold') - . "\n"; - exit 1; - } - my $usr = $ARGV[0]; - my $pass = $ARGV[1]; - my $sshkey = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty "; - $sshkey = $sshkey . $ARGV[2]; - my $home_dir = '/usr/home/' . $usr . '/'; - system( - '/usr/local/bin/dash', - '-c', - "adduser << EOF -" . $usr . " - - - - - -git-shell - - - - - -" . $pass . " -" . $pass . " - -yes -no -EOF" - ); - system( - '/usr/local/bin/dash', - '-c', - '/bin/mkdir -v ' . $home_dir . '.ssh/' - ); - system( - '/usr/local/bin/dash', - '-c', - '/usr/sbin/chown -v ' . $usr . ':' . $usr . ' ' . $home_dir . '.ssh/' - ); - system( - '/usr/local/bin/dash', - '-c', - '/bin/chmod -v 700 ' . $home_dir . '.ssh/' - ); - open(my $fh, '>:encoding(UTF-8)', $home_dir . '.ssh/authorized_keys'); - print $fh $sshkey . "\n"; - close($fh); - system( - '/usr/local/bin/dash', - '-c', - '/usr/sbin/chown -v ' . $usr . ':' . $usr . ' ' . $home_dir . '.ssh/authorized_keys' - ); - system( - '/usr/local/bin/dash', - '-c', - '/bin/chmod -v 600 ' . $home_dir . '.ssh/authorized_keys' - ); - exit; -} - -main(); - -__END__ diff --git a/src/vps-do.pl b/src/vps-do.pl index 3c165c1..2ce11ff 100755 --- a/src/vps-do.pl +++ b/src/vps-do.pl @@ -18,10 +18,10 @@ sub main { my $ssh_boy = 'root@jozanleclerc.xyz'; if ( $ARGV[0] eq 'addsshkey' || + $ARGV[0] eq 'adduser' || $ARGV[0] eq 'chdesc' || $ARGV[0] eq 'chowner' || $ARGV[0] eq 'newrepo' || - $ARGV[0] eq 'newuser' || $ARGV[0] eq 'rmrepo' || $ARGV[0] eq 'rmuser' ) { @@ -40,17 +40,36 @@ sub main { . colored($ARGV[0], 'bold yellow') . ": unknown script. Known scripts are:\n" . colored("addsshkey\n", 'bold green') + . colored("adduser\n", 'bold green') . colored("chdesc\n", 'bold green') . colored("chowner\n", 'bold green') . colored("newrepo\n", 'bold green') - . colored("newuser\n", 'bold green') . colored("rmrepo\n", 'bold green') . colored("rmuser\n", 'bold green') . colored("update-gitjoe\n", 'bold green') . colored("update-vps\n", 'bold green'); exit 2; } - print "Calling " . colored($called_script, 'bold green') . " via " . colored($ssh_boy, 'bold') . "...\n"; + print "Calling " . colored($called_script, 'bold green') . " via " . colored($ssh_boy, 'bold magenta') . ".\n"; + if ($argc > 1) { + print "Arguments:\n"; + my $i = 1; + while ($i < $argc) { + print colored($ARGV[$i], 'bold yellow') . "\n"; + $i += 1; + } + } + my $dash = `/bin/sh -c "which dash"`; + chomp $dash; + system( + $dash, + '-c', + 'ssh ' . $ssh_boy . " << EOF 2>&1 +ls -lh +uname -n +exit +" + ); exit; } -- cgit v1.2.3