Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Local variables #447

Merged
merged 5 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ fi
location=$(cat "$file")

if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
rm -f $file
echo "Failed to reach http://$location"
exit 1
fi
Expand Down
29 changes: 5 additions & 24 deletions src/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ ext2fmt() {

getSize() {
local DISK_FILE=$1
local DISK_EXT
local DISK_FMT
local DISK_EXT DISK_FMT

DISK_EXT="$(echo "${DISK_FILE//*./}" | sed 's/^.*\.//')"
DISK_FMT="$(ext2fmt "$DISK_EXT")"
Expand All @@ -77,18 +76,13 @@ getSize() {
}

resizeDisk() {

local GB
local REQ
local FAIL
local SPACE
local SPACE_GB
local DISK_FILE=$1
local CUR_SIZE=$2
local DATA_SIZE=$3
local DISK_SPACE=$4
local DISK_DESC=$5
local DISK_FMT=$6
local GB REQ FAIL SPACE SPACE_GB

GB=$(( (CUR_SIZE + 1073741823)/1073741824 ))
info "Resizing $DISK_DESC from ${GB}G to $DISK_SPACE .."
Expand Down Expand Up @@ -135,7 +129,6 @@ resizeDisk() {
}

convertDisk() {

local CONV_FLAGS="-p"
local SOURCE_FILE=$1
local SOURCE_FMT=$2
Expand All @@ -153,15 +146,11 @@ convertDisk() {
}

createDisk() {

local GB
local FAIL
local SPACE
local SPACE_GB
local DISK_FILE=$1
local DISK_SPACE=$2
local DISK_DESC=$3
local DISK_FMT=$4
local GB FAIL SPACE SPACE_GB

FAIL="Could not create a $DISK_SPACE $DISK_FMT file for $DISK_DESC ($DISK_FILE)"

Expand Down Expand Up @@ -206,12 +195,6 @@ createDisk() {
}

addDisk () {

local FS
local DIR
local CUR_SIZE
local DATA_SIZE
local DISK_FILE
local DISK_ID=$1
local DISK_BASE=$2
local DISK_EXT=$3
Expand All @@ -220,6 +203,7 @@ addDisk () {
local DISK_INDEX=$6
local DISK_ADDRESS=$7
local DISK_FMT=$8
local FS DIR CUR_SIZE DATA_SIZE DISK_FILE

DISK_FILE="$DISK_BASE.$DISK_EXT"
DIR=$(dirname "$DISK_FILE")
Expand All @@ -239,9 +223,7 @@ addDisk () {
fi

if ! [ -f "$DISK_FILE" ] ; then
local PREV_EXT
local PREV_FMT
local PREV_FILE
local PREV_EXT PREV_FMT PREV_FILE TMP_FILE

if [[ "${DISK_FMT,,}" != "raw" ]]; then
PREV_FMT="raw"
Expand All @@ -256,7 +238,6 @@ addDisk () {
info "Detected that ${DISK_DESC^^}_FMT changed from \"$PREV_FMT\" to \"$DISK_FMT\"."
info "Starting conversion of $DISK_DESC to this new format, please wait until completed..."

local TMP_FILE
TMP_FILE="$DISK_BASE.tmp"
rm -f "$TMP_FILE"

Expand Down
1 change: 1 addition & 0 deletions src/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ configureDHCP() {
sleep 2
done

local TAP_NR TAP_PATH MAJOR MINOR
TAP_NR=$(</sys/class/net/"$VM_NET_TAP"/ifindex)
TAP_PATH="/dev/tap${TAP_NR}"

Expand Down
13 changes: 7 additions & 6 deletions src/power.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ _trap(){
_graceful_shutdown() {

set +e
local cnt response

[ ! -f "$QEMU_PID" ] && exit 130
[ -f "$QEMU_COUNT" ] && return
Expand All @@ -32,11 +33,11 @@ _graceful_shutdown() {
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null

# Send shutdown command to guest agent via serial port
RESPONSE=$(curl -sk -m 30 -S http://127.0.0.1:2210/read?command=6 2>&1)
response=$(curl -sk -m 30 -S http://127.0.0.1:2210/read?command=6 2>&1)

if [[ ! "$RESPONSE" =~ "\"success\"" ]]; then
if [[ ! "$response" =~ "\"success\"" ]]; then

echo && error "Failed to send shutdown command ( ${RESPONSE} )."
echo && error "Failed to send shutdown command ( $response )."

kill -15 "$(cat "$QEMU_PID")"
pkill -f qemu-system-x86_64 || true
Expand All @@ -46,15 +47,15 @@ _graceful_shutdown() {
while [ "$(cat $QEMU_COUNT)" -lt "$QEMU_TIMEOUT" ]; do

# Increase the counter
echo $(($(cat $QEMU_COUNT)+1)) > $QEMU_COUNT
echo $(($(cat $QEMU_COUNT)+1)) > "$QEMU_COUNT"

# Try to connect to qemu
if echo 'info version'| nc -q 1 -w 1 localhost "$QEMU_PORT" >/dev/null 2>&1 ; then

sleep 1

CNT="$(cat $QEMU_COUNT)/$QEMU_TIMEOUT"
[[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($CNT)"
cnt="$(cat $QEMU_COUNT)/$QEMU_TIMEOUT"
[[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($cnt)"

fi

Expand Down
4 changes: 1 addition & 3 deletions src/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ rm -rf "$STORAGE/tmp"

getCountry () {

local rc
local json
local result
local url=$1
local query=$2
local rc json result

{ json=$(curl -m 5 -H "Accept: application/json" -sfk "$url"); rc=$?; } || :
(( rc != 0 )) && return 0
Expand Down