summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2009-09-10 08:31:05 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2009-09-10 08:31:05 +0200
commit2008ba326f55e3dd7eb88da10fb94d4907f29a27 (patch)
tree1b57d4bbfd8462835de9f2db5eccb4a4a0bc1d68 /bin
parentab732dc7bae9b524ee01531bc11bb4d8e1a9240d (diff)
Sorted some stuff
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ct350
1 files changed, 177 insertions, 173 deletions
diff --git a/bin/ct b/bin/ct
index b03358e..6582398 100755
--- a/bin/ct
+++ b/bin/ct
@@ -17,12 +17,16 @@
setopt extended_glob
typeset -a -U triggers
typeset -a PKG_ROOTS CL_OPTIONS
-typeset self=$0
+
+# required by pkg_debug, since functions have their name as $0
+self=$0
c_info=$'\e[0;36m'
c_error=$'\e[0;31m'
c_reset=$'\e[0m'
+## Basic output functions
+
function info {
echo -ne - "${c_info}$*${c_reset}"
}
@@ -212,20 +216,6 @@ function progress {
## VCS Wrappers
-function vcs_setup {
- cd $PKG_DIR/$1
-}
-
-function vcs_to_list (
- vcs_setup $1
- if [[ -d $PKG_DIR/$1/.git ]] {
- echo -n - "$1 git "
- echo ${$(git log -n 1 master)[2]}
- } else {
- warn "No git repository found: '$1'\n"
- }
-)
-
function vcs_add (
pkgroot_parse $(list_get_root $1)
cd $PKG_DIR
@@ -239,11 +229,6 @@ function vcs_add (
pkgroot_clean
)
-function vcs_log (
- vcs_setup $1
- git log
-)
-
function vcs_branch_is_master (
vcs_setup $1
typeset IFS=$'\n' branch line
@@ -258,6 +243,11 @@ function vcs_branch_is_master (
}
)
+function vcs_log (
+ vcs_setup $1
+ git log
+)
+
function vcs_pull (
vcs_setup $1
if ((GIT_USE_ORIGIN)) {
@@ -279,6 +269,10 @@ function vcs_push (
}
)
+function vcs_setup {
+ cd $PKG_DIR/$1
+}
+
function vcs_status (
typeset gitstatus
vcs_setup $1
@@ -287,14 +281,45 @@ function vcs_status (
echo $gitstatus
)
+function vcs_to_list (
+ vcs_setup $1
+ if [[ -d $PKG_DIR/$1/.git ]] {
+ echo -n - "$1 git "
+ echo ${$(git log -n 1 master)[2]}
+ } else {
+ warn "No git repository found: '$1'\n"
+ }
+)
+
## List stuff
+function list_exists {
+ grep -q "^$1 " $PKG_DIR/.list-remote
+}
+
+function list_get_root {
+ echo - ${$(grep "^$1 " $PKG_DIR/.list-remote)[4]}
+}
+
+function list_incoming {
+ [[ $(list_version_local $1) != $(list_version_remote $1) ]]
+}
+
function list_is_installed {
grep -q "^$1 " $PKG_DIR/.list
}
-function list_exists {
- grep -q "^$1 " $PKG_DIR/.list-remote
+function list_package_update {
+ typeset list
+ list=$(grep -v "^$1 " $PKG_DIR/.list)
+ echo - $list > $PKG_DIR/.list
+ vcs_to_list $1 >> $PKG_DIR/.list
+}
+
+function list_package_remove {
+ typeset list
+ list=$(grep -v "^$1 " $PKG_DIR/.list)
+ echo - $list > $PKG_DIR/.list
}
function list_packages_local {
@@ -305,14 +330,6 @@ function list_packages_remote {
cut -d ' ' -f 1 $PKG_DIR/.list-remote
}
-function list_incoming {
- [[ $(list_version_local $1) != $(list_version_remote $1) ]]
-}
-
-function list_get_root {
- echo - ${$(grep "^$1 " $PKG_DIR/.list-remote)[4]}
-}
-
function list_type {
echo - ${$(grep "^$1 " $PKG_DIR/.list-remote)[2]}
}
@@ -321,6 +338,18 @@ function list_type_local {
echo - ${$(grep "^$1 " $PKG_DIR/.list)[2]}
}
+function list_update_local {
+ typeset -i all=${#$(echo $PKG_DIR/*(/))}
+ typeset -i current=0
+ typeset package
+ rm -f $PKG_DIR/.list
+ for package in *(-/); {
+ (( current++ ))
+ progress $current $all 'Updating package list' $package
+ vcs_to_list $package >> $PKG_DIR/.list
+ }
+}
+
function list_update_remote {
typeset tmpfile=$(mktemp -t pkglist.XXXXXX) PKG_ROOT
typeset -i ret=0
@@ -342,31 +371,6 @@ function list_update_remote {
}
}
-function list_update_local {
- typeset -i all=${#$(echo $PKG_DIR/*(/))}
- typeset -i current=0
- typeset package
- rm -f $PKG_DIR/.list
- for package in *(-/); {
- (( current++ ))
- progress $current $all 'Updating package list' $package
- vcs_to_list $package >> $PKG_DIR/.list
- }
-}
-
-function list_package_update {
- typeset list
- list=$(grep -v "^$1 " $PKG_DIR/.list)
- echo - $list > $PKG_DIR/.list
- vcs_to_list $1 >> $PKG_DIR/.list
-}
-
-function list_package_remove {
- typeset list
- list=$(grep -v "^$1 " $PKG_DIR/.list)
- echo - $list > $PKG_DIR/.list
-}
-
function list_version_local {
echo ${$(grep "^$1 " $PKG_DIR/.list)[3]}
}
@@ -651,94 +655,30 @@ function pkg_add {
global_hook $1 post-add
}
-function pkg_push {
- check_installed $1
- if list_incoming $1 || ! list_exists $1; then
- clear_line
- info "Pushing $1\n"
- global_hook $1 pre-update
- vcs_push $1
- global_hook $1 post-update
- fi
-}
-
-function pkg_remove {
- check_installed $1
- if [[ -r $PKG_DIR/$1/priority ]] {
- if (( $(cat $PKG_DIR/$1/priority) > 3 )) {
- confirm_no "Package '$1' is $(priority_name $(cat $PKG_DIR/$1/priority)). Really remove?" || return
- }
- }
- global_hook $1 pre-remove
- rm -rf $PKG_DIR/$1
- info "Package removed.\n"
-}
-
-function pkg_upgrade {
- check_installed $1
- if list_exists $1 && [[ $(list_type $1) != $(list_type_local $1) ]]; then
- clear_line
- warn "Incompatible systems. Please reinstall: $1\n"
- warn " remote '$(list_type $1)' <-> local '$(list_type_local $1)'\n"
- return 9
- fi
- if list_incoming $1 || ! list_exists $1; then
- clear_line
- info "Updating $1 to $(list_version_remote $1)\n"
- global_hook $1 pre-update
- vcs_pull $1
- global_hook $1 post-update
- fi
-}
-
-function pkg_list {
- typeset package crap
- case $1 in
- ''|local)
- list_packages_local
- ;;
- all|remote)
- list_packages_remote
- ;;
- not-installed)
- for package in $(list_packages_remote); {
- list_is_installed $package || echo $package
- }
- ;;
- esac
-}
-
-function pkg_status {
- typeset vcs_status
- check_installed $1
- vcs_status=$(PAGER='' vcs_status $1)
- if [[ -n $vcs_status ]] {
- if ((SILENT)) {
- echo $1
- } else {
- clear_line
- info "$1:\n"
- echo $vcs_status
- }
- }
-}
-
-function pkg_refresh {
- check_installed $1
- global_hook $1 pre-update
- global_hook $1 post-update
-}
-
-function pkg_update {
- if [[ -z $1 || $1 == local ]] {
- info "Updating local package list\n"
- list_update_local
- clear_line
- }
- if [[ -z $1 || $1 == remote ]] {
- info "Updating remote package list\n"
- list_update_remote
+function pkg_debug {
+ echo "--- running ---"
+ echo " zsh $ZSH_VERSION"
+ echo " git "${$(git --version)[3]}
+ echo " caretaker "${$(git --git-dir=$PKG_DIR/${${(s:/:)$(readlink $self)}[-3]}/.git/ log -n 1)[2]}
+ echo "--- settings ---"
+ echo " PKGLIST_LOCAL $PKGLIST_LOCAL"
+ for PKG_ROOT in $PKG_ROOTS; {
+ pkgroot_parse $PKG_ROOT
+ echo " PKG_ROOT $PKG_ROOT"
+ echo " PKG_PROTO $PKG_PROTO"
+ echo " PKG_USER $PKG_USER"
+ echo " PKG_HOST $PKG_HOST"
+ echo " PKG_UAH $PKG_UAH"
+ echo " PKGLIST_PATH $PKGLIST_PATH"
+ pkgroot_clean
}
+ echo " PKG_DIR $PKG_DIR"
+ echo " CL_OPTIONS $CL_OPTIONS"
+ echo " SILENT $SILENT"
+ echo " COLOURS $COLOURS"
+ echo " PROGRESS $PROGRESS"
+ echo " AUTOUPDATE $AUTOUPDATE"
+ echo " GIT_USE_ORIGIN $GIT_USE_ORIGIN"
}
function pkg_info {
@@ -794,30 +734,21 @@ function pkg_info {
show_info 'Description' $description
}
-function pkg_debug {
- echo "--- running ---"
- echo " zsh $ZSH_VERSION"
- echo " git "${$(git --version)[3]}
- echo " caretaker "${$(git --git-dir=$PKG_DIR/${${(s:/:)$(readlink $self)}[-3]}/.git/ log -n 1)[2]}
- echo "--- settings ---"
- echo " PKGLIST_LOCAL $PKGLIST_LOCAL"
- for PKG_ROOT in $PKG_ROOTS; {
- pkgroot_parse $PKG_ROOT
- echo " PKG_ROOT $PKG_ROOT"
- echo " PKG_PROTO $PKG_PROTO"
- echo " PKG_USER $PKG_USER"
- echo " PKG_HOST $PKG_HOST"
- echo " PKG_UAH $PKG_UAH"
- echo " PKGLIST_PATH $PKGLIST_PATH"
- pkgroot_clean
- }
- echo " PKG_DIR $PKG_DIR"
- echo " CL_OPTIONS $CL_OPTIONS"
- echo " SILENT $SILENT"
- echo " COLOURS $COLOURS"
- echo " PROGRESS $PROGRESS"
- echo " AUTOUPDATE $AUTOUPDATE"
- echo " GIT_USE_ORIGIN $GIT_USE_ORIGIN"
+function pkg_list {
+ typeset package crap
+ case $1 in
+ ''|local)
+ list_packages_local
+ ;;
+ all|remote)
+ list_packages_remote
+ ;;
+ not-installed)
+ for package in $(list_packages_remote); {
+ list_is_installed $package || echo $package
+ }
+ ;;
+ esac
}
function pkg_log {
@@ -825,6 +756,79 @@ function pkg_log {
vcs_log $1
}
+function pkg_push {
+ check_installed $1
+ if list_incoming $1 || ! list_exists $1; then
+ clear_line
+ info "Pushing $1\n"
+ global_hook $1 pre-update
+ vcs_push $1
+ global_hook $1 post-update
+ fi
+}
+
+function pkg_refresh {
+ check_installed $1
+ global_hook $1 pre-update
+ global_hook $1 post-update
+}
+
+function pkg_remove {
+ check_installed $1
+ if [[ -r $PKG_DIR/$1/priority ]] {
+ if (( $(cat $PKG_DIR/$1/priority) > 3 )) {
+ confirm_no "Package '$1' is $(priority_name $(cat $PKG_DIR/$1/priority)). Really remove?" || return
+ }
+ }
+ global_hook $1 pre-remove
+ rm -rf $PKG_DIR/$1
+ info "Package removed.\n"
+}
+
+function pkg_status {
+ typeset vcs_status
+ check_installed $1
+ vcs_status=$(PAGER='' vcs_status $1)
+ if [[ -n $vcs_status ]] {
+ if ((SILENT)) {
+ echo $1
+ } else {
+ clear_line
+ info "$1:\n"
+ echo $vcs_status
+ }
+ }
+}
+
+function pkg_update {
+ if [[ -z $1 || $1 == local ]] {
+ info "Updating local package list\n"
+ list_update_local
+ clear_line
+ }
+ if [[ -z $1 || $1 == remote ]] {
+ info "Updating remote package list\n"
+ list_update_remote
+ }
+}
+
+function pkg_upgrade {
+ check_installed $1
+ if list_exists $1 && [[ $(list_type $1) != $(list_type_local $1) ]]; then
+ clear_line
+ warn "Incompatible systems. Please reinstall: $1\n"
+ warn " remote '$(list_type $1)' <-> local '$(list_type_local $1)'\n"
+ return 9
+ fi
+ if list_incoming $1 || ! list_exists $1; then
+ clear_line
+ info "Updating $1 to $(list_version_remote $1)\n"
+ global_hook $1 pre-update
+ vcs_pull $1
+ global_hook $1 post-update
+ fi
+}
+
cd $PKG_DIR || die "Cannot cd $PKG_DIR"
@@ -832,23 +836,23 @@ cd $PKG_DIR || die "Cannot cd $PKG_DIR"
# wrap foobar "$1" <- the "" are neccessary here, since $1 is optional (and therefore may be empty)
case $action in
a|add) pkg_add $* ;;
- rm|remove) pkg_remove $* ;;
+ debug) pkg_debug $* ;;
+ e|eval) eval $* ;;
i|info) pkg_info $* ;;
ls|list) pkg_list $* ;;
l|log) pkg_log $* ;;
+ f|pull)
+ (( AUTOUPDATE )) && pkg_update remote
+ wrap pkg_upgrade "$1" 'Looking for updates'
+ ;;
p|push)
(( AUTOUPDATE )) && pkg_update
wrap pkg_push "$1" 'Pushing'
;;
r|refresh) wrap pkg_refresh "$1" 'Refreshing' ;;
+ rm|remove) pkg_remove $* ;;
s|status) wrap pkg_status "$1" 'Checking package status' ;;
u|update) pkg_update $* ;;
- f|pull)
- (( AUTOUPDATE )) && pkg_update remote
- wrap pkg_upgrade "$1" 'Looking for updates'
- ;;
- e|eval) eval $* ;;
- debug) pkg_debug $* ;;
*) die "wait, what?\nct: unknown action: '$action'\n" ;;
esac