diff options
author | Daniil Baturin <daniil@vyos.io> | 2024-02-08 16:11:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-08 16:11:24 +0000 |
commit | 0949fdbf93cd76d7f8c65ed56cdfc27a43c1944f (patch) | |
tree | dd4401900444d1888ff3a04bfa23feb823e27450 | |
parent | 6a0b841718bb83cffbbb198c788f7d634c4c9dc0 (diff) | |
parent | 6e94def372856437d6e2fd6252ae272cc502c87e (diff) | |
download | vyatta-op-0949fdbf93cd76d7f8c65ed56cdfc27a43c1944f.tar.gz vyatta-op-0949fdbf93cd76d7f8c65ed56cdfc27a43c1944f.zip |
Merge pull request #84 from erkin/current
op-mode: T4038: Remove legacy `vyatta-image-tools.pl`
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | functions/interpreter/vyatta-image-complete | 20 | ||||
-rw-r--r-- | functions/interpreter/vyatta-op-run | 4 | ||||
-rwxr-xr-x | scripts/vyatta-image-tools.pl | 289 | ||||
-rw-r--r-- | templates/clone/node.def | 1 | ||||
-rw-r--r-- | templates/clone/system/config/node.def | 1 | ||||
-rw-r--r-- | templates/clone/system/config/node.tag/from/node.def | 1 | ||||
-rw-r--r-- | templates/clone/system/config/node.tag/from/node.tag/node.def | 18 | ||||
-rw-r--r-- | templates/clone/system/config/node.tag/node.def | 14 | ||||
-rw-r--r-- | templates/clone/system/node.def | 1 | ||||
-rw-r--r-- | templates/copy/file/node.def | 1 | ||||
-rw-r--r-- | templates/copy/file/node.tag/node.def | 3 | ||||
-rw-r--r-- | templates/copy/file/node.tag/to/node.def | 1 | ||||
-rw-r--r-- | templates/copy/file/node.tag/to/node.tag/node.def | 10 | ||||
-rw-r--r-- | templates/copy/node.def | 1 | ||||
-rw-r--r-- | templates/delete/file/node.def | 1 | ||||
-rw-r--r-- | templates/delete/file/node.tag/node.def | 10 | ||||
-rw-r--r-- | templates/show/file/node.def | 1 | ||||
-rw-r--r-- | templates/show/file/node.tag/node.def | 10 |
19 files changed, 14 insertions, 374 deletions
diff --git a/Makefile.am b/Makefile.am index 398c259..c5d9322 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,7 +21,6 @@ bin_SCRIPTS += scripts/rename-image.pl bin_SCRIPTS += scripts/show-image-storage.pl bin_SCRIPTS += scripts/vyatta-op-cmd-wrapper -sbin_SCRIPTS = scripts/vyatta-image-tools.pl all-local: ./gen-unpriv-commands.sh diff --git a/functions/interpreter/vyatta-image-complete b/functions/interpreter/vyatta-image-complete index cfc1c90..48110cf 100644 --- a/functions/interpreter/vyatta-image-complete +++ b/functions/interpreter/vyatta-image-complete @@ -48,12 +48,14 @@ _vyatta_image_file_complete() _vyatta_op_completions=( "" " " ) return 0; fi + _vyatta_image_path_complete } -declare -a non_comps=( "http://<user>:<passwd>@<host>/<file>" \ +declare -a non_comps=( "http(s)://<user>:<passwd>@<host>/<file>" \ "scp://<user>:<passwd>@<host>/<file>" \ - "ftp://<user>:<passwd>@<host>/<file>" \ + "sftp://<user>:<passwd>@<host>/<file>" \ + "ftp(s)://<user>:<passwd>@<host>/<file>" \ "tftp://<host>/<file>" ) _vyatta_image_path_complete() @@ -79,9 +81,9 @@ _vyatta_image_path_complete() for i in `seq 0 $[${#reply[@]}-1]`; do file=${reply[$i]} reply[$i]=${file/#\/lib\/live\/mount\/persistence\/boot\//} - reply[$i]="${reply[$i]}://config/" + reply[$i]="${reply[$i]}://" done - reply+=( "running://config/" ) + reply+=( "running://" ) if [[ -d /lib/live/mount/persistence/opt/vyatta/etc/config || -d /lib/live/mount/persistence/config ]]; then reply+=( "disk-install://" ) fi @@ -108,13 +110,13 @@ _vyatta_image_path_complete() for i in `seq 0 $[${#reply[@]}-1]`; do file=${reply[$i]} if [[ $isrunningimg == "running" ]];then - reply[$i]="running://config/" + reply[$i]="running://" elif [[ $isdiskinstall == "disk-install" ]]; then reply[$i]="disk-install://" else reply[$i]=${file/#\/lib\/live\/mount\/persistence\/boot\//} - if [[ -d /ib/live/mount/persistence/boot/${reply[$i]} ]]; then - reply[$i]="${reply[$i]/#\//}://config/" + if [[ -d /lib/live/mount/persistence/boot/${reply[$i]} ]]; then + reply[$i]="${reply[$i]/#\//}://" fi fi done @@ -125,9 +127,9 @@ _vyatta_image_path_complete() if [[ $topdir == "running" ]]; then cur="/${cur}" elif [[ $topdir == "disk-install" ]]; then - cur="/ib/live/mount/persistence/${cur}" + cur="/lib/live/mount/persistence/${cur}" else - cur="/ib/live/mount/persistence/boot/${topdir}/rw/${cur}" + cur="/lib/live/mount/persistence/boot/${topdir}/rw/${cur}" fi reply=( $(compgen -f ${cur}) ) # for loop from _filedirs() in /etc/bash_completion diff --git a/functions/interpreter/vyatta-op-run b/functions/interpreter/vyatta-op-run index ee4cb1c..6bf6645 100644 --- a/functions/interpreter/vyatta-op-run +++ b/functions/interpreter/vyatta-op-run @@ -218,7 +218,9 @@ _vyatta_op_run () local run_cmd=$(_vyatta_op_get_node_def_field $tpath/node.def run) run_cmd=$(_vyatta_op_conv_run_cmd "$run_cmd") # convert the positional parameters local ret=0 - local cmd_regex="^(LESSOPEN=|less|pager|tail|/opt/vyatta/bin/vyatta-tshark-interface-port.pl).*" + # Exception for the `show file` command + local file_cmd='\$\{vyos_op_scripts_dir\}\/file\.py' + local cmd_regex="^(LESSOPEN=|less|pager|tail|(sudo )?$file_cmd).*" if [ -n "$run_cmd" ]; then eval $restore_shopts if [[ -t 1 && "${args[1]}" == "show" && ! $run_cmd =~ $cmd_regex ]] ; then diff --git a/scripts/vyatta-image-tools.pl b/scripts/vyatta-image-tools.pl deleted file mode 100755 index d654a22..0000000 --- a/scripts/vyatta-image-tools.pl +++ /dev/null @@ -1,289 +0,0 @@ -#!/usr/bin/perl -w -use Getopt::Long; -use lib "/opt/vyatta/share/perl5/"; - -use strict; -use IO::Prompt; - -my ($show, $delete, $updateone); -my @copy; -my @update; - -GetOptions( - "show=s" => \$show, - "delete=s" => \$delete, - "update=s{2}" => \@update, - "updateone=s" => \$updateone, - "copy=s{2}" => \@copy -); - -if (defined $show){ - show($show); -} -if (defined $delete){ - delete_file($delete); -} -if (@update){ - update(@update); -} -if (defined($updateone)){ - update($updateone, "running"); -} -if (@copy){ - copy(@copy); -} - -sub conv_file { - my $file = " "; - my $filein = pop(@_); - $file = $filein; - my $topdir; - if ($file =~ /(.+?):\/\/(.*)/){ - $topdir = $1; - $file = $2; - } elsif ($file =~ /^\//) { - $topdir = "running"; - } else { - print "File: $filein not found \n"; - exit 1; - } - if ($topdir eq "running") { - $file = "/$file"; - } elsif (lc($topdir) eq 'disk-install') { - $file = "/lib/live/mount/persistence/$file"; - } elsif (grep { lc($topdir) eq $_ } ("ftp", "tftp", "http", "https", "scp", "sftp")) { - $file = $filein; - $topdir = 'url'; - } else { - if (!-d "/lib/live/mount/persistence/boot/$topdir/rw"){ - print "Image $topdir not found!\n"; - exit 1; - } - $file = "/lib/live/mount/persistence/boot/$topdir/rw/$file"; - } - return ($topdir, $file); -} - -sub conv_file_to_rel { - my ($topdir, $filename) = @_; - if ($topdir eq "running"){ - $filename =~ s?/?$topdir://?; - } elsif ($topdir eq "disk-install") { - $filename =~ s?/lib/live/mount/persistence/?$topdir://?; - } else { - $filename =~ s?/lib/live/mount/persistence/boot/$topdir/rw/?$topdir://?; - } - return $filename; -} - -sub delete_file { - my ($file) = @_; - (my $topdir, $file) = conv_file($file); - if ($topdir eq 'url'){ - print "Cannot delete files from a url\n"; - exit 1; - } - if (-d $file){ - my $print_dir = conv_file_to_rel($topdir,$file); - if (y_or_n("Do you want to erase the entire $print_dir directory?")){ - system("rm -rf $file"); - print("Directory erased\n"); - } - } elsif (-f $file) { - my $print_file = conv_file_to_rel($topdir,$file); - if (y_or_n("Do you want to erase the $print_file file?")){ - system("rm -rf $file"); - print("File erased\n"); - } - } -} - -sub url_copy { - my ($from, $to) = @_; - my ($f_topdir, $t_topdir); - ($f_topdir, $from) = conv_file($from); - ($t_topdir, $to) = conv_file($to); - if ($t_topdir eq 'url' && $f_topdir eq 'url'){ - print "Cannot copy a url to a url\n"; - exit 1; - } elsif($t_topdir eq 'url') { - if (-d $from){ - print "Cannot upload an entire directory to url\n"; - exit 1; - } elsif ($to =~ /http/){ - print "Cannot upload to http url\n"; - exit 1; - } - upload($from, $to); - } elsif ($f_topdir eq 'url') { - if (-d $to){ - $from =~ /.*\/(.*)/; - my $from_file = $1; - $to = "$to/$from_file"; - if (-f "$to") { - if (!y_or_n("This file exists; overwrite if needed?")){ - exit 0; - } - } - } - print "Downloading...\n"; - download($from, $to); - print "Download complete.\n"; - } - exit 0; -} - -sub copy { - my ($from, $to) = @_; - my ($f_topdir, $t_topdir); - ($f_topdir, $from) = conv_file($from); - if ($f_topdir eq 'url'){ - url_copy($from, $to); - } - ($t_topdir, $to) = conv_file($to); - if ($t_topdir eq 'url'){ - url_copy($from, $to); - } - $from =~ /.*\/(.*)/; - my $from_file = $1; - if (-d $from && -e $to && !(-d $to)){ - print "Cannot copy a directory to a file.\n"; - return 1; - } elsif (-f $to || (-d $to && -f "$to/$from_file")) { - if (y_or_n("This file exists; overwrite if needed?")){ - rsync($from, $to); - } - } elsif (-d $to && -d $from){ - if (y_or_n("This directory exists; would you like to merge?")){ - rsync($from, $to); - } - } else { - rsync($from, $to); - } -} - -sub update { - my ($to, $from) = @_; - my ($t_topdir, $f_topdir); - ($f_topdir, $from) = conv_file("$from://"); - if ($f_topdir eq 'url'){ - print "Cannot clone from a url\n"; - exit 1; - } - ($t_topdir, $to) = conv_file("$to://"); - if ($t_topdir eq 'running'){ - print "Cannot clone to running\n"; - exit 1; - } - if ($t_topdir eq 'disk-install'){ - print "Cannot clone to disk-install\n"; - exit 1; - } - if ($t_topdir eq 'url'){ - print "Cannot clone to a url\n"; - exit 1; - } - my $print_from = conv_file_to_rel($f_topdir, $from); - my $print_to = conv_file_to_rel($t_topdir, $to); - my $msg = "WARNING: This is a destructive copy of the /config directories\n". - "This will erase all data in the ".$print_to."config directory\n". - "This data will be replaced with the data from ".$print_from."config\n". - "The current config data will be backed up in ".$print_to."config.preclone\n". - "Do you wish to continue?"; - if (y_or_n("$msg")){ - system("rm -rf $to/config.preclone"); - system("mv $to/config $to/config.preclone") if (-d "$to/config"); - my $confdir="config"; - $confdir="opt/vyatta/etc/config" if ($f_topdir eq "disk-install"); - if (rsync("$from/$confdir", $to) > 0){ - print "Clone Failed!\nRestoring old config\n"; - system("mv $to/config.preclone $to/config"); - } - } -} - -sub rsync { - my ($from,$to) = @_; - system("rsync -a --progress --exclude '.wh.*' $from $to"); - return $?; -} - -sub upload { - my ($from, $to) = @_; - system("python3 -c 'from vyos.remote import upload; upload(\"$from\", \"$to\")'") -} - -sub download { - my ($from, $to) = @_; - system("python3 -c 'from vyos.remote import download; download(\"$to\", \"$from\", progressbar=True, check_space=True)'"); -} - -sub y_or_n { - my ($msg) = @_; - my $process_client = $ENV{'VYATTA_PROCESS_CLIENT'}; - if (defined $process_client){ - return 1 if ($process_client =~ /gui2_rest/); - } - print "$msg (Y/N): "; - my $input = <>; - return 1 if ($input =~ /Y|y/); - return 0; -} - -sub show { - my ($topdir, $file) = conv_file(pop(@_)); - my $output = ""; - if ($topdir eq 'url'){ - print "Cannot show files from a url\n"; - exit 1; - } - if (-d $file) { - print "########### DIRECTORY LISTING ###########\n"; - system("ls -lGph --group-directories-first $file"); - } elsif (-T $file) { - print "########### FILE INFO ###########\n"; - my $filename = conv_file_to_rel($topdir, $file); - print "File Name: $filename\n"; - print "Text File: \n"; - my $lsstr = `ls -lGh $file`; - parsels($lsstr); - print " Description:\t"; - system("file -sb $file"); - print "\n########### FILE DATA ###########\n"; - system("cat $file"); - } elsif ($file =~ /.*\.pcap/){ - print "########### FILE INFO ###########\n"; - my $filename = conv_file_to_rel($topdir, $file); - print "File Name: $filename\n"; - print "Binary File: \n"; - my $lsstr = `ls -lGh $file`; - parsels($lsstr); - print " Description:\t"; - system("file -sb $file"); - print "\n########### FILE DATA ###########\n"; - system("sudo tshark -r $file | less"); - } elsif (-B $file) { - print "########### FILE INFO ###########\n"; - my $filename = conv_file_to_rel($topdir, $file); - print "File Name: $filename\n"; - print "Binary File: \n"; - my $lsstr = `ls -lGh $file`; - parsels($lsstr); - print " Description:\t"; - system("file -sb $file"); - print "\n########### FILE DATA ###########\n"; - system("hexdump -C $file| less"); - } else { - my $filename = conv_file_to_rel($topdir, $file); - print "File: $filename not found\n"; - } -} - -sub parsels { - my $lsout = pop(@_); - my @ls = split(' ', $lsout); - print " Permissions: $ls[0]\n"; - print " Owner:\t$ls[2]\n"; - print " Size:\t\t$ls[3]\n"; - print " Modified:\t$ls[4] $ls[5] $ls[6]\n"; -} diff --git a/templates/clone/node.def b/templates/clone/node.def deleted file mode 100644 index 25c577a..0000000 --- a/templates/clone/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Clone an object diff --git a/templates/clone/system/config/node.def b/templates/clone/system/config/node.def deleted file mode 100644 index 0b1b387..0000000 --- a/templates/clone/system/config/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Clone system configuration diff --git a/templates/clone/system/config/node.tag/from/node.def b/templates/clone/system/config/node.tag/from/node.def deleted file mode 100644 index 6c2682c..0000000 --- a/templates/clone/system/config/node.tag/from/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Image to clone from diff --git a/templates/clone/system/config/node.tag/from/node.tag/node.def b/templates/clone/system/config/node.tag/from/node.tag/node.def deleted file mode 100644 index d883c8c..0000000 --- a/templates/clone/system/config/node.tag/from/node.tag/node.def +++ /dev/null @@ -1,18 +0,0 @@ -help: Image to update from -allowed: reply=( $(compgen -d /lib/live/mount/persistence/boot/ | grep -v grub) ) - for i in `seq 0 $[${#reply[@]}-1]`; do - file=${reply[$i]} - reply[$i]=${file/#\/lib\/live\/mount\/persistence\/boot\//} - done - reply+=( "running" ) - if [[ -d /lib/live/mount/persistence/config ]];then - reply+=( "disk-install" ) - fi - echo "${reply[*]}" -run: if [ "$VYATTA_USER_LEVEL_DIR" == "/opt/vyatta/etc/shell/level/admin" ]; - then - sudo ${vyatta_sbindir}/vyatta-image-tools.pl --update $4 $6 - else - echo Must be an admin user to run this command. - fi - diff --git a/templates/clone/system/config/node.tag/node.def b/templates/clone/system/config/node.tag/node.def deleted file mode 100644 index ec82322..0000000 --- a/templates/clone/system/config/node.tag/node.def +++ /dev/null @@ -1,14 +0,0 @@ -help: Image to update -allowed: reply=( $(compgen -d /lib/live/mount/persistence/boot/ | grep -v grub) ) - for i in `seq 0 $[${#reply[@]}-1]`; do - file=${reply[$i]} - reply[$i]=${file/#\/lib\/live\/mount\/persistence\/boot\//} - done - echo "${reply[*]}" -run: if [ "$VYATTA_USER_LEVEL_DIR" == "/opt/vyatta/etc/shell/level/admin" ]; - then - sudo ${vyatta_sbindir}/vyatta-image-tools.pl --updateone $4 - else - echo Must be an admin user to run this command. - fi - diff --git a/templates/clone/system/node.def b/templates/clone/system/node.def deleted file mode 100644 index ea29628..0000000 --- a/templates/clone/system/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Clone a system object diff --git a/templates/copy/file/node.def b/templates/copy/file/node.def deleted file mode 100644 index e1b2447..0000000 --- a/templates/copy/file/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Copy files diff --git a/templates/copy/file/node.tag/node.def b/templates/copy/file/node.tag/node.def deleted file mode 100644 index 50b9153..0000000 --- a/templates/copy/file/node.tag/node.def +++ /dev/null @@ -1,3 +0,0 @@ -help: Copy files from specified source -comptype: imagefiles -allowed: echo -n "<imagefiles>" diff --git a/templates/copy/file/node.tag/to/node.def b/templates/copy/file/node.tag/to/node.def deleted file mode 100644 index 21f3ade..0000000 --- a/templates/copy/file/node.tag/to/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Path to copy into diff --git a/templates/copy/file/node.tag/to/node.tag/node.def b/templates/copy/file/node.tag/to/node.tag/node.def deleted file mode 100644 index b9a136e..0000000 --- a/templates/copy/file/node.tag/to/node.tag/node.def +++ /dev/null @@ -1,10 +0,0 @@ -help: Copy files to specified destination -comptype: imagefiles -allowed: echo -n "<imagefiles>" -run: if [ "$VYATTA_USER_LEVEL_DIR" == "/opt/vyatta/etc/shell/level/admin" ]; - then - sudo ${vyatta_sbindir}/vyatta-image-tools.pl --copy $3 $5 - else - echo Must be an admin user to run this command. - fi - diff --git a/templates/copy/node.def b/templates/copy/node.def deleted file mode 100644 index eb33037..0000000 --- a/templates/copy/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Copy an object diff --git a/templates/delete/file/node.def b/templates/delete/file/node.def deleted file mode 100644 index 92c8f6c..0000000 --- a/templates/delete/file/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Delete files in a particular image diff --git a/templates/delete/file/node.tag/node.def b/templates/delete/file/node.tag/node.def deleted file mode 100644 index 0faf383..0000000 --- a/templates/delete/file/node.tag/node.def +++ /dev/null @@ -1,10 +0,0 @@ -help: Delete files in the specified directory -comptype: imagefiles -allowed: echo -n "<imagefiles>" -run: if [ "$VYATTA_USER_LEVEL_DIR" == "/opt/vyatta/etc/shell/level/admin" ]; - then - sudo ${vyatta_sbindir}/vyatta-image-tools.pl --delete=$3 - else - echo Must be an admin user to run this command. - fi - diff --git a/templates/show/file/node.def b/templates/show/file/node.def deleted file mode 100644 index a6c408d..0000000 --- a/templates/show/file/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Show files for a particular image diff --git a/templates/show/file/node.tag/node.def b/templates/show/file/node.tag/node.def deleted file mode 100644 index 8d3eb32..0000000 --- a/templates/show/file/node.tag/node.def +++ /dev/null @@ -1,10 +0,0 @@ -help: Show files in the specified directory -comptype: imagefiles -allowed: echo -n "<imagefiles>" -run: if [ "$VYATTA_USER_LEVEL_DIR" == "/opt/vyatta/etc/shell/level/admin" ]; - then - sudo ${vyatta_sbindir}/vyatta-image-tools.pl --show=$3 - else - echo Must be an admin user to run this command. - fi - |