screen-profiles-export: new script, for exporting a profile to systems

where screen-profiles are not installed
This commit is contained in:
Dustin Kirkland 2009-03-28 11:31:40 -05:00
commit 7966c0746a
2 changed files with 248 additions and 1 deletions

4
debian/changelog vendored
View file

@ -10,11 +10,13 @@ screen-profiles (1.41) unreleased; urgency=low
don't use fully qualified path for lsb_release as it seems this has moved
around (see Dapper)
* licenses updated to GPLv3 (dropped "or later" clause)
* screen-profiles-export: new script, for exporting a profile to systems
where screen-profiles are not installed
[ James Wilcox ]
* bin/updates-available: support SUSE's zypper
-- Dustin Kirkland <kirkland@ubuntu.com> Sat, 28 Mar 2009 09:55:36 -0500
-- Dustin Kirkland <kirkland@ubuntu.com> Sat, 28 Mar 2009 11:30:38 -0500
screen-profiles (1.40-0ubuntu1) jaunty; urgency=low

245
screen-profiles-export Executable file
View file

@ -0,0 +1,245 @@
#!/bin/sh -e
#
# screen-profile-export
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
#
# 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 <http://www.gnu.org/licenses/>.
# Inputs needed:
# target tarball (-f)
# .tar
# .tar.bz2
# .tar.gz
# selected profile
# choose distro (-d)
# choose light/dark (-i)
# choose color (-c)
PROG="screen-profiles"
SHARE="/usr/share/$PROG"
TMPDIR=`mktemp -d screen-profiles.XXXXXXXX` || error "Could not create a temporary directory"
# Make sure we clean up $TMPDIR if we exit for any reason
trap "rm -rf "$TMPDIR" 2>/dev/null || true" EXIT HUP INT QUIT TERM
usage() {
echo
echo "Usage:"
echo " $0 [-d DISTRO] [-c COLOR] -f TARGET.tar.gz"
echo
echo "DISTRO and COLOR are obtained interactively if unspecified."
echo "TARGET.tar.gz is required"
echo
exit 1
}
error() {
echo "ERROR: $1" 1>&2
exit 1
}
choose() {
i=0
x=
selected=
for x in $@; do
i=$(expr $i + 1)
[ $i -lt 10 ] && i=" $i"
echo " $i. $x" 1>&2
done
echo
count=1
while /bin/true; do
if [ $count -gt 5 ]; then
echo `gettext "ERROR: Invalid selection"`
exit 1
fi
count=`expr $count + 1`
if ! test $selected -gt 0 2>/dev/null; then
read -p "`gettext 'Choose'` [1 -$i]: " -r selected
elif ! test $selected -le $i 2>/dev/null; then
read -p "`gettext 'Choose'` [1 -$i]: " -r selected
else
break
fi
done
i=0
for x in $@; do
i=$(expr $i + 1)
if [ "$i" = "$selected" ]; then
SELECTED="$x"
return 0
fi
done
exit 1
}
status_config() {
# Generate the status configuration
# Disable the menu, since screen-profiles configurator is not available
echo "
arch=0
cpu-count=1
cpu-freq=1
ec2-cost=0
hostname=1
load-average=1
mem-available=1
mem-used=1
menu=0
reboot-required=1
release=1
updates-available=1
whoami=1"
}
hr() {
echo "###############################################################################"
}
header() {
hr
echo "# This GNU Screen profile was generated by the screen-profile-export"
echo "# program, which is part of the screen-profiles 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/screen-profiles"
echo "#"
echo "# Copyright (C) 2008 Canonical Ltd."
echo "#"
echo "# Author: Dustin Kirkland <kirkland@canonical.com>"
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 <http://www.gnu.org/licenses/>."
hr
}
sources() {
# insert the common profile, replace the /var/lib exe path
echo
cat $SHARE/profiles/common | sed "s:/var/lib/$PROG/:\$HOME/.$PROG/bin/:"
hr
echo
cat $SHARE/keybindings/common
hr
echo
hr
cat "$SOURCE"
hr
}
# Handle command line parameters
distro=
color=
file=
while [ $# -gt 1 ]; do
case "$1" in
-d)
distro="$2"
shift 2
;;
-c)
color="$2"
shift 2
;;
-f)
file="$2"
shift 2
;;
*)
usage
;;
esac
done
[ -z "$file" ] && usage
[ -e "$file" -o -e "$file.tar.gz" ] && error "File exists, please remove before running [$file]"
file=`echo "$file" | sed "s:\.tar.*$::"`
file="$file".tar.gz
# Grab list of available distros and colors
distros=`find $SHARE/profiles/ -type f | xargs -i basename {} | sed "s/-.*$//" | sort -u | grep -v "common" | grep -v "plain"`
colors=`find $SHARE/profiles/ -type f | sed "s/^.*\///" | sed "s/^.*-//" | sort -u | egrep -v "common|plain"`
# Obtain selections
count=1
while /bin/true; do
if [ $count -gt 5 ]; then
echo `gettext "ERROR: Invalid selection"`
exit 1
fi
SOURCE="$SHARE"/profiles/"$distro"-"$color"
if [ -f "$SOURCE" ]; then
break
else
# Try in the misc directory too
SOURCE="$SHARE"/profiles/misc/"$distro"-"$color"
if [ -f "$SOURCE" ]; then
break
fi
fi
echo
echo `gettext "Select a distro: "`
choose $distros
distro=$SELECTED
echo
echo `gettext "Select a color: "`
choose $colors
color=$SELECTED
count=`expr $count + 1`
done
# Create workspace
PROFILE="$TMPDIR/.screenrc"
STATUS="$TMPDIR/.$PROG/status"
mkdir -p "$TMPDIR/.$PROG/bin"
# Copy status scripts
cp -a /var/lib/$PROG/* "$TMPDIR/.$PROG/bin"
# Generate the monolithic profile
header > "$PROFILE"
sources >> "$PROFILE"
# Some gardening
# Drop additional "source" calls
sed -i "s:^source .*::" "$PROFILE"
# Use .screenrc instead
sed -i "s:.$PROG/profile\":\.screenrc\":" "$PROFILE"
# Drop the F9->Menu key
sed -i "s:^bindkey -k k9 screen -t help:#bindkey -k k9 screen -t help:" "$PROFILE"
# tar up the results
tar -zcf "$file" -C "$TMPDIR" . || error "Could not create archive"
echo
echo "Success!"
echo
echo `gettext "Profile"` ": [$distro-$color]"
echo `gettext "Archive"` ": [$file]"
echo `gettext "Extract this archive in your home directory on the target system."`
echo