summaryrefslogtreecommitdiff
path: root/cmd/updater/update.sh
blob: 136ce67d511196760e2387fa7f1bb99f06a330de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
#!/bin/bash
# shellcheck disable=2009,2093,2164

FILENAME=$(basename -- "$0")
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
UPDATETYPE="update"
INSTALLOPT="-u"
RESUME_INSTALL=0
BINDIR=""
CHANNEL=""
DATADIRS=()
NOSTART=""
BINDIRSPEC="-p ${SCRIPTPATH}"
DATADIRSPEC=""
TESTROLLBACK=""
UNKNOWNARGS=()
HOSTEDFLAG=""
HOSTEDSPEC=""
BUCKET=""
GENESIS_NETWORK_DIR=""
GENESIS_NETWORK_DIR_SPEC=""
SKIP_UPDATE=0
TOOLS_OUTPUT_DIR=""
DRYRUN=false
IS_ROOT=false
if [ $EUID -eq 0 ]; then
    IS_ROOT=true
fi


set -o pipefail

# If someone set the environment variable asking us to cleanup
# when we're done, install a trap to do so
# We use an environment variable instead of an arg because
# older scripts won't recognize it and will fail (an issue with tests)
if [ "${CLEANUP_UPDATE_TEMP_DIR}" != "" ]; then
    trap "rm -rf ${CLEANUP_UPDATE_TEMP_DIR}" 0
fi

while [ "$1" != "" ]; do
    case "$1" in
        -i)
            UPDATETYPE="install"
            INSTALLOPT="-i"
            ;;
        -u)
            UPDATETYPE="update"
            INSTALLOPT="-u"
            ;;
        -m)
            UPDATETYPE="migrate"
            INSTALLOPT="-m"
            ;;
        -r)
            RESUME_INSTALL=1
            ;;
        -c)
            shift
            CHANNEL="$1"
            ;;
        -d)
            shift
            THISDIR=$1
            mkdir -p "${THISDIR}" >/dev/null
            pushd "${THISDIR}" >/dev/null
            THISDIR=$(pwd -P)
            popd >/dev/null
            DATADIRS+=(${THISDIR})
            DATADIRSPEC+="-d ${THISDIR} "
            ;;
        -p)
            shift
            BINDIR="$1"
            BINDIRSPEC="-p $1"
            ;;
        -n)
            NOSTART="-n"
            ;;
        -testrollback)
            TESTROLLBACK=1
            ;;
        -hosted)
            HOSTEDFLAG="-H"
            HOSTEDSPEC="-hosted"
            ;;
        -g)
            shift
            GENESIS_NETWORK_DIR=$1
            GENESIS_NETWORK_DIR_SPEC="-g $1"
            ;;
        -b)
            shift
            BUCKET="-b $1"
            ;;
        -s)
            SKIP_UPDATE=1
            ;;
        -gettools)
            shift
            TOOLS_OUTPUT_DIR=$1
            ;;
        -z)
            DRYRUN=true
            ;;
        *)
            echo "Unknown option" "$1"
            UNKNOWNARGS+=("$1")
            ;;
    esac
    shift
done

# If this is an update, we'll validate that before doing anything else.
# If this is an install, we'll create it.
if [ ${RESUME_INSTALL} -eq 0 ] && ! $DRYRUN; then
    if [ "${BINDIR}" = "" ]; then
        BINDIR="${SCRIPTPATH}"
    fi
fi

# If -d not specified, don't default any more
if [ "${#DATADIRS[@]}" -eq 0 ]; then
    echo "You must specify at least one data directory with \`-d\`"
    exit 1
fi

CURRENTVER=0

ROLLBACK=0
ROLLBACKBIN=0
ROLLBACKDATA=()
NEW_LEDGER=0
RESTART_NODE=0

function check_install_valid() {
    # Check for key files that indicate a valid install that can be updated
    if [ ! -f "${BINDIR}/algod" ]; then
        echo "Missing ${BINDIR}/algod"
        return 1
    fi
    return 0
}

function validate_channel_specified() {
    if [ "${CHANNEL}" = "" ]; then
        CHANNEL="$((${BINDIR}/algod -c) | head -n 1)"
        if [ "${CHANNEL}" = "" ]; then
            echo "Unable to determine release channel - please run again with -c <channel>"
            return 1
        fi
    fi
}

function determine_current_version() {
    CURRENTVER="$(( ${BINDIR}/algod -v 2>/dev/null || echo 0 ) | head -n 1)"
    echo Current Version = ${CURRENTVER}
}

function get_updater_url() {
    local UNAME
    local OS
    local ARCH
    UNAME=$(uname)
    if [[ "${UNAME}" = "Darwin" ]]; then
        OS="darwin"
        UNAME=$(uname -m)
        if [[ "${UNAME}" = "x86_64" ]]; then
            ARCH="amd64"
        else
            echo "This platform ${UNAME} is not supported by updater."
            exit 1
        fi
    elif [[ "${UNAME}" = "Linux" ]]; then
        OS="linux"
        UNAME=$(uname -m)
        if [[ "${UNAME}" = "x86_64" ]]; then
            ARCH="amd64"
        elif [[ "${UNAME}" = "armv6l" ]]; then
            ARCH="arm"
        elif [[ "${UNAME}" = "armv7l" ]]; then
            ARCH="arm"
        elif [[ "${UNAME}" = "aarch64" ]]; then
            ARCH="arm64"
        else
            echo "This platform ${UNAME} is not supported by updater."
            exit 1
        fi
    else
        echo "This operation system ${UNAME} is not supported by updater."
        exit 1
    fi
    UPDATER_FILENAME="install_master_${OS}-${ARCH}.tar.gz"
    UPDATER_URL="https://github.com/algorand/go-algorand-doc/raw/master/downloads/installers/${OS}_${ARCH}/${UPDATER_FILENAME}"
}

# check to see if the binary updater exists. if not, it will automatically the correct updater binary for the current platform
function check_for_updater() {
    # check if the updater binary exist.
    if [ -f "${SCRIPTPATH}/updater" ]; then
        return 0
    fi
    get_updater_url

    # check the curl is available.
    CURL_VER=$(curl -V 2>/dev/null || true)
    if [ "${CURL_VER}" = "" ]; then
        # no curl is installed.
        echo "updater binary is missing and cannot be downloaded since curl is missing."
        if [[ "$(uname)" = "Linux" ]]; then
            echo "To install curl, run the following command:"
            echo "apt-get update; apt-get install -y curl"
        fi
        exit 1
    fi

    CURL_OUT=$(curl -LJO --silent ${UPDATER_URL})
    if [ "$?" != "0" ]; then
        echo "failed to download updater binary from ${UPDATER_URL} using curl."
        echo "${CURL_OUT}"
        exit 1
    fi

    if [ ! -f "${SCRIPTPATH}/${UPDATER_FILENAME}" ]; then
        echo "downloaded file ${SCRIPTPATH}/${UPDATER_FILENAME} is missing."
        exit
    fi

    tar -zxvf "${SCRIPTPATH}/${UPDATER_FILENAME}" updater
    if [ "$?" != "0" ]; then
        echo "failed to extract updater binary from ${SCRIPTPATH}/${UPDATER_FILENAME}"
        exit 1
    fi

    rm -f "${SCRIPTPATH}/${UPDATER_FILENAME}"
    echo "updater binary was downloaded"
}

function check_for_update() {
    determine_current_version
    check_for_updater
    LATEST="$(${SCRIPTPATH}/updater ver check -c ${CHANNEL} ${BUCKET} | sed -n '2 p')"
    if [ $? -ne 0 ]; then
        echo "No remote updates found"
        return 1
    fi

    echo Latest Version = ${LATEST}

    if [ ${CURRENTVER} -ge ${LATEST} ]; then
        if [ "${UPDATETYPE}" = "install" ]; then
            echo No new version found - forcing install anyway
        else
            echo No new version found
            return 1
        fi
    fi

    echo New version found
    return 0
}

function download_tools_update() {
    local TOOLS_SPECIFIC_VERSION=$1
    echo "downloading tools update ${TOOLS_SPECIFIC_VERSION}"
    TOOLS_TEMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t "tmp")
    export TOOLS_CLEANUP_UPDATE_TEMP_DIR=${TOOLS_TEMPDIR}
    trap "rm -rf ${TOOLS_CLEANUP_UPDATE_TEMP_DIR}" 0

    TOOLS_TARFILE=${TOOLS_TEMPDIR}/${LATEST}.tar.gz

    if ( ! "${SCRIPTPATH}"/updater gettools -c "${CHANNEL}" -o "${TOOLS_TARFILE}" "${BUCKET}" "${TOOLS_SPECIFIC_VERSION}" ) ; then
        echo "Error downloading tools tarfile"
        exit 1
    fi
    echo "Tools tarfile downloaded to ${TOOLS_TARFILE}"

    mkdir -p "${TOOLS_OUTPUT_DIR}"
    if ( ! tar -xf "${TOOLS_TARFILE}" -C "${TOOLS_OUTPUT_DIR}" ) ; then
        echo "Error extracting the tools update file ${TOOLS_TARFILE}"
        exit 1
    fi
    echo "Tools extracted to ${TOOLS_OUTPUT_DIR}"
}

TEMPDIR=""
TARFILE=""
UPDATESRCDIR=""

function download_update() {
    SPECIFIC_VERSION=$1

    if [ -n "${TOOLS_OUTPUT_DIR}" ]; then
        download_tools_update "${SPECIFIC_VERSION}"
    fi

    TEMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t "tmp")
    export CLEANUP_UPDATE_TEMP_DIR=${TEMPDIR}
    trap "rm -rf ${CLEANUP_UPDATE_TEMP_DIR}" 0

    TARFILE=${TEMPDIR}/${LATEST}.tar.gz
    UPDATESRCDIR=${TEMPDIR}/a
    mkdir ${UPDATESRCDIR}

    ${SCRIPTPATH}/updater ver get -c ${CHANNEL} -o ${TARFILE} ${BUCKET} ${SPECIFIC_VERSION}

    if [ $? -ne 0 ]; then
        echo Error downloading update file
        exit 1
    fi
    echo Update Downloaded to ${TARFILE}
}

function check_and_download_update() {
    if ! check_for_update; then
        return 1
    fi

    download_update
}

function download_update_for_current_version() {
    determine_current_version
    echo "Downloading update package for current version ${CURRENTVER}..."
    download_update "-v ${CURRENTVER}"
}

function expand_update() {
    echo Expanding update...
    if ! tar -zxof "${TARFILE}" -C "${UPDATESRCDIR}"; then
        return 1
    fi
    validate_update
}

function validate_update() {
    echo Validating update...
    # We should consider including a version.info file
    # that we can compare against the expected version
    return 0
}

function check_service() {
    local service_type="$1"
    local dd="$2"
    local path

    if [ "$service_type" = "user" ]; then
        path=$(awk -F= '{ print $2 }' <(systemctl --user show -p FragmentPath "algorand@$(systemd-escape "$dd")"))
    else
        path=$(awk -F= '{ print $2 }' <(systemctl show -p FragmentPath "algorand@$(systemd-escape "$dd")"))
    fi

    if [ "$path" != "" ]; then
        return 0
    fi

    return 1
}

function run_systemd_action() {
    if [ "$(uname)" = "Darwin" ]; then
        return 1
    fi

    local action=$1
    local data_dir=$2
    local process_owner

    # If the service is system-level, check if it's root or sudo
    if check_service system "$data_dir"; then
        process_owner=$(awk '{ print $1 }' <(ps aux | grep "[a]lgod -d ${data_dir}"))
        if $IS_ROOT; then
            if systemctl "$action" "algorand@$(systemd-escape "$data_dir")"; then
                echo "systemd system service: $action"
                return 0
            fi
        elif grep sudo <(groups "$process_owner") &> /dev/null; then
            if sudo -n systemctl "$action" "algorand@$(systemd-escape "$data_dir")"; then
                echo "sudo -n systemd system service: $action"
                return 0
            fi
        fi

    # If the service is user-level then run systemctl --user
    elif check_service user "$data_dir"; then
        if systemctl --user "$action" "algorand@$(systemd-escape "${data_dir}")"; then
            echo "systemd user service: $action"
            return 0
        fi
    fi

    return 1
}

function backup_binaries() {
    echo Backing up current binary files...
    mkdir -p "${BINDIR}/backup"
    BACKUPFILES="algod kmd carpenter doberman goal update.sh updater diagcfg"
    # add node_exporter to the files list we're going to backup, but only we if had it previously deployed.
    [ -f "${BINDIR}/node_exporter" ] && BACKUPFILES="${BACKUPFILES} node_exporter"
    tar -zcf "${BINDIR}/backup/bin-v${CURRENTVER}.tar.gz" -C "${BINDIR}" ${BACKUPFILES} >/dev/null 2>&1
}

function backup_data() {
    CURDATADIR=$1
    BACKUPDIR="${CURDATADIR}/backup"

    echo "Backing up current data files from ${CURDATADIR}..."
    mkdir -p "${BACKUPDIR}"
    BACKUPFILES="genesis.json wallet-genesis.id"
    tar --no-recursion --exclude='*.log' --exclude='*.log.archive' --exclude='*.tar.gz' -zcf "${BACKUPDIR}/data-v${CURRENTVER}.tar.gz" -C "${CURDATADIR}" ${BACKUPFILES} >/dev/null 2>&1
}

function backup_current_version() {
    backup_binaries
    for DD in ${DATADIRS[@]}; do
        backup_data "${DD}"
    done
}

function rollback_binaries() {
    echo "Rolling back binary files..."
    tar -zxof ${BINDIR}/backup/bin-v${CURRENTVER}.tar.gz -C ${BINDIR}
}

function rollback_data() {
    CURDATADIR=$1
    BACKUPDIR="${CURDATADIR}/backup"

    echo "Rolling back data files in ${CURDATADIR}..."
    rm ${CURDATADIR}/wallet-genesis.id
    tar -zxof ${BACKUPDIR}/data-v${CURRENTVER}.tar.gz -C ${CURDATADIR}
}

function install_new_binaries() {
    if [ ! -d ${UPDATESRCDIR}/bin ]; then
        return 0
    else
        echo Installing new binary files...
        ROLLBACKBIN=1
        rm -rf ${BINDIR}/new
        mkdir ${BINDIR}/new
        cp ${UPDATESRCDIR}/bin/* ${BINDIR}/new
        mv ${BINDIR}/new/* ${BINDIR}
        rm -rf ${BINDIR}/new
    fi
}

function reset_wallets_for_new_ledger() {
    CURDATADIR=$1

    echo "New Ledger - restoring genesis accounts in ${CURDATADIR}"
    pushd ${CURDATADIR} >/dev/null
    mkdir -p "${NEW_VER}"
    for file in *.partkey *.rootkey; do
        if [ -e "${file}" ]; then
            cp "${file}" "${NEW_VER}/${file}"
            echo 'Installed genesis account file: ' "${file}"
        fi
    done
    popd >/dev/null
}

function import_rootkeys() {
    CURDATADIR=$1

    echo "New Ledger - importing rootkeys for genesis accounts"
    ${BINDIR}/goal account importrootkey -u -d ${CURDATADIR}
}

function install_new_data() {
    if [ ! -d ${UPDATESRCDIR}/data ]; then
        return 0
    else
        CURDATADIR=$1
        echo "Installing new data files into ${CURDATADIR}..."
        ROLLBACKDATA+=(${CURDATADIR})
        cp "${UPDATESRCDIR}/data/"* "${CURDATADIR}"
    fi
}

function copy_genesis_files() {
    echo "Copying genesis files locally"
    cp -rf ${UPDATESRCDIR}/genesis/ ${BINDIR}/genesisfiles/
}

function check_for_new_ledger() {
    CURDATADIR=$1
    echo "Checking for new ledger in ${CURDATADIR}"
    EXISTING_VER=$(${UPDATESRCDIR}/bin/algod -d ${CURDATADIR} -g ${CURDATADIR}/genesis.json -G)

    if [ -z $EXISTING_VER ]; then
        if [ -z ${GENESIS_NETWORK_DIR} ]; then
            echo "Updating genesis files for default network"
        else
            echo "Installing genesis files for network ${GENESIS_NETWORK_DIR}"
        fi
    else
        GENESIS_SPLIT=(${EXISTING_VER//-/ })
        GENESIS_NETWORK_DIR=${GENESIS_SPLIT[0]}
        echo "Updating genesis files for network ${GENESIS_NETWORK_DIR}"

        # If that genesis dir doesn't exist, use the default file - this is likely a custom network build
        if [ ! -d ${UPDATESRCDIR}/genesis/${GENESIS_NETWORK_DIR} ]; then
            GENESIS_NETWORK_DIR=""
        fi
    fi

    NEW_VER=$(${UPDATESRCDIR}/bin/algod -d ${CURDATADIR} -g ${UPDATESRCDIR}/genesis/${GENESIS_NETWORK_DIR}/genesis.json -G)
    if [ $? -ne 0 ]; then
        echo "Cannot determine new genesis ID. Not updating. This may be a problem!"
        return 1
    fi

    # Copy new genesis.json even if version didn't change; we might have
    # changed the file itself in a compatible way.
    cp ${UPDATESRCDIR}/genesis/${GENESIS_NETWORK_DIR}/genesis.json ${CURDATADIR}

    echo ${NEW_VER} > ${CURDATADIR}/wallet-genesis.id
    if [ "${NEW_VER}" != "${EXISTING_VER}" ]; then
        echo "New genesis ID, resetting wallets"
        NEW_LEDGER=1
        reset_wallets_for_new_ledger ${CURDATADIR}

        import_rootkeys ${CURDATADIR}
    fi
}

# Delete all logs.
function clean_legacy_logs() {
    CURDATADIR=$1

    echo "Deleting existing log files in ${CURDATADIR}"
    rm -f ${CURDATADIR}/node-*.log
    rm -f ${CURDATADIR}/node-*.log.archive
    return 0
}

function startup_node() {
    if [ "${NOSTART}" != "" ]; then
        echo Auto-start node disabled - not starting
        return
    fi

    CURDATADIR=$1
    echo Restarting node in ${CURDATADIR}...

    check_install_valid
    if [ $? -ne 0 ]; then
        fail_and_exit "Installation does not appear to be valid"
    fi

    if ! run_systemd_action restart "${CURDATADIR}"; then
        echo "No systemd services, restarting node with goal."
        ${BINDIR}/goal node restart -d "${CURDATADIR}" ${HOSTEDFLAG}
    fi
}

function startup_nodes() {
    for DD in ${DATADIRS[@]}; do
        startup_node ${DD}
    done
}

function rollback() {
    echo Rolling back from failed update...
    if [ ${ROLLBACKBIN} -ne 0 ]; then
        rollback_binaries
    fi
    for ROLLBACKDIR in ${ROLLBACKDATA[@]}; do
        rollback_data ${ROLLBACKDIR}
    done
}

function fail_and_exit() {
    echo "*** UPDATE FAILED: $1 ***"
    if [ ${ROLLBACK} -ne 0 ]; then
        ROLLBACK=0
        rollback
        check_install_valid
        if [ ${RESTART_NODE} -ne 0 ]; then
            startup_nodes
        fi
        exit 0
    fi
    exit 1
}

function apply_fixups() {
    echo "Applying migration fixups..."

    # Delete obsolete algorand binary - renamed to 'goal'
    rm "${BINDIR}/algorand" >/dev/null 2>&1

    for DD in ${DATADIRS[@]}; do
        clean_legacy_logs "${DD}"

        # Purge obsolete cadaver files (now agreement.cdv[.archive])
        rm -f "${DD}"/service*.cadaver
    done
}

#--------------------------------------------
# Main Update Driver

# Need to verify the bindir was specified (with -p)
# and that it's a valid directory.
# Unless it's an install
if [ ! -d "${BINDIR}" ]; then
    if [ "${UPDATETYPE}" = "install" ]; then
        mkdir -p "${BINDIR}"
    else
        fail_and_exit "Missing or invalid binaries path specified '${BINDIR}'"
    fi
fi

if [ "${UPDATETYPE}" != "install" ]; then
    if ! check_install_valid; then
        echo "Unable to perform an update - installation does not appear valid"
        exit 1
    fi
fi

# If we're initiating an update/install, check for an update and if we have a new one,
# expand it and invoke the new update.sh script.
if [ ${RESUME_INSTALL} -eq 0 ] && ! $DRYRUN; then
    validate_channel_specified

    if [ "${UPDATETYPE}" = "migrate" ]; then
        download_update_for_current_version
    else
        check_and_download_update
    fi

    if [ $? -ne 0 ]; then
        # No update - stop here
        exit $?
    fi

    if ! expand_update; then
        fail_and_exit "Error expanding update"
    fi

    # Spawn the new update script and exit - this allows us to push update.sh changes that take effect immediately
    # Note that the SCRIPTPATH we're passing in should be our binaries directory, which is what we expect to be
    # passed as the last argument (if any)
    echo "Starting the new update script to complete the installation..."
    exec "${UPDATESRCDIR}/bin/${FILENAME}" ${INSTALLOPT} -r -c ${CHANNEL} ${DATADIRSPEC} ${NOSTART} ${BINDIRSPEC} ${HOSTEDSPEC} ${GENESIS_NETWORK_DIR_SPEC} ${UNKNOWNARGS[@]}

    # If we're still here, exec failed.
    fail_and_exit "Error executing the new update script - unable to continue"
else
    # We're running the script from our expanded update, which is located in the last script's ${TEMPDIR}/a/bin
    # We need to define our TEMPDIR and UPDATESRCDIR to match those values; we do so by making them relative
    # to where our resuming script lives.
    TEMPDIR=${SCRIPTPATH}/../..
    UPDATESRCDIR=${SCRIPTPATH}/..
    echo "... Resuming installation from the latest update script"

    determine_current_version
fi

# Any fail_and_exit beyond this point will run a restart
RESTART_NODE=1

if ! $DRYRUN; then
    if [ ${SKIP_UPDATE} -eq 0 ]; then
        backup_current_version
    fi

    # We don't care about return code - doesn't matter if we failed to archive

    ROLLBACK=1

    if ! install_new_binaries; then
        fail_and_exit "Error installing new files"
    fi

    for DD in ${DATADIRS[@]}; do
        if ! install_new_data "${DD}"; then
            fail_and_exit "Error installing data files into ${DD}"
        fi
    done

    copy_genesis_files

    for DD in ${DATADIRS[@]}; do
        if ! check_for_new_ledger "${DD}"; then
            fail_and_exit "Error updating ledger in ${DD}"
        fi
    done

    if [ "${TESTROLLBACK}" != "" ]; then
        fail_and_exit "Simulating update failure - rolling back"
    fi

    apply_fixups
fi

if [ "${NOSTART}" != "" ]; then
    echo "Install complete - restart node manually"
else
    startup_nodes
fi

exit 0