8000 update.sh replaces itself while it runs: a syntax error after the update · Issue #67 · alexbeeken/skrongle-mini · GitHub
[go: up one dir, main page]

Skip to content

update.sh replaces itself while it runs: a syntax error after the update #67

Closed

Description

@alexbeeken

Updating 0.1.2 to 0.2.0 with sudo /opt/skrongle/update.sh worked (the service came up on 0.2.0) and then printed:

/opt/skrongle/update.sh: 93: Syntax error: ")" unexpected

Cause: cp -R "$TMP/new/." "$DIR/" copies the new release over /opt/skrongle, which includes update.sh itself, while sh is still running it. sh reads a script as it goes, so once its buffer ran out it read the rest from the new file at the old byte offset. The 0.1.2 and 0.2.0 scripts differ in length, so that was the middle of a case arm. A syntax error stops the shell, so nothing from the garbage ran, but it could have been a complete command.

Wrapping the body in a function is not enough: after the function returns the shell reads what follows the call from the new file too (tried under dash). The fix is to run from a copy: on its first lines the script copies itself to a temp file and re-executes from there, with the installed path kept in SKRONGLE_UPDATE_SELF for messages and for finding /opt/skrongle. scripts/release-qa/package-smoke.sh checks the shipped script does this.

The running script is always the installed, older one, so the fix protects updates from the first release that ships it onward. Updating 0.2.0 to the next release will show the message once more; it is harmless there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0