multipass update

master
Kebler Network System Administrator 2022-03-28 10:06:42 -07:00
parent 8ffd43d25e
commit 04b6d727f1
2 changed files with 37 additions and 10 deletions

View File

@ -10,3 +10,5 @@ alias mps="multipass shell"
alias mpssh="multipass_ssh"
alias mprm="multipass_remove"
alias mph="multipass --help"
alias mpscr="multipass_ssh_script"
alias mprd="sudo snap restart multipass.multipassd"

View File

@ -27,12 +27,13 @@ multipass_launch () {
}
multipass_get_sshid () {
dest=${1:-$HOME/.ssh/multipass_id_rsa}
dest=${1:-$HOME/.ssh/multipass_key}
[[ -f $dest ]] && echo $dest && return 0
src=${SNAP_VAR:-/var/snap}/multipass/common/data/multipassd/ssh-keys/id_rsa
[[ ! -f $src ]] && return 1
sudo cp $src $dest
sudo chown $USER:$USER $dest
chmod 600 $dest
echo $dest
}
@ -41,21 +42,38 @@ multipass_get_ip () {
json=$(multipass info --format json $1 2> /dev/null)
[[ ! $json ]] && return 2
ip=$(echo "$json" | jq -r .info.$1.ipv4[0] 2> /dev/null)
[[ $ip ]] && echo $ip || return 3
[[ $ip = "null" ]] && return 3
[[ $ip ]] && echo $ip || return 4
return 0
}
multipass_ssh () {
[[ ! $1 ]] && echo must supply name of instance name && return 1
ip=$(multipass_get_ip $1)
[[ ! $ip ]] && echo "no ip for instance $1, aborting" && return
multipass_ssh_options () {
id=$(multipass_get_sshid)
user=${2:-ubuntu}
echo ssh -i $id $user@$ip
ssh -i $id $user@$ip
[[ $? -gt 0 ]] && return 1
echo -o IdentitiesOnly=yes -o IdentityFile=$id
return 0
}
multipass_scp () {
multipass_ssh_cmd () {
[[ ! $1 ]] && { echo must supply name of instance name; return 1; }
ip=$(multipass_get_ip $1)
[[ ! $ip ]] && { echo "no ip for instance $1"; return 2; }
user=${2:-ubuntu}
opts=$(multipass_ssh_options)
[[ ! $opts ]] && return 3
echo $opts $user@$ip
return 0
}
multipass_ssh () {
cmd=$(multipass_ssh_cmd $@) || { echo failed: $cmd;return $?; }
echo ssh $cmd
ssh $cmd
}
multipass_scp () {
[[ $1 = "-u" ]] && user=$2 && shift 2 || user=ubuntu
[[ ! $1 ]] && echo must supply name of instance name && return 1
ip=$(multipass_get_ip $1)
@ -66,3 +84,10 @@ multipass_get_ip () {
echo sudo scp -i $id -r $2 $user@$ip:$3
sudo scp -i $id $2 $user@$ip:$3
}
multipass_ssh_script () {
cmd=$(multipass_ssh_cmd $2) || { echo failed: $cmd;return $?; }
module_load remote
remote_script $1 "$cmd"
}