Permalink
Browse files

upgrades wip

  • Loading branch information...
pulpofred
pulpofred committed Nov 17, 2015
1 parent 3dd47e3 commit 2222d58e813a05760d2dc5d156ec8f8af4da344a
Showing with 69 additions and 31 deletions.
  1. +30 −6 build.tcl
  2. +10 −10 fruho/main.tcl
  3. +24 −1 fruhod/main.tcl
  4. +5 −14 sklib/skutil.tcl
@@ -122,7 +122,7 @@ proc test {} {
# convert commit log into dict commit# => commit_line
proc parse-commits {commits} {
set commit2msg [dict create]
set prev ""
@@ -179,6 +179,7 @@ proc github-upload-artifacts {upload_url gituser gitpass} {
return $artifacts
}
# generate html with list of commits/changes
proc html-changelog {commit2msg} {
set html ""
dict for {commit msg} $commit2msg {
@@ -216,22 +217,45 @@ proc release {gituser} {
}
set ::FRUHO_VERSION 0.0.7
prepare-lib sklib 0.0.0
proc push-update {os arch tohost} {
lappend ::auto_path [file normalize ./lib/generic]
package require skutil
set updatedir [file normalize ./build/update/$::FRUHO_VERSION/$os-$arch]
file mkdir $updatedir
set fc [file normalize ./build/fruho/$os-$arch/fruho.bin]
set fd [file normalize ./build/fruhod/$os-$arch/fruhod.bin]
set privkey [file normalize ../confidential/sk/keys/fruho/signer/signer_private.pem]
# sign the binaries
create-signature $privkey $fc
create-signature $privkey $fd
# zip the bundle
set zip $updatedir/update.zip
ex rm $zip
ex zip -j $zip $fc $fc.sig $fd $fd.sig
# ssh push
set remotezip /tmp/fruho-update-$::FRUHO_VERSION-$os-$arch-update.zip
puts "Uploading $remotezip to $tohost"
ex scp $zip $tohost:$remotezip
}
set ::FRUHO_VERSION 0.0.7
prepare-lib sklib 0.0.0
#build-total
#package require i18n
#i18n code2msg ./fruho/main.tcl {es pl} ./fruho/messages.txt
build-fruho linux [this-arch]
build-fruhod linux [this-arch]
build-deb-rpm [this-arch]
#push-update linux [this-arch] vbox_123
#release hypatia2
@@ -2069,12 +2069,11 @@ proc UpdateNowClicked {uframe} {
set about .options_dialog.nb.about
$uframe.button configure -state disabled
set version $::model::Latest_version
if {[int-ver $version] <= [int-ver [build-version]]} {
log Nothing to update. This build version is [build-version]. Latest version is $version
if {[int-ver $::model::Latest_version] <= [int-ver [build-version]]} {
log Nothing to update. This build version is [build-version]. Latest version is $::model::Latest_version
return
}
set dir [file join $::model::UPGRADEDIR $version]
set dir [file join $::model::UPGRADEDIR $::model::Latest_version]
file mkdir $dir
go download-get-update $uframe $dir
} on error {e1 e2} {
@@ -2966,19 +2965,20 @@ proc ffread-loop {} {
}
{^version (\S+) (.*)$} {
set daemon_version [lindex $details 1]
puts stderr "DAEMON VERSION: $daemon_version"
puts stderr "FRUHO CLIENT VERSION: [build-version]"
puts stderr [log "DAEMON VERSION: $daemon_version"]
puts stderr [log "FRUHO CLIENT VERSION: [build-version]"]
# fruho client to restart itself if daemon already upgraded and not too often
if {[int-ver $daemon_version] > [int-ver [build-version]]} {
set sha [sha1sum [this-binary]]
# restart only if different binaries
if {$sha ne $::model::Running_binary_fingerprint} {
if {[sha1sum [this-binary]] ne $::model::Running_binary_fingerprint} {
puts stderr [log Different binaries detected]
model save
set err [seamless-upgrade $dir/fruhod.bin [this-binary]]
# Restart itself - the fruho client binary was replaced by the daemon
# Note: If you are using execl in a Tk application and it fails, you may not do anything that accesses the X server or you will receive a BadWindow error from the X server. This includes exe-cuting the Tk version of the exit command. We suggest using the following command to abort Tk applications after an execl fail-ure:
execl [this-binary]
kill [id process]
} else {
log Aborted. Trying to seamless-upgrade to the same binary
puts stderr [log Aborted. Version mismatch between daemon and client detected but client sees the same binary]
}
}
@@ -275,8 +275,31 @@ proc ffread {} {
set dir [lindex $tokens 1]
# if upgrade is successfull it never returns (execl replace program)
#set err [upgrade $dir]
# First try to upgrade the daemon
set err [seamless-upgrade $dir/fruhod.bin [this-binary]]
ffwrite ctrl [log "Could not upgrade from $dir: $err"]
if {$err ne ""} {
ffwrite ctrl [log "Could not upgrade [this-binary] from $dir: $err"]
return
}
# Try to upgrade fruho client only if daemon succeeded
# We need to do it here in fruhod because we need root
set err [seamless-upgrade $dir/fruho.bin /usr/local/bin/fruho.bin]
if {$err ne ""} {
ffwrite ctrl [log "Could not upgrade /usr/local/bin/fruho.bin from $dir: $err"]
return
}
# Restart the daemon only if both succeeded
# Fruho client will restart itself after detecting version mismatch
# execl replaces the calling process image with a new process image.
# This has the effect of running a new program with the process ID of the calling process.
# if this does not fail it never returns
# Note: If you are using execl in a Tk application and it fails, you may not do anything that accesses the X server or you will receive a BadWindow error from the X server. This includes exe-cuting the Tk version of the exit command. We suggest using the following command to abort Tk applications after an execl fail-ure:
# kill [id process]
# On Windows, where the fork command is not available, execl starts a new process and returns the process id.
execl [this-binary]
}
default {
ffwrite ctrl "Unknown command"
@@ -911,19 +911,14 @@ proc this-binary {} {
# seamless upgrade (wishful thinking huh?)
# Used separately by client and daemon.
# On success, it never returns (program is restarted within the same process by execl)
# On success return empty string
# On failure, revert changes and return descriptive error
# Steps:
# - verify signature (signature file is implied from src file by suffixing it with .sig)
# - backup dst to /tmp
# - replace and chmod src to dst
# - execl - restart by replacing process image in memory
proc seamless-upgrade {src dst} {
try {
# assertion to allow only upgrade to the location of the running process
if {$dst ne [this-binary]} {
return [log seamless-upgrade to dst: $dst failed. Can only upgrade to the running process location [this-binary]]
}
foreach f [list $src $src.sig $dst] {
# use "exists" instead of "isfile" since when run as starkit the process does not see itself as a file
if {![file exists $f]} {
@@ -942,14 +937,10 @@ proc seamless-upgrade {src dst} {
# we must use external system commands the file command does not work on the currently running program
exec mv $dst $bf
exec cp -f $src $dst
exec chmod u+rwx,go+rx $src
# execl replaces the calling process image with a new process image.
# This has the effect of running a new program with the process ID of the calling process.
# if this does not fail it never returns
# Note: If you are using execl in a Tk application and it fails, you may not do anything that accesses the X server or you will receive a BadWindow error from the X server. This includes exe-cuting the Tk version of the exit command. We suggest using the following command to abort Tk applications after an execl fail-ure:
# kill [id process]
# On Windows, where the fork command is not available, execl starts a new process and returns the process id.
execl $dst
log Changing permissions: chmod u+rwx,go+rx $dst
set chmodout [exec chmod u+rwx,go+rx $dst 2>@1]
log $chmodout
return
} on error {e1 e2} {
# restore binaries from the backup path
catch {

0 comments on commit 2222d58

Please sign in to comment.