Merge pull request #320 from deevus/scoop-update-git

Scoop update using git
This commit is contained in:
Simon Hartcher
2015-04-05 12:35:21 +10:00
3 changed files with 47 additions and 41 deletions
-2
View File
@@ -29,8 +29,6 @@ cp "$dir\_scoop_extract\scoop-master\*" $dir -r -force
rm "$dir\_scoop_extract" -r -force
rm $zipfile
$null > "$dir\last_updated" # save install timestamp
echo 'creating shim...'
shim "$dir\bin\scoop.ps1" $false
+15 -11
View File
@@ -8,21 +8,25 @@
. "$psscriptroot\..\lib\depends.ps1"
. "$psscriptroot\..\lib\config.ps1"
function timeago($when) {
$diff = [datetime]::now - $last_update
# check if scoop needs updating
$currentdir = fullpath $(versiondir 'scoop' 'current')
$needs_update = $false
if($diff.totaldays -gt 2) { return "$([int]$diff.totaldays) days ago" }
if($diff.totalhours -gt 2) { return "$([int]$diff.totalhours) hours ago" }
if($diff.totalminutes -gt 2) { return "$([int]$diff.totalminutes) minutes ago" }
return "$([int]$diff.totalseconds) seconds ago"
if(test-path "$currentdir\.git") {
pushd $currentdir
git fetch -q origin
$commits = $(git log "HEAD..origin/$(scoop config SCOOP_BRANCH)" --oneline)
if($commits) { $needs_update = $true }
popd
}
else {
$needs_update = $true
}
# check when scoop was last updated
$timestamp = "$(versiondir 'scoop' 'current')\last_updated"
if(test-path $timestamp) {
$last_update = [io.file]::getlastwritetime((resolve-path $timestamp))
"scoop was last updated $(timeago($last_update))"
if($needs_update) {
"scoop is out of date. run scoop update to get the latest changes."
}
else { "scoop is up-to-date."}
$failed = @()
$old = @()
+32 -28
View File
@@ -26,42 +26,46 @@ $force = $opt.f -or $opt.force
$use_cache = !($opt.k -or $opt.'no-cache')
function update_scoop() {
$tempdir = versiondir 'scoop' 'update'
$currentdir = versiondir 'scoop' 'current'
# check for git
$git = try { gcm git -ea stop } catch { $null }
if(!$git) { abort "scoop uses git to update itself. run 'scoop install git'." }
if(test-path $tempdir) {
try { rm -r $tempdir -ea stop -force } catch { abort "couldn't remove $tempdir`: it may be in use" }
"updating scoop..."
$currentdir = fullpath $(versiondir 'scoop' 'current')
if(!(test-path "$currentdir\.git")) {
# load config
$repo = $(scoop config SCOOP_REPO)
if(!$repo) {
$repo = "http://github.com/lukesampson/scoop"
scoop config SCOOP_REPO "$repo"
}
$branch = $(scoop config SCOOP_BRANCH)
if(!$branch) {
$branch = "master"
scoop config SCOOP_BRANCH "$branch"
}
# remove non-git scoop
rm -r -force $currentdir -ea stop
# get git scoop
git clone -q $repo --branch $branch --single-branch $currentdir
}
else {
pushd $currentdir
git pull -q
popd
}
$tempdir = ensure $tempdir
$currentdir = fullpath $currentdir
$zipurl = 'https://github.com/lukesampson/scoop/archive/master.zip'
$zipfile = "$tempdir\scoop.zip"
echo 'downloading...'
dl $zipurl $zipfile
echo 'extracting...'
unzip $zipfile $tempdir
rm $zipfile
echo 'replacing files...'
$null = robocopy "$tempdir\scoop-master" $currentdir /mir /njh /njs /nfl /ndl
rm -r -force $tempdir -ea stop
$null > "$currentdir\last_updated" # save update timestamp
ensure_scoop_in_path
shim "$currentdir\bin\scoop.ps1" $false
@(buckets) | % {
"updating $_ bucket..."
$git = try { gcm git -ea stop } catch { $null }
if(!$git) { warn "git is required for buckets. run 'scoop install git'." }
else {
pushd (bucketdir $_)
git pull -q
popd
}
pushd (bucketdir $_)
git pull -q
popd
}
success 'scoop was updated successfully!'
}