From 5d3d10368a1a32d085dadff36cab89580fea3fbc Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Sat, 12 Dec 2009 10:31:25 -0800 Subject: [PATCH] * byobu-export, byobu-config: - comprehensively rewritten, basically put all of byobu's installed files in ~/.byobu, and use some clever sed scripts to fixup paths --- byobu-config | 18 +++++---- byobu-export | 112 +++++++++++++++++---------------------------------- 2 files changed, 46 insertions(+), 84 deletions(-) diff --git a/byobu-config b/byobu-config index 738ba46a..63f06d3c 100755 --- a/byobu-config +++ b/byobu-config @@ -30,7 +30,11 @@ HOME=os.getenv("HOME") USER=os.getenv("USER") PKG="byobu" SHARE='/usr/share/'+PKG +if not os.path.exists(SHARE): + SHARE = "%s/.%s/%s" % (HOME, PKG, SHARE) DOC='/usr/share/doc/'+PKG +if not os.path.exists(DOC): + DOC = "%s/.%s/%s" % (HOME, PKG, DOC) DEF_ESC="A" RELOAD = "If you are using the default set of keybindings, press\n or to activate these changes.\n\nOtherwise, exit this screen session and start a new one." RELOAD_FLAG="/var/run/screen/S-"+USER+"/"+PKG+".reload-required" @@ -106,8 +110,7 @@ def menu(screen, size, isInstalled): else: return li.current() -def messagebox(screen, width, height, title, text, \ - scroll=0, \ +def messagebox(screen, width, height, title, text, scroll=0, \ buttons=((_("Okay"), "okay"),(_("Cancel"), "cancel", ESC)) ): t = Textbox(width, height, text, scroll=scroll ) @@ -119,10 +122,9 @@ def messagebox(screen, width, height, title, text, \ return bb.buttonPressed(g.runOnce()) def help(screen, size, config): - for fn in glob.glob(DOC+'*/help.txt'): - f=file(fn) - text=f.read() - f.close() + f=file(DOC+'/help.txt') + text=f.read() + f.close() text=text.replace("", getesckey(), 1) @@ -410,7 +412,7 @@ def defaultwindows(screen, size): def install(screen, size, isInstalled): if not isInstalled: - out = commands.getoutput("bash /usr/share/"+PKG+"/byobu-launcher-install") + out = commands.getoutput("byobu-launcher-install") if out == "": out = _("Byobu will be launched automatically next time you login.") @@ -418,7 +420,7 @@ def install(screen, size, isInstalled): buttons=((_("Menu"), ))) return 100 else: - out = commands.getoutput("bash /usr/share/"+PKG+"/byobu-launcher-uninstall") + out = commands.getoutput("byobu-launcher-uninstall") if out == "": out = _("Byobu will not be used next time you login.") diff --git a/byobu-export b/byobu-export index 6b1a6807..3761d720 100755 --- a/byobu-export +++ b/byobu-export @@ -17,20 +17,21 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +set -e + PKG="byobu" -SHARE="/usr/share/$PKG" DIR=`mktemp -t -d $PKG.XXXXXXXX` || error "Could not create a temporary directory" +[ -d "$TMP" ] || TMP=/tmp # Make sure we clean up $DIR if we exit for any reason -trap "rm -rf "$DIR" 2>/dev/null || true" EXIT HUP INT QUIT TERM +trap "rm -rf "$DIR" "$file" 2>/dev/null || true" EXIT HUP INT QUIT TERM usage() { echo echo "Usage:" echo " $0 [-f TARGET.tar.gz]" echo - echo "If TARGET.tar.gz is unspecified, a randomly generated" - echo "filename will be used." + echo "If TARGET.tar.gz is unspecified, $TMP/$PKG.tar.gz will be used." echo exit 1 } @@ -41,37 +42,6 @@ error() { exit 1 } -hr() { - echo "###############################################################################" -} - -header() { - hr - echo "# This GNU Screen profile was generated by the $PKG-export" - echo "# program, which is part of the $PKG package, and contains a" - echo "# subset of the functionality available from the full package." - echo "#" - echo "# For more information, source code, questions, and bugs, see:" - echo "# * https://launchpad.net/$PKG" - echo "#" - echo "# Copyright (C) 2008 Canonical Ltd." - echo "#" - echo "# Author: Dustin Kirkland " - echo "#" - echo "# This program is free software: you can redistribute it and/or modify" - echo "# it under the terms of the GNU General Public License as published by" - echo "# the Free Software Foundation, version 3 of the License." - echo "#" - echo "# This program is distributed in the hope that it will be useful," - echo "# but WITHOUT ANY WARRANTY; without even the implied warranty of" - echo "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" - echo "# GNU General Public License for more details." - echo "#" - echo "# You should have received a copy of the GNU General Public License" - echo "# along with this program. If not, see ." - hr -} - # Handle command line parameters file= while [ $# -gt 1 ]; do @@ -86,60 +56,50 @@ while [ $# -gt 1 ]; do esac done +# Handle filename [ $# -eq 1 ] && file="$1" - if [ -z "$file" ]; then - # Generate a temp archive filename - while true; do - file=`mktemp -t $PKG.XXXXXX` || error "Could not generate random filename" - if [ ! -e "$file.tar.gz" ]; then - mv -i "$file" "$file.tar.gz" - file="$file.tar.gz" - generated=1 - break - else - rm -f "$file" - fi - done -else - echo "$file" | grep -qs "\.tar\.gz$" || error "Target file must be a '.tar.gz' archive" - if [ -e "$file" ]; then - echo `gettext "File exists"` " [$file]" - echo -n "`gettext 'Remove file? [y/N] '`" - remove=`head -n1` - if [ "$remove" = "Y" -o "$remove" = "y" ]; then - rm -f "$file" - else - exit 1 - fi + file="$TMP/$PKG.tar.gz" +fi +echo "$file" | grep -qs "\.tar\.gz$" || error "Target file must be a '.tar.gz' archive" +if [ -e "$file" ]; then + echo `gettext "File exists"` " [$file]" + echo -n "`gettext 'Remove file? [y/N] '`" + remove=`head -n1` + if [ "$remove" = "Y" -o "$remove" = "y" ]; then + rm -f "$file" + else + exit 1 fi fi # Create workspace -PROFILE="$DIR/.byobu/profile" -STATUS="$DIR/.$PKG/status" -mkdir -p "$DIR/.$PKG/bin" +for i in etc usr/bin usr/lib usr/share/doc; do + mkdir -p "$DIR/.$PKG/$i/$PKG" +done dpkg-query --show --showformat '${Package} ${Version}\n' $PKG > "$DIR/.$PKG/version" 2>/dev/null || true echo "http://launchpad.net/$PKG" >> "$DIR/.$PKG/version" -header > "$PROFILE" printf "FOREGROUND=k\nBACKGROUND=W\n" > "$DIR/.$PKG/color" # Copy necessary scripts -cat /usr/share/byobu/profiles/common >> "$PROFILE" -cp -a /usr/share/byobu/keybindings/*-keys "$DIR/.$PKG" -cp -a /usr/lib/$PKG/* "$DIR/.$PKG/bin" -cp -a /usr/bin/$PKG-status "$DIR/.$PKG" -cp -a /usr/bin/$PKG-janitor "$DIR/.$PKG" -cp -a /usr/bin/$PKG-config "$DIR/.$PKG" -cat /etc/$PKG/statusrc > "$STATUS" +cp -a /etc/$PKG "$DIR/.$PKG/etc" +cp -a /usr/share/$PKG "$DIR/.$PKG/usr/share" +cp -a /usr/share/doc/$PKG "$DIR/.$PKG/usr/share/doc" +cp -a /usr/lib/$PKG "$DIR/.$PKG/usr/lib" +cp -a /usr/bin/$PKG-* "$DIR/.$PKG/usr/bin" +cp /etc/$PKG/statusrc "$DIR/.$PKG/status" echo "source \$HOME/.$PKG/profile" > "$DIR/.screenrc" +echo "source \$HOME/.$PKG/usr/share/$PKG/keybindings/common" > "$DIR/.$PKG/keybindings" +cd $DIR/.$PKG; ln -s usr/lib/$PKG bin; cd - +cd $DIR/.$PKG; ln -s usr/share/$PKG/profiles/common profile; cd - -# Some gardening -# Use the local byobu-config -sed -i "s:$PKG-config:\$HOME/.$PKG/$PKG-config:" "$DIR/.$PKG/"*-keys -sed -i "s:$PKG-status:\$HOME/.$PKG/$PKG-status:" "$PROFILE" -sed -i "s:$PKG-janitor:\$HOME/.$PKG/$PKG-janitor:" "$PROFILE" -cd "$DIR/.$PKG"; ln -s f-keys keybindings; cd - +# Some gardening; update paths to be $HOME-based +for i in $(ls /usr/bin/$PKG-* | grep -v "install"); do + bin=$(basename "$i") + sed -i "s:$bin:\$HOME/.$PKG$i:g" $(find $DIR -type f) +done +sed -i "s:/etc/\$PKG:\$HOME/.$PKG/etc/\$PKG:g" $(find $DIR -type f) +rm -f $DIR/.$PKG/usr/bin/$PKG-export # tar up the results tar --owner=root --group=root -zcf "$file" -C "$DIR" . || error "Could not create archive"