Skip to content

cmd: rclone selfupdate - #5080

Merged
ivandeex merged 6 commits into
rclone:masterfrom
ivandeex:pr-selfupdate
Mar 11, 2021
Merged

ivandeex merged 6 commits into
rclone:masterfrom
ivandeex:pr-selfupdate

Conversation

@ivandeex

@ivandeex ivandeex commented Mar 1, 2021 •

Copy link
Copy Markdown
Member

What is the purpose of this change?

Implements rclone self-update command (ticket #548)

Flags and features:

  • verifies sha256 hash of release archive
  • verifies access to replaced file and directory, optionally asks user to run with elevated privileges (in Scotland - elavated)
  • mimics permission bits of original file, if any
  • --output - downloads new executable to a custom location
  • --beta - self-explanatory
  • --check - just an alias of rclone version --check

Yet unimplemented, left for future patches:

  • --stable (--backports)
  • --version

UPDATE 2021-03-08:
Will be implemented:

  • --stable (mutually exclusive with --beta)
  • --version VER (micro-release autocompletion if stable)
  • --package deb (linux only)
  • --package rpm (linux only)
  • PGP signature validation (pending public key)

Was the change discussed in an issue or in the forum before?

Yes:

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

@ivandeex ivandeex self-assigned this Mar 1, 2021
@ivandeex
ivandeex marked this pull request as draft March 1, 2021 10:43
@ivandeex
ivandeex force-pushed the pr-selfupdate branch 4 times, most recently from 5cb3947 to abefc3a Compare March 1, 2021 11:58
@ivandeex ivandeex linked an issue Mar 1, 2021 that may be closed by this pull request
@ivandeex
ivandeex force-pushed the pr-selfupdate branch 5 times, most recently from d4f9e8d to f386616 Compare March 1, 2021 13:43
@darthShadow

Copy link
Copy Markdown
Member

Should we also add a note in the Docs that the manpages will no longer be accurate after the binary is updated using this?

@ivandeex

ivandeex commented Mar 1, 2021

Copy link
Copy Markdown
Member Author

Should we also add a note in the Docs that the manpages will no longer be accurate after the binary is updated using this?

I will add this warning in the success message

@ivandeex

ivandeex commented Mar 1, 2021 •

Copy link
Copy Markdown
Member Author

As expected Windows has a quirk. It will never allow to rewrite a currently running executable, even if user has full write permissions. On Unix the command will detect incomplete write permissions in advance, but in this case the command will exit with code 1, keep the downloaded file (it will by default have .new appended to the name) and print the following message :

Failed to replace old file, new version 1.54.xxx saved as C:\bin\rclone.exe.new

The workaround for scheduled update tasks is to use the --output flag:

C:\bin\rclone.exe self-update --output C:\bin\rclone_new.exe
del C:\bin\rclone.exe
rename C:\bin\rclone_new.exe C:\bin\rclone.exe

@darthShadow

darthShadow commented Mar 1, 2021 •

Copy link
Copy Markdown
Member

This seems like a reasonable alternative way of accomplishing it: https://stackoverflow.com/a/55247459/3476387

@ivandeex ivandeex added this to the v1.55 milestone Mar 2, 2021
@albertony

albertony commented Mar 2, 2021 •

Copy link
Copy Markdown
Contributor

The rename trick works great, and it is also possible to tell Windows to automatically delete it on next startup, simply by adding the path into registry value HKLM\System\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations. Not that it is very important in this case, but just an idea..

Edit: Seems like Chocolatey (package manager) uses this method. Could not find it clearly documented anywhere, but basing it on the discussions in this issue: chocolatey/choco#1768

@ivandeex

ivandeex commented Mar 3, 2021 •

Copy link
Copy Markdown
Member Author

I would like to have the first released version of the command have only the required features, release it as fast as possible and leave optional features for later enhancements.
I think we can postpone registry tricks or leave it for chocolatey installer. If someone installed a choco package, I'd recommend to update it using choco too, cinst -y rclone without mixing package with self-update strategy.
@albertony

@ivandeex

This comment has been minimized.

@albertony

Copy link
Copy Markdown
Contributor

I think we can postpone registry tricks

Sure. BTW: It's exposed as an Windows API function, MoveFileEx with flag MOVEFILE_DELAY_UNTIL_REBOOT, so no direct registry access necessary - if it is easy to call the api from golang (or there is a library wrapping that function, could not find any with a quick search).

I would like to have the first released version of the command have only the required features, release it as fast as possible and leave optional features for later enhancements.

I agree. Have not really decided myself what I would want (delete rclone.exe.old on boot or not), but just wanted to note it in case it could turn up useful..

Great work btw!

@ivandeex

This comment has been minimized.

@ivandeex

ivandeex commented Mar 3, 2021 •

Copy link
Copy Markdown
Member Author

Based on the discussion in https://forum.rclone.org/t/rclone-cmount-on-linux/22602 the official build of rclone for Linux does not support cmount and runtime detection of such features will need tweaks in the build process, so it's out of scope for this PR. I will address it in a later patch. Its requirements are captured in #5091

@ivandeex ivandeex changed the title rclone self-update cmd: rclone selfupdate Mar 3, 2021
@ivandeex

ivandeex commented Mar 3, 2021 •

Copy link
Copy Markdown
Member Author

Implementation details:

All unit tests pass for me

@ncw
Please review

@albertony @darthShadow
Please take a look and give it a try

@ivandeex

ivandeex commented Mar 7, 2021 •

Copy link
Copy Markdown
Member Author

Summary of new changes after 1st review:

  • using fshttp.Client now [ncw]
  • replace GOOS darwin with osx in archive names [ncw]
  • use fstest/testy.SkipUnreliable to run in integration suite only [ncw]
  • removed unneeded os.Remove(savedFile) [albertony]
  • prepend v to incomplete semantic --version [darthShadow]
  • extract last micro release from index.html to complete version number [darthShadow]
  • examples from cmd/self-update: add --stable flag #5076 (comment) work correctly now [darthShadow, albertony]
  • random suffix for .new files [ncw]
  • .old file by default is rclone.old.exe [ivandeex]
  • random old suffix rclone.xxxx.old.exe if a race was detected [ncw]
  • install .deb/.rpm by flag --package deb|rpm (default: zip) [ncw]
  • missing "the" in the docs [ncw]
  • a draft of PGP check [ncw]

@ncw
Could you provide a valid (#5080 (comment)) public key (#5080 (comment)) ?

@ivandeex
ivandeex requested a review from ncw March 7, 2021 22:31
@ivandeex
ivandeex removed the request for review from ncw March 8, 2021 08:22
@ivandeex

ivandeex commented Mar 8, 2021 •

Copy link
Copy Markdown
Member Author

TODO will create an RFC issue for the MoveFileEx aka MOVEFILE_DELAY_UNTIL_REBOOT feature requested in #5080 (comment) when we merge this pull.

UPD: Done

@ncw

ncw commented Mar 9, 2021

Copy link
Copy Markdown
Member

Summary of new changes after 1st review:

[snip]

Great changes :-) I'll run through a code review now.

Could you provide a valid (#5080 (comment)) public key (#5080 (comment)) ?

I think this should do it

$ gpg --armor --export-options export-minimal --export [email protected]

Which produced

-----BEGIN PGP PUBLIC KEY BLOCK-----

mQGiBDuy3V0RBADVQOAF5aFiCxD3t2h6iAF2WMiaMlgZ6kX2i/u7addNkzX71VU9
7NpI0SnsP5YWt+gEedST6OmFbtLfZWCR4KWn5XnNdjCMNhxaH6WccVqNm4ALPIqT
59uVjkgf8RISmmoNJ1d+2wMWjQTUfwOEmoIgH6n+2MYNUKuctBrwAACflwCg1I1Q
O/prv/5hczdpQCs+fL87DxsD/Rt7pIXvsIOZyQWbIhSvNpGalJuMkW5Jx92UjsE9
1Ipo3Xr6SGRPgW9+NxAZAsiZfCX/19knAyNrN9blwL0rcPDnkhdGwK69kfjF+wq+
QbogRGodbKhqY4v+cMNkKiemBuTQiWPkpKjifwNsD1fNjNKfDP3pJ64Yz7a4fuzV
X1YwBACpKVuEen34lmcX6ziY4jq8rKibKBs4JjQCRO24kYoHDULVe+RS9krQWY5b
e0foDhru4dsKccefK099G+WEzKVCKxupstWkTT/iJwajR8mIqd4AhD0wO9W3MCfV
Ov8ykMDZ7qBWk1DHc87Ep3W1o8t8wq74ifV+HjhhWg8QAylXg7QlTmljayBDcmFp
Zy1Xb29kIDxuaWNrQGNyYWlnLXdvb2QuY29tPohxBBMRCAAxBQsHCgMEAxUDAgMW
AgECF4AWIQT79zfs6firGGBL0qyTk14C/ztU+gUCXjg2UgIZAQAKCRCTk14C/ztU
+lmmAJ4jH5FyULzStjisuTvHLTVz6G44eQCfaR5QGZFPseenE5ic2WeQcBcmtoG5
Ag0EO7LdgRAIAI6QdFBg3/xa1gFKPYy1ihV9eSdGqwWZGJvokWsfCvHy5180tj/v
UNOLAJrdqglMSvevNTXe8bT65D6423AAsLhch9wq/aNqrHolTYABzxRigjcS1//T
yln5naGUzlVQXDVfrDk3Md/NrkdOFj7r/YyMF0+iWwpFz2qAjL95i5wfVZ1kWGrT
2AmivE1wD1sWT/Ja3FDI0NRkU0Nbz/a0TKe4ml8iLVtZXpTRbxxCCPdkHXXgSyu1
eZ4NrF/wTJuvwGn12TJ1EF95aVkHxAUw0+KmLGdcyBG+IKuHamrsjWIAXGXV///K
AxPgUthccQ03HMjltFsrdmen5Q034YM3eOsAAwUH/jAKiIAA8LpZmZPnt9GZ4+Ol
Zp22VAfyfDOFl4Ol+cWjkLAgjAFsm5gnOKcRSE/9XPxnQqkhw7+ZygYuUMgTDJ99
/5IM1UQL3ooS+oFrDaE99S8bLeOe17skcdXcA/K83VqD9m93rQRnbtD+75zqKkZn
9WNFyKCXg5P6PFPdNYRtlQKOcwFR9mHRLUmapQSAM8Y2pCgALZ7GViKQca8/TT1T
gZk9fJMZYGez+IlOPxTJxjn80+vywk4/wdIWSiQj+8u5RzT9sjmm77wbMVNGRqYd
W/EemW9Zz9vi0CIvJGgbPMqcuxw8e/5lnuQ6Mi3uDR0P2RNIAhFrdZpVSME8xQaI
RgQYEQIABgUCO7LdgQAKCRCTk14C/ztU+mLBAKC2cdFy7eLaQAvyzcE2VK6HVIjn
JACguA00bxLQuJ4+RCJrLFZP8ZlN2sc=
=TtR5
-----END PGP PUBLIC KEY BLOCK-----

I've attached a zip with the ascii version and the binary version too just in case you want the binary version.

ncw-pgp-keys.zip

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is looking really nice :-)

I put a couple of docs comments inline.

Well done!

Comment thread cmd/selfupdate/help.go Resolved
Comment thread cmd/selfupdate/help.go Resolved
Comment thread cmd/selfupdate/selfupdate.go Resolved
Comment thread cmd/selfupdate/selfupdate.go Resolved
Comment thread cmd/selfupdate/selfupdate.go Resolved
Comment thread cmd/selfupdate/selfupdate.go Resolved
Comment thread cmd/selfupdate/selfupdate.go Resolved
Comment thread cmd/selfupdate/selfupdate.go Resolved
Comment thread cmd/selfupdate/selfupdate.go Resolved
Comment thread cmd/selfupdate/selfupdate.go Resolved
Comment thread cmd/selfupdate/selfupdate.go Resolved
Comment thread cmd/selfupdate/selfupdate_test.go Resolved
@ivandeex

ivandeex commented Mar 11, 2021 •

Copy link
Copy Markdown
Member Author

PGP signature validation - implemented.

The only minor thing left is name for the flag: --package vs --format
and wording in the help message
See #5080 (comment)

Will now proceed on to rclone bisync and sum file support.

@ivandeex ivandeex removed their assignment Mar 11, 2021
@albertony

Copy link
Copy Markdown
Contributor

Testing the --version parameter, I found it useful to include support for --dry-run and --interactive. Then I can run with --version 1.50 --dry-run and verify that I would get v1.50.2, and also get a confirmation of the full path to the rclone binary that would be updated (e.g. when testing on a rclone.exe in current build directory while also having a release version of rclone.exe in PATH). Perhaps most relevant just for testing like I do now, and not so much for regular users of a released version, but just mentioning it in case you really love endless suggestions of nice to have additions.... 😇

I added (locally) the following into InstallUpdate (the executable update part, did not consider the package update):

if operations.SkipDestructive(ctx, targetFile, "update to version " + newVersion) {
    return nil
}

@ncw

ncw commented Mar 11, 2021

Copy link
Copy Markdown
Member

PGP signature validation - implemented.

The only minor thing left is name for the flag: --package vs --format
and wording in the help message
See #5080 (comment)

package is great!

I put some suggested text in the comment above

Will now proceed on to rclone bisync and sum file support.

:-)

@ivandeex

Copy link
Copy Markdown
Member Author

Testing the --version parameter, I found it useful to include support for --dry-run and --interactive. Then I can run with --version 1.50 --dry-run and verify that I would get v1.50.2 and also get a confirmation of the full path to the rclone binary.....

I think --check in fact already means the dry run mode (in context of selfupdate).
The flag combination selfupdate --check (without other flags) is an alias for rclone version --check, it prints the latest stable/beta versions.

Let's add more flag combinations to cover your use cases with an output like below:

$ rclone selfupdate --check [--version VER] [--stable] [--beta] [--output PATH] [--package PKG]
Warning: --package flag is ignored in --check mode
If used without --check, this would install rclone version RESOLVED_VER at RESOLVED_PATH
if operations.SkipDestructive(ctx, targetFile, "update to version " + newVersion) {
    return nil
}

I think that SkipDestructive as well as interactive mode is relevant for operations over data while self-update is a maintenance command.
It's a bit of overkill here.

@ivandeex

Copy link
Copy Markdown
Member Author

All requests addressed.
Unit tests pass.
LGTM.
Merging.

@ivandeex
ivandeex merged commit 6fa7434 into rclone:master Mar 11, 2021
@ivandeex
ivandeex deleted the pr-selfupdate branch March 11, 2021 19:39
@ivandeex ivandeex self-assigned this Oct 28, 2021
lafkpages pushed a commit to lafkpages/rclone that referenced this pull request Jul 20, 2026
Implements self-update command
Fixes rclone#548
Fixes rclone#5076
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmd/self-update: add --stable flag rclone self-update command

4 participants