mirror of
https://github.com/AuxXxilium/arv-v-dsm.git
synced 2024-11-23 23:10:58 +07:00
fix: Local variables (#447)
* fix: Local variables * fix: Keep location
This commit is contained in:
parent
ba7fd2fe4a
commit
03d2665725
@ -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
|
||||
|
29
src/disk.sh
29
src/disk.sh
@ -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")"
|
||||
@ -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 .."
|
||||
@ -135,7 +129,6 @@ resizeDisk() {
|
||||
}
|
||||
|
||||
convertDisk() {
|
||||
|
||||
local CONV_FLAGS="-p"
|
||||
local SOURCE_FILE=$1
|
||||
local SOURCE_FMT=$2
|
||||
@ -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)"
|
||||
|
||||
@ -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
|
||||
@ -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")
|
||||
@ -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"
|
||||
@ -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"
|
||||
|
||||
|
@ -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}"
|
||||
|
||||
|
13
src/power.sh
13
src/power.sh
@ -21,6 +21,7 @@ _trap(){
|
||||
_graceful_shutdown() {
|
||||
|
||||
set +e
|
||||
local cnt response
|
||||
|
||||
[ ! -f "$QEMU_PID" ] && exit 130
|
||||
[ -f "$QEMU_COUNT" ] && return
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user