From a96a0642df506a2694df792bf8104a821310b59d Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Fri, 19 Jun 2009 19:09:45 -0500 Subject: [PATCH] * byobu, byobu-janitor, debian/install, profiles/common, profiles/profile.skel: remove janitorial logic scattered across several scripts and put it in a single place; call this script before launching byobu, and then only once a day or when the user refreshes their profile Signed-off-by: Dustin Kirkland --- byobu | 95 +++++-------------------------------------- byobu-janitor | 57 ++++++++++++++++++++++++++ debian/changelog | 7 +++- debian/install | 1 + profiles/common | 1 + profiles/profile.skel | 2 +- 6 files changed, 77 insertions(+), 86 deletions(-) create mode 100644 byobu-janitor diff --git a/byobu b/byobu index 72eed69f..d7e9c070 100755 --- a/byobu +++ b/byobu @@ -1,7 +1,7 @@ #!/bin/sh # -# screen wrapper script -# Copyright (C) 2008 Canonical Ltd. +# byobu - screen wrapper script +# Copyright (C) 2008-2009 Canonical Ltd. # # Authors: Dustin Kirkland # @@ -17,93 +17,20 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -OLDPKG="screen-profiles" PKG="byobu" -SCREEN_REAL="screen" -# Upgrade old config dir to the new name -[ -d "$HOME/.$OLDPKG" -a ! -e "$HOME/.$PKG" ] && mv -f "$HOME/.$OLDPKG" "$HOME/.$PKG" +# Sanitize the environment +byobu-janitor -# Create the .$PKG directory, if it doesn't already exist -[ -d "$HOME/.$PKG" ] || mkdir -p "$HOME/.$PKG" - -# Use $SCREENRC if non-empty, and readable; otherwise, use the one in $HOME -[ -n "$SCREENRC" -a -r "$SCREENRC" ] || SCREENRC="$HOME/.screenrc" - -# If $SCREENRC exists but $HOME/.$PKG/profile does not, -# this shows that the user has an existing custom screen configuration, -# and thus we will not force $PKG on them. -if [ -r "$SCREENRC" -a ! -e "$HOME/.$PKG/profile" -a ! -h "$HOME/.$PKG/profile" ]; then - exec $SCREEN_REAL -c "$SCREENRC" "$@" - exit $? -fi - -# If the user is running byobu with some arguments, but has not selected -# their profile yet, don't bother them with profile selection at this time -if [ $# -gt 0 -a ! -h "$HOME/.$PKG/profile" ]; then - exec $SCREEN_REAL "$@" - exit $? -fi - -DEFAULT_PROFILE="light" - -# Ensure that the user has selected a screen profile -profile="$HOME/.$PKG/profile" -[ -h "$profile" ] || select-screen-profile -s "$DEFAULT_PROFILE" - -# Previously, profiles were prepended with ubuntu-. -# This is no longer the case, for cross-distro compatibility. -# Try to fix broken symlinks for upgrading users, or prompt to reselect. -if [ -h "$profile" -a ! -r "$profile" ]; then - if stat "$profile" | head -n1 | grep -qs ".*->.*ubuntu\-.*"; then - newsrc=$(stat "$profile" | head -n1 | sed "s/.*\`//" | sed "s/'.*//" | sed "s/ubuntu-//") - if [ -r "$newsrc" ]; then - ln -sf "$newsrc" "$profile" - else - select-screen-profile -s "$DEFAULT_PROFILE" - fi - elif stat "$profile" | head -n1 | grep -qs ".*->.*plain'$"; then - ln -sf "/usr/share/$PKG/profiles/NONE" "$profile" - else - select-screen-profile -s "$DEFAULT_PROFILE" - fi -fi - -if [ ! -r "$profile" ]; then - echo - echo "Your selected profile is not accessible." - echo - echo "Either select a different profile:" - echo " $ select-screen-profile" - echo - echo "Or install the extras package:" - echo " $ sudo apt-get install $PKG-extras" - echo - exit 1 -fi - -# Ensure that their keybindings are seeded -[ -s "$HOME/.$PKG/keybindings" ] || echo "source /usr/share/$PKG/keybindings/common" > "$HOME/.$PKG/keybindings" -sed -i "s/$OLDPKG/$PKG/g" "$HOME/.$PKG/keybindings" - -# Ensure that the user's configuration is seeded -[ -r "$HOME/.$PKG/status" ] || touch "$HOME/.$PKG/status" -[ -r "$HOME/.$PKG/windows" ] || touch "$HOME/.$PKG/windows" -if grep -qs "^[^#]" "$HOME/.$PKG/windows"; then - # User has some default windows, so don't launch motd+shell - DEFAULT_WINDOW= -else - # User has no default windows, so launch motd+shell - DEFAULT_WINDOW="$SHELL -c motd+shell" -fi - -# Ensure that the user's $SCREENRC at least exists -[ -r "$SCREENRC" ] || touch "$SCREENRC" +# Launch motd+shell, unless the user has default windows set to launch +[ -n "$SHELL" ] || SHELL="/bin/sh" +[ -x "$SHELL" ] || SHELL="/bin/sh" +DEFAULT_WINDOW="$SHELL -c motd+shell" +grep -qs "^[^#]" "$HOME/.$PKG/windows" && DEFAULT_WINDOW= # Now let's execute screen! if [ "$#" = "0" ]; then - [ -n "$SHELL" -a -x "$SHELL" ] || SHELL="/bin/sh" - exec $SCREEN_REAL -c "/usr/share/$PKG/profiles/byoburc" $DEFAULT_WINDOW + exec screen -c "/usr/share/$PKG/profiles/byoburc" $DEFAULT_WINDOW else - exec $SCREEN_REAL -c "$HOME/.$PKG/profile" "$@" + exec screen -c "$HOME/.$PKG/profile" "$@" fi diff --git a/byobu-janitor b/byobu-janitor new file mode 100644 index 00000000..1eaccd69 --- /dev/null +++ b/byobu-janitor @@ -0,0 +1,57 @@ +#!/bin/sh -e +# +# byobu-janitor - a collection of byobu tasks that ensure a clean +# environtment and smooth upgrades +# +# Copyright (C) 2009 Canonical Ltd. +# +# Authors: Dustin Kirkland +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +OLDPKG="screen-profiles" +PKG="byobu" +DEFAULT_PROFILE="light" +PROFILE="$HOME/.$PKG/profile" + +# Affects: Upgrades from screen-profiles +# If the old config dir exists, but the new one doesn't, provide a migration mechanism. +if [ -d "$HOME/.$OLDPKG" ] && [ ! -e "$HOME/.$PKG" ]; then + # Rename the config dir + mv -f "$HOME/.$OLDPKG" "$HOME/.$PKG" + ln -sf "$HOME/.$PKG" "$HOME/.$OLDPKG" + # Replace all instances of the old package name with the new + sed -i "s/$OLDPKG/$PKG/g" "$HOME/.$PKG"/* + # Fix the chosen profile symlink + if [ -h "$PROFILE" ]; then + # Determine the chosen profile color + profile=`readlink "$PROFILE" | sed "s:^.*-::"` + # Try to set that color, if it exists, otherwise set to default + select-screen-profile -s "$profile" >/dev/null 2>&1 || select-screen-profile -s "$DEFAULT_PROFILE" >/dev/null 2>&1 + fi +fi + +# Affects: First runs with no configuration +# Seed the configuration +[ -d "$HOME/.$PKG" ] || mkdir -p "$HOME/.$PKG" +[ -r "$PROFILE" ] || select-screen-profile -s "$DEFAULT_PROFILE" >/dev/null 2>&1 +[ -s "$HOME/.$PKG/keybindings" ] || echo "source /usr/share/$PKG/keybindings/common" > "$HOME/.$PKG/keybindings" +[ -r "$HOME/.$PKG/status" ] || touch "$HOME/.$PKG/status" +[ -r "$HOME/.$PKG/windows" ] || touch "$HOME/.$PKG/windows" +[ -r "$HOME/.screenrc" ] || touch "$HOME/.screenrc" + +# Affects: Upgrades from <= byobu-2.11 +# The status scripts used to have hyphens in their name, but now use +# underscores such that we can source the file as a shell snippet; +# fix existing status configuration. +sed -i "s/-/_/g" "$HOME/.$PKG/status" diff --git a/debian/changelog b/debian/changelog index fe31e920..7261019a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,11 +13,16 @@ byobu (2.13) unreleased; urgency=low * byobu-status: move all of the cleanup hacks to byobu-janitor; create a find_script() function that allows for scripts in both /usr/lib and $HOME/.byobu + * byobu, byobu-janitor, debian/install, profiles/common, + profiles/profile.skel: remove janitorial logic scattered across + several scripts and put it in a single place; call this script before + launching byobu, and then only once a day or when the user refreshes + their profile [ Ciemon Dunville ] * byobu.1: reflect the keybinding toggle change to Ctrl-a-! - -- Dustin Kirkland Fri, 19 Jun 2009 17:50:59 -0500 + -- Dustin Kirkland Fri, 19 Jun 2009 19:09:36 -0500 byobu (2.12-0ubuntu1) karmic; urgency=low diff --git a/debian/install b/debian/install index a12036fc..662118e4 100644 --- a/debian/install +++ b/debian/install @@ -14,6 +14,7 @@ byobu usr/bin byobu-config usr/bin byobu-status usr/bin byobu-status-detail usr/bin +byobu-janitor usr/bin screen-launcher-install usr/share/byobu screen-launcher-uninstall usr/share/byobu motd+shell usr/bin diff --git a/profiles/common b/profiles/common index b91fb889..6e5b74c4 100644 --- a/profiles/common +++ b/profiles/common @@ -32,6 +32,7 @@ msgwait 1 # ~600 ~10 minutes # ~180 ~3 minutes # ~60 ~1 minute +backtick 10 86399 86399 byobu-janitor backtick 99 86011 86011 byobu-status logo backtick 100 599 599 byobu-status release backtick 101 181 181 byobu-status updates_available diff --git a/profiles/profile.skel b/profiles/profile.skel index 833d6f0e..370c0cda 100644 --- a/profiles/profile.skel +++ b/profiles/profile.skel @@ -23,7 +23,7 @@ source /usr/share/byobu/profiles/common # Window tabs, second to last line -caption always "%{kW}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{kW}%?%+Lw%? %= %{= Wk}%110`%109`%122`%111`" +caption always "%{kW}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{kW}%?%+Lw%? %= %{= Wk}%110`%109`%122`%111`%10`" # Status string, last line hardstatus string '%99`%{= Wk} %100`%112`%= %102`%101`%127`%114`%115`%108`%125`%126`%113`%119`%117`%116`%106`%104`%103`%105`%107`%123`%120`%121`'