diff options
author | erkin <e.altunbas@vyos.io> | 2021-03-30 13:12:30 +0300 |
---|---|---|
committer | erkin <e.altunbas@vyos.io> | 2021-03-30 13:12:30 +0300 |
commit | 276ca84c2276652d75885138670ff73fc2aeaba8 (patch) | |
tree | 04a21afe86985dc97e789a0b5201c972e388a2d7 /scripts | |
parent | 621114584ac967f03f22701d3a795169b0d2f73c (diff) | |
download | vyatta-op-276ca84c2276652d75885138670ff73fc2aeaba8.tar.gz vyatta-op-276ca84c2276652d75885138670ff73fc2aeaba8.zip |
T3356: Replace vyatta-remote-copy.pl with remote.py
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/tech-support-archive | 78 | ||||
-rwxr-xr-x | scripts/vyatta-remote-copy.pl | 94 |
2 files changed, 38 insertions, 134 deletions
diff --git a/scripts/tech-support-archive b/scripts/tech-support-archive index 9524557..2321d76 100755 --- a/scripts/tech-support-archive +++ b/scripts/tech-support-archive @@ -19,54 +19,52 @@ do_rotate () HOSTNAME=`hostname` CURTIME=`date +%F-%H%M%S` - - if [ -n "$1" ]; then - if [[ "$1" =~ scp:///* ]]; then - OUT="$HOSTNAME.tech-support-archive.$CURTIME" - REMOTE="1" - elif [[ "$1" =~ ftp:///* ]]; then - OUT="$HOSTNAME.tech-support-archive.$CURTIME" - REMOTE="1" - else - #file to be save locally - OUT="$1.$HOSTNAME.tech-support-archive.$CURTIME" - fi - else +if [ -n "$1" ]; then + if [[ "$1" =~ scp:///* ]]; then + OUT="$HOSTNAME.tech-support-archive.$CURTIME" + REMOTE="1" + elif [[ "$1" =~ ftp:///* ]]; then OUT="$HOSTNAME.tech-support-archive.$CURTIME" + REMOTE="1" + else + # File to be saved locally + OUT="$1.$HOSTNAME.tech-support-archive.$CURTIME" fi +else + OUT="$HOSTNAME.tech-support-archive.$CURTIME" +fi + +if [[ $OUT != /* ]]; then + FILE_NAME=$OUT + do_rotate + # it's not absolute path. save in default path. + OUT="$DEFAULT_PATH/$OUT" + mkdir -p $OUT >& /dev/null + chgrp $DEFAULT_GROUP $OUT >& /dev/null + chmod 775 $OUT >& /dev/null +else + mkdir -p $OUT >& /dev/null + chgrp $DEFAULT_GROUP $OUT >& /dev/null + chmod 775 $OUT >& /dev/null + FILE_NAME=`echo $OUT | sed -e 's/\//\n/g' | tail -1` +fi - if [[ $OUT != /* ]]; then - FILE_NAME=$OUT - do_rotate - # it's not absolute path. save in default path. - OUT="$DEFAULT_PATH/$OUT" - mkdir -p $OUT >& /dev/null - chgrp $DEFAULT_GROUP $OUT >& /dev/null - chmod 775 $OUT >& /dev/null - else - mkdir -p $OUT >& /dev/null - chgrp $DEFAULT_GROUP $OUT >& /dev/null - chmod 775 $OUT >& /dev/null - FILE_NAME=`echo $OUT | sed -e 's/\//\n/g' | tail -1` - fi builtin cd "$OUT" -echo "Saving the archivals..." -sudo tar -zcf config.tgz /opt/vyatta/etc/config --exclude "*tech-support-archive*" >& /dev/null -sudo tar -zcf etc.tgz /etc >& /dev/null -sudo tar -zcf home.tgz /home >& /dev/null -sudo tar -zcf var-log.tgz /var/log >& /dev/null -sudo tar -zcf root.tgz /root >& /dev/null -sudo tar -zcf tmp.tgz /tmp >& /dev/null -sudo tar -zcf core-dump.tgz /var/core >& /dev/null +echo "Saving the archives..." +sudo tar zcf config.tgz /opt/vyatta/etc/config --exclude "*tech-support-archive*" >& /dev/null +sudo tar zcf etc.tgz /etc >& /dev/null +sudo tar zcf home.tgz /home >& /dev/null +sudo tar zcf var-log.tgz /var/log >& /dev/null +sudo tar zcf root.tgz /root >& /dev/null +sudo tar zcf tmp.tgz /tmp >& /dev/null +sudo tar zcf core-dump.tgz /var/core >& /dev/null builtin cd "../" -sudo tar -zcvf $FILE_NAME.tgz $FILE_NAME >& /dev/null +sudo tar zcvf $FILE_NAME.tgz $FILE_NAME >& /dev/null sudo rm -r $FILE_NAME -OUT=$OUT.tgz +OUT=$OUT.tgz echo "Saved tech-support archival at $OUT" if [ $REMOTE == "1" ]; then - perl /opt/vyatta/bin/vyatta-remote-copy.pl $1 $OUT $FLAG + python3 -c "from vyos.remote import upload; upload(\"$OUT\", \"$1\")" fi - -exit diff --git a/scripts/vyatta-remote-copy.pl b/scripts/vyatta-remote-copy.pl deleted file mode 100755 index 23dd135..0000000 --- a/scripts/vyatta-remote-copy.pl +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/perl - -# Author: Deepti Kulkarni -# Date: May 2010 -# Description: script to save file remotely. - -# **** License **** -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# 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. -# -# This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2006, 2007, 2008 Vyatta, Inc. -# All Rights Reserved. -# **** End License **** - -use strict; -use lib "/opt/vyatta/share/perl5"; -use IO::Prompt; - -my $save_file; - -if (defined($ARGV[0])) { - $save_file = $ARGV[0]; -} -my $tmp_file = $ARGV[1]; -my $flag = $ARGV[2]; - -my $mode = 'local'; -my $proto; - -if ($save_file =~ /^[^\/]\w+:\//) { - -if ($save_file =~ /^(\w+):\/\/\w/) { - $mode = 'url'; - $proto = lc($1); - if ($proto eq 'ftp') { - } - elsif ($proto eq 'scp') { - } else { - print "Invalid url protocol [$proto]\n"; - exit 1; - } - } else { - print "Invalid url [$save_file]\n"; - exit 1; - } -} -if ($flag == 0) -{ - $save_file=$save_file . ".gz" -} -if ($flag == 2) -{ - $save_file=$save_file . ".tgz" -} -if ($mode eq 'url') { - print "Saving output to $save_file\n"; - my $rc = system("curl -# -T $tmp_file $save_file"); - if ($proto eq 'scp' && ($rc >> 8) == 51){ - $save_file =~ m/scp:\/\/(.*?)\//; - my $host = $1; - if ($host =~ m/.*@(.*)/) { - $host = $1; - } - my $rsa_key = `ssh-keyscan -t rsa $host 2>/dev/null`; - print "The authenticity of host '$host' can't be established.\n"; - my $fingerprint = `ssh-keygen -lf /dev/stdin <<< \"$rsa_key\" | awk {' print \$2 '}`; - chomp $fingerprint; - print "RSA key fingerprint is $fingerprint.\n"; - if (prompt("Are you sure you want to continue connecting (yes/no) [Yes]? ", -tynd=>"y")) { - mkdir "~/.ssh/"; - open(my $known_hosts, ">>", "$ENV{HOME}/.ssh/known_hosts") - or die "Cannot open known_hosts: $!"; - print $known_hosts "$rsa_key\n"; - close($known_hosts); - $rc = system("curl -# -T $tmp_file $save_file"); - print "\n"; - } - } - system("rm -f $tmp_file"); - if ($rc) { - print "Error saving $save_file\n"; - exit 1; - } -} - -print "Done\n"; -exit 0; |