Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
virtu
scripts
Commits
25caebfa
Verified
Commit
25caebfa
authored
1 year ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
feat: comms with VM script, painful experience ngl
parent
fd12228a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
qga_comms.sh
+40
-0
40 additions, 0 deletions
qga_comms.sh
with
40 additions
and
0 deletions
qga_comms.sh
0 → 100755
+
40
−
0
View file @
25caebfa
#!/usr/bin/env bash
if
[
$#
-eq
0
]
;
then
echo
"Usage:
$0
<message>"
exit
1
fi
user_msg
=
$1
first_user
=
$(
{
echo
'{"execute":"guest-get-users"}'
;
sleep
1
;
}
| socat unix-connect:/tmp/qga.sock - | jq
-r
'.return[0].user'
)
echo
"First user:
$first_user
"
file_path
=
"/home/"
$first_user
"/busted"
echo
"Creating file:
$file_path
"
create_file_cmd
=
$(
jq
-n
--arg
file_path
"
$file_path
"
'{"execute":"guest-file-open", "arguments":{"path":$file_path,"mode":"w"}}'
)
file_handle
=
$(
{
echo
$create_file_cmd
;
sleep
1
;
}
| socat unix-connect:/tmp/qga.sock - | jq
'.return'
)
bytes_count
=
$(
echo
-n
$user_msg
|
wc
-c
|
awk
'{print $1}'
)
encoded_str
=
$(
echo
-n
$user_msg
|
base64
|
tr
-d
'\n'
)
int_handle
=
$((
file_handle
))
int_bytes_count
=
$((
bytes_count
))
write_to_file_cmd
=
$(
jq
-n
--argjson
int_handle
"
$int_handle
"
\
--arg
encoded_str
"
$encoded_str
"
\
--argjson
int_bytes_count
"
$int_bytes_count
"
\
'{"execute":"guest-file-write", "arguments":{"handle":$int_handle,"buf-b64":$encoded_str,"count":$int_bytes_count}}'
)
echo
"Writing to
$file_path
(
$file_handle
)..."
{
echo
$write_to_file_cmd
;
sleep
1
;
}
| socat unix-connect:/tmp/qga.sock -
>
/dev/null
close_file_cmd
=
$(
jq
-n
--argjson
int_handle
"
$int_handle
"
\
'{"execute":"guest-file-close", "arguments":{"handle":$int_handle}}'
)
echo
"Closing
$file_path
(
$file_handle
)..."
{
echo
$close_file_cmd
;
sleep
1
;
}
| socat unix-connect:/tmp/qga.sock -
>
/dev/null
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment