• Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    C
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cross-platform C library that enables your application to auto-update itself in place.

Libautoupdate

Cross-platform C library that enables your application to auto-update itself in place.

Build Status Build status

Terminal simulation of a simple auto-update

API

There is only one public API, i.e. autoupdate().

int autoupdate(argc, argv, host, port, path, current)

It accepts the following arguments:

  • the 1st and 2nd arguments are the same as those passed to main()
  • host is the host name of the update server to communicate with
  • port is the port of the server, which is a string on Windows and a 16-bit integer on macOS / Linux
  • path is the paramater passed to the HTTP/1.0 HEAD request of the Round 1
  • current is the current version string to be compared with what is returned from the server
    • a new version is considered detected if this string is not a substring of the server's reply

It never returns if a new version was detected and auto-update was successfully performed. Otherwise, it returns one of the following integers to indicate the situation:

Return Value Indication
0 Latest version confirmed. No need to update
1 Auto-update shall not proceed due to environment variable CI being set
2 Auto-update process failed prematurely and detailed errors are printed to stderr
3 Failed to restart after replacing itself with the new version
4 Auto-update shall not proceed due to being already checked in the last 24 hours

Communication

Round 1

Libautoupdate first makes a HTTP/1.0 HEAD request to the server, in order to peek the latest version string.

Libautoupdate -- HTTP/1.0 HEAD request --> Server

The server is expected to repond with HTTP 302 Found and provide a Location header.

It then compares the content of Location header with the current version string. It proceeds to Round 2 if the current version string is NOT a sub-string of the Location header.

Round 2

Libautoupdate makes a full HTTP/1.0 GET request to the Location header of the last round.

Libautoupdate -- HTTP/1.0 GET request --> Server

The server is expected to respond with 200 OK transferring the new release itself.

Based on the Content-Type header received, an addtional inflation operation might be performed:

  • Content-Type: application/x-gzip: Gzip Inflation is performed
  • Content-Type: application/zip: Deflate compression is assumed and the first file is inflated and used

Self-replacing

After 2 rounds of communication with the server, libautoupdate will then proceeds with a self-replacing process, i.e. the program replaces itself in-place with the help of the system temporary directory, after which it restarts itself with the new release.

Examples

Just call autoupdate() at the beginning of your main(), before all actual logic of your application. See the following code for examples.

Windows

#include <autoupdate.h>

int wmain(int argc, wchar_t *wargv[])
{
	int autoupdate_result;

	autoupdate_result = autoupdate(
		argc,
		wargv,
		"enclose.io",
		"80",
		"/nodec/nodec-x64.exe"
		"v1.1.0"
	);

	/* 
		actual logic of your application
		...
	*/
}

macOS / Linux

#include <autoupdate.h>

int main(int argc, char *argv[])
{
	int autoupdate_result;

	autoupdate_result = autoupdate(
		argc,
		argv,
		"enclose.io",
		80,
		"/nodec/nodec-darwin-x64"
		"v1.1.0"
	);

	/* 
		actual logic of your application
		...
	*/
}

Hints

  • Set environment variable CI=true will prevent auto-updating
  • Remove the file ~/.libautoupdate will remove the once-per-24-hours check limit

To-do

  • Cater to bad network connection situations
  • Print more information about the new version
  • Use better error messages when the user did not have permissions to move the new version into the destination directory
  • Move the old binary to the system temporary directory, yet not deleting it.
    • The Operating System will delete it when restarted/tmpdir-full
    • Add facility to restore/rollback to the old file once the new version went wrong

Authors

Minqi Pan et al.

License

MIT

See Also

  • Node.js Packer: Packing your Node.js application into a single executable.
  • Ruby Packer: Packing your Ruby application into a single executable.

More Repositories

1

node-packer

Packing your Node.js application into a single executable.
C++
3,067
star
2

ruby-packer

Packing your Ruby application into a single executable.
C
1,559
star
3

libsquash

Portable, user-land SquashFS that can be easily linked and embedded within your application.
C
135
star
4

mathjax-rails

Simple gem to integrate MathJax with Rails and maintains MathJax at a system-wide directory.
Ruby
65
star
5

ssh2http

Delegating git ssh requests to git http backends.
Ruby
34
star
6

disclose

Pack your Node.js project into an executable without recompiling Node.js
C
26
star
7

FormCore

.NET + React + Ant Design infrastructure for inheritable dynamic forms
JavaScript
12
star
8

fast-hessian

High-performance C++ implementation of Hessian 2.0 Serialization Protocol for Node.js.
JavaScript
11
star
9

grape-rails-routes

Add routes printing for Grape with Rails
Ruby
9
star
10

thebooks

่ฏ•้ชŒไธ€ไธ‹steak BDD
Ruby
3
star
11

CNUKejian

Courseware Sharing System
Ruby
3
star
12

spreadtheword

Automatically generate a release-note document based on git commit messages.
Ruby
3
star
13

git2

git commands implemented on libgit2
C
2
star
14

kaokaodianping

่€ƒ่€ƒ็‚น่ฏ„โ€”โ€”ๆŒ‘้€‰ๆœ€้€‚ๅˆไฝ ็š„ๅŸน่ฎญๆœบๆž„
JavaScript
2
star
15

BLOG-OF-P.S.V.R

P.S.V.R's old blog
C
2
star
16

redis-search-amplifier

Amplifies the effectiveness of redis-search via the aid of remote search engines
Ruby
2
star
17

nodejs-experiments

1
star
18

cnudenglu

็™ป้™†CNUๆœ‰็บฟๅฑ€ๅŸŸ็ฝ‘ๅ’Œๆ— ็บฟๅฑ€ๅŸŸ็ฝ‘็š„ๅฟซ้€Ÿ่„šๆœฌ
1
star
19

homeland-pm

adds Personal Message service to Homeland
Ruby
1
star
20

cnucamp

cnucamp.org
Ruby
1
star
21

ruby-toolbox-best-gems

list best gems pulled from ruby-toolbox.com
Ruby
1
star
22

rails3-mongoid-devise-and-goodies

a skeleton rails 3.1 app featuring mongoid and devise and other good gems
1
star
23

duanfault

ๆฎต้”™่ฏฏ
1
star
24

tmp_csharp

tmp_csharp
1
star
25

edu_sphere

digged up the first rails app that I made, very old indeed
JavaScript
1
star
26

ruby-packer-tests

Performing download-and-run tests on the single binaries generated by Ruby Packer.
PowerShell
1
star
27

bio

DNAๅบๅˆ—ไธ‰็ปดๆ‹Ÿๅˆ
Ruby
1
star
28

jgdianping

Evaluation Website for Training institutions
1
star
29

pmq20.github.io

https://www.minqi-pan.com
TeX
1
star
30

cssImagePeeler

Peel Off images From a CSS file and Save them onto disk
Ruby
1
star
31

silver-data

1
star
32

rails-diff-track

tracks the diff of the default directory structure generated by `rails new`
Ruby
1
star
33

ie_isolation

Isolate a set of views specially for IE and deprecated browsers for Ruby on Rails.
1
star
34

active_record_dump

dumps your database to active record statements and then can be easily transferred to other databases
1
star
35

rng2sql

A tool to convert RELAX NG to SQL tables, or, put in another way, creating SQL tables according to RELAX NG
1
star
36

rails-redis-cache

Redis-based query cache for rails models, like get_name_via_id, get_address_via_name, etc.
1
star
37

tracing-a-memory-leak-in-a-long-running-eventmachine-application-en

Presentation: In Huanteng Smart we manufacture smart household gadgets which all connect to a single long running eventmachine application to receive and send instructions with the server. This eventmachine application is a single Linux process holding all TCP connections never closes them. One day, we found that this process was leaking memory, and here is how we managed to trace its cause.
R
1
star
38

ios_hello_world

Simple iOS prj as a team Run-in
Objective-C
1
star