* screen-profiles-export: randomly generate tarball name, if unspecified

Signed-off-by: Dustin Kirkland <kirkland@canonical.com>
This commit is contained in:
Dustin Kirkland 2009-04-21 16:18:01 -05:00
commit 84c8547485
2 changed files with 41 additions and 28 deletions

View file

@ -19,19 +19,20 @@
PROG="screen-profiles"
SHARE="/usr/share/$PROG"
TMPDIR=`mktemp -d screen-profiles.XXXXXXXX` || error "Could not create a temporary directory"
DIR=`mktemp -t -d screen-profiles.XXXXXXXX` || error "Could not create a temporary directory"
# Grab list of available colors
colors=`find $SHARE/profiles/ -type f | sed "s/^.*\///" | sed "s/^.*-//" | sort -u | egrep -v "common|plain"`
# 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
# 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
usage() {
echo
echo "Usage:"
echo " $0 [-c COLOR] -f TARGET.tar.gz"
echo
echo "TARGET.tar.gz is required"
echo "If TARGET.tar.gz is unspecified, a randomly generated"
echo "filename will be used."
echo
echo "COLOR is obtained interactively if unspecified; or one of:"
for c in $colors; do
@ -43,6 +44,7 @@ usage() {
error() {
echo "ERROR: $1" 1>&2
[ "$generated" = "1" -a -f "$file" ] && rm -f "$file"
exit 1
}
@ -59,8 +61,7 @@ choose() {
count=1
while /bin/true; do
if [ $count -gt 5 ]; then
echo `gettext "ERROR: Invalid selection"`
exit 1
error "Invalid selection"
fi
count=`expr $count + 1`
if ! test $selected -gt 0 2>/dev/null; then
@ -165,7 +166,20 @@ done
[ $# -eq 1 ] && file="$1"
[ -z "$file" ] && usage
if [ -z "$file" ]; then
# Generate a temp archive filename
while true; do
file=`mktemp -t screen-profiles.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]"
@ -176,21 +190,20 @@ if [ -e "$file" ]; then
exit 1
fi
fi
fi
# Obtain selections
count=1
distro="ubuntu"
while /bin/true; do
if [ $count -gt 5 ]; then
echo `gettext "ERROR: Invalid selection"`
exit 1
error "Invalid selection"
fi
SOURCE="$SHARE"/profiles/"$distro"-"$color"
SOURCE="$SHARE"/profiles/"$color"
if [ -f "$SOURCE" ]; then
break
else
# Try in the misc directory too
SOURCE="$SHARE"/profiles/misc/"$distro"-"$color"
SOURCE="$SHARE"/profiles/misc/"$color"
if [ -f "$SOURCE" ]; then
break
fi
@ -203,13 +216,13 @@ while /bin/true; do
done
# Create workspace
PROFILE="$TMPDIR/.screenrc"
STATUS="$TMPDIR/.$PROG/status"
mkdir -p "$TMPDIR/.$PROG/bin"
PROFILE="$DIR/.screenrc"
STATUS="$DIR/.$PROG/status"
mkdir -p "$DIR/.$PROG/bin"
# Copy status scripts
cp -a /var/lib/$PROG/* "$TMPDIR/.$PROG/bin"
cp -a /usr/bin/$PROG-status "$TMPDIR/.$PROG"
cp -a /var/lib/$PROG/* "$DIR/.$PROG/bin"
cp -a /usr/bin/$PROG-status "$DIR/.$PROG"
# Generate the monolithic profile
header > "$PROFILE"
@ -225,12 +238,12 @@ sed -i "s:.$PROG/profile\":\.screenrc\":" "$PROFILE"
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"
tar -zcf "$file" -C "$DIR" . || error "Could not create archive"
echo
echo "Success!"
echo
echo " "`gettext "Profile"` ": [$distro-$color]"
echo " "`gettext "Profile"` ": [$color]"
echo " "`gettext "Archive"` ": [$file]"
echo
echo `gettext "Extract the archive in your home directory on the target system."`

View file

@ -11,7 +11,7 @@ screen\-profiles\-export \- create a screen-profiles archive for export
Optional parameter specifying the desired color scheme. If omitted, the program will interactively prompt for this value.
.TP
.B \-f TARGET.tar.gz
Required parameter for the target file to contain the output archive.
If TARGET.tar.gz is unspecified, a randomly generated filename will be used.
.SH DESCRIPTION
\fBscreen\-profiles\-export\fP is a program that creates a monolithic .screenrc profile, and copies the status notification scripts into an archive file. This archive can then be extracted on a target system where \fBscreen\-profiles\fP is not installed (perhaps because the program is not packaged for that distribution, or perhaps because the administrator has not installed the package).