* 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" PROG="screen-profiles"
SHARE="/usr/share/$PROG" 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 # Grab list of available colors
colors=`find $SHARE/profiles/ -type f | sed "s/^.*\///" | sed "s/^.*-//" | sort -u | egrep -v "common|plain"` 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 # Make sure we clean up $DIR if we exit for any reason
trap "rm -rf "$TMPDIR" 2>/dev/null || true" EXIT HUP INT QUIT TERM trap "rm -rf "$DIR" 2>/dev/null || true" EXIT HUP INT QUIT TERM
usage() { usage() {
echo echo
echo "Usage:" echo "Usage:"
echo " $0 [-c COLOR] -f TARGET.tar.gz" echo " $0 [-c COLOR] -f TARGET.tar.gz"
echo echo
echo "TARGET.tar.gz is required" echo "If TARGET.tar.gz is unspecified, a randomly generated"
echo "filename will be used."
echo echo
echo "COLOR is obtained interactively if unspecified; or one of:" echo "COLOR is obtained interactively if unspecified; or one of:"
for c in $colors; do for c in $colors; do
@ -43,6 +44,7 @@ usage() {
error() { error() {
echo "ERROR: $1" 1>&2 echo "ERROR: $1" 1>&2
[ "$generated" = "1" -a -f "$file" ] && rm -f "$file"
exit 1 exit 1
} }
@ -59,8 +61,7 @@ choose() {
count=1 count=1
while /bin/true; do while /bin/true; do
if [ $count -gt 5 ]; then if [ $count -gt 5 ]; then
echo `gettext "ERROR: Invalid selection"` error "Invalid selection"
exit 1
fi fi
count=`expr $count + 1` count=`expr $count + 1`
if ! test $selected -gt 0 2>/dev/null; then if ! test $selected -gt 0 2>/dev/null; then
@ -165,7 +166,20 @@ done
[ $# -eq 1 ] && file="$1" [ $# -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" echo "$file" | grep -qs "\.tar\.gz$" || error "Target file must be a '.tar.gz' archive"
if [ -e "$file" ]; then if [ -e "$file" ]; then
echo `gettext "File exists"` " [$file]" echo `gettext "File exists"` " [$file]"
@ -176,21 +190,20 @@ if [ -e "$file" ]; then
exit 1 exit 1
fi fi
fi fi
fi
# Obtain selections # Obtain selections
count=1 count=1
distro="ubuntu"
while /bin/true; do while /bin/true; do
if [ $count -gt 5 ]; then if [ $count -gt 5 ]; then
echo `gettext "ERROR: Invalid selection"` error "Invalid selection"
exit 1
fi fi
SOURCE="$SHARE"/profiles/"$distro"-"$color" SOURCE="$SHARE"/profiles/"$color"
if [ -f "$SOURCE" ]; then if [ -f "$SOURCE" ]; then
break break
else else
# Try in the misc directory too # Try in the misc directory too
SOURCE="$SHARE"/profiles/misc/"$distro"-"$color" SOURCE="$SHARE"/profiles/misc/"$color"
if [ -f "$SOURCE" ]; then if [ -f "$SOURCE" ]; then
break break
fi fi
@ -203,13 +216,13 @@ while /bin/true; do
done done
# Create workspace # Create workspace
PROFILE="$TMPDIR/.screenrc" PROFILE="$DIR/.screenrc"
STATUS="$TMPDIR/.$PROG/status" STATUS="$DIR/.$PROG/status"
mkdir -p "$TMPDIR/.$PROG/bin" mkdir -p "$DIR/.$PROG/bin"
# Copy status scripts # Copy status scripts
cp -a /var/lib/$PROG/* "$TMPDIR/.$PROG/bin" cp -a /var/lib/$PROG/* "$DIR/.$PROG/bin"
cp -a /usr/bin/$PROG-status "$TMPDIR/.$PROG" cp -a /usr/bin/$PROG-status "$DIR/.$PROG"
# Generate the monolithic profile # Generate the monolithic profile
header > "$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" sed -i "s:^bindkey -k k9 screen -t help:#bindkey -k k9 screen -t help:" "$PROFILE"
# tar up the results # 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
echo "Success!" echo "Success!"
echo echo
echo " "`gettext "Profile"` ": [$distro-$color]" echo " "`gettext "Profile"` ": [$color]"
echo " "`gettext "Archive"` ": [$file]" echo " "`gettext "Archive"` ": [$file]"
echo echo
echo `gettext "Extract the archive in your home directory on the target system."` 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. Optional parameter specifying the desired color scheme. If omitted, the program will interactively prompt for this value.
.TP .TP
.B \-f TARGET.tar.gz .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 .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). \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).