Compare commits
5 Commits
c661ccd8eb
...
d321ec9761
Author | SHA1 | Date |
---|---|---|
Matteo Cypriani | d321ec9761 | |
Matteo Cypriani | 4147272b47 | |
Matteo Cypriani | 718768755c | |
Matteo Cypriani | 3fb819f430 | |
Matteo Cypriani | dbb0d6bf3a |
|
@ -43,11 +43,13 @@ compressed file to XZ (with default compression level).
|
||||||
|
|
||||||
Known compression formats are GZip (.gz), BZip2 (.bz2), LZMA (.lzma), and
|
Known compression formats are GZip (.gz), BZip2 (.bz2), LZMA (.lzma), and
|
||||||
Lempel-Ziv (.Z). Short tar compressed suffixes are also allowed: .tgz, .tbz,
|
Lempel-Ziv (.Z). Short tar compressed suffixes are also allowed: .tgz, .tbz,
|
||||||
.tb2, .tlz, .taz.
|
.tb2, .tlz, .taz (and the output file's extension will be .txz).
|
||||||
|
|
||||||
In case of recompression, the original compressed file is kept. In case of
|
In case of recompression, the original compressed file is kept (so you can
|
||||||
compression (i.e. when the suffix of the file does not correspond to a known
|
compare input and output file sizes and decide to keep the original or the
|
||||||
compression format), the original uncompressed file is removed.
|
recompressed file). In case of compression (i.e. when the suffix of the file
|
||||||
|
does not correspond to a known compression format), the original uncompressed
|
||||||
|
file is removed.
|
||||||
|
|
||||||
**Note**: the atool package provides the `arepack` command, which can
|
**Note**: the atool package provides the `arepack` command, which can
|
||||||
recompress to several formats and not only to XZ. `xzize` has the advantage to
|
recompress to several formats and not only to XZ. `xzize` has the advantage to
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# xzize.sh, Copyright © 2010 Matteo Cypriani
|
# xzize.sh, Copyright © 2010, 2019 Matteo Cypriani
|
||||||
#
|
#
|
||||||
# This program is free software. It comes without any warranty, to
|
# This program is free software. It comes without any warranty, to
|
||||||
# the extent permitted by applicable law. You can redistribute it
|
# the extent permitted by applicable law. You can redistribute it
|
||||||
|
@ -8,156 +8,159 @@
|
||||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||||
#
|
#
|
||||||
# This script recompresses to XZ (with maximum compression level) a
|
# This script recompresses to XZ one or several GZip (.gz, .tgz), BZip2 (.bz2,
|
||||||
# GZip (.gz, .tgz), BZip2 (.bz2, .tbz, .tb2), LZMA (.lzma, .tlz), and
|
# .tbz, .tb2), LZMA (.lzma, .tlz), or Lempel-Ziv (.Z, .taz) compressed file(s).
|
||||||
# Lempel-Ziv (.Z, .taz) compressed file. The original file is keeped.
|
# The original files are kept.
|
||||||
# If the file extension does not correspond to a known compression
|
#
|
||||||
# format, the file is compressed to XZ. In that case, the original
|
# If a file extension does not correspond to a known compression format, that
|
||||||
# file is removed.
|
# file is compressed to XZ. In that case, the original file is removed.
|
||||||
# If the file is already XZ compressed (.xz, .txz), nothing is done.
|
#
|
||||||
|
# If the file is already XZ-compressed (.xz, .txz), nothing is done.
|
||||||
|
|
||||||
|
#set -x
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
# Destination file suffix when source file name suffix is a
|
# Destination file suffix when source file name suffix is a
|
||||||
# 3-letter compressed tar suffix:
|
# 3-letter compressed tar suffix:
|
||||||
TAR_XZ_EXT=txz
|
readonly TAR_XZ_EXT=txz
|
||||||
|
|
||||||
# Default compression level:
|
# Default compression level:
|
||||||
COMPRESSION_LEVEL=
|
COMPRESSION_LEVEL=
|
||||||
|
|
||||||
test_extension()
|
test_extension()
|
||||||
{
|
{
|
||||||
FILE="$1"
|
FILE="$1"
|
||||||
EXTENSION="$2"
|
EXTENSION="$2"
|
||||||
NEWEXTENSION=xz
|
NEWEXTENSION=xz
|
||||||
if [ $# -eq 3 ] ; then
|
if [ $# -eq 3 ] ; then
|
||||||
NEWEXTENSION="$3"
|
NEWEXTENSION="$3"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BASE="$(basename "$FILE" ."$EXTENSION")"
|
BASE="$(echo "$FILE" | sed "s/\.${EXTENSION}//")"
|
||||||
if [ "$BASE" != "$FILE" ] ; then
|
if [ "$BASE" != "$FILE" ] ; then
|
||||||
DEST="$BASE".$NEWEXTENSION
|
DEST="$BASE".$NEWEXTENSION
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DEST="$FILE"
|
DEST="$FILE"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
do_recompress()
|
do_recompress()
|
||||||
{
|
{
|
||||||
if [ -e "$DEST" ] ; then
|
if [ -e "$DEST" ] ; then
|
||||||
echo "Skipping source file « $SOURCE »: destination file « $DEST » already exists!" >&2
|
echo "Skipping source file « $SOURCE »: destination file « $DEST » already exists!" >&2
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
echo "Recompressing « $SOURCE » to « $DEST »…"
|
echo "Recompressing « $SOURCE » to « $DEST »…"
|
||||||
$ACTION -c "$SOURCE" | xz $COMPRESSION_LEVEL >"$DEST"
|
$ACTION -c "$SOURCE" | xz $COMPRESSION_LEVEL >"$DEST"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## Verify number of arguments ##
|
## Verify number of arguments ##
|
||||||
|
|
||||||
if [ $# -lt 1 ] ; then
|
if [ $# -lt 1 ] ; then
|
||||||
echo "$0 requires at least one argument!" >&2
|
echo "$0 requires at least one argument!" >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
## Process files ##
|
## Process files ##
|
||||||
|
|
||||||
for SOURCE in "$@" ; do
|
for SOURCE in "$@" ; do
|
||||||
# Does source file exist?
|
# Does source file exist?
|
||||||
if [ ! -e "$SOURCE" ] ; then
|
if [ ! -e "$SOURCE" ] ; then
|
||||||
echo "Skipping source file « $SOURCE »: does not exist!" >&2
|
echo "Skipping source file « $SOURCE »: does not exist!" >&2
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Does source file is regular?
|
# Is source file regular?
|
||||||
if [ ! -f "$SOURCE" ] ; then
|
if [ ! -f "$SOURCE" ] ; then
|
||||||
echo "Skipping source file « $SOURCE »: is not a regular file!" >&2
|
echo "Skipping source file « $SOURCE »: is not a regular file!" >&2
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# GZip
|
# GZip
|
||||||
if test_extension "$SOURCE" gz ; then
|
if test_extension "$SOURCE" gz ; then
|
||||||
ACTION=gunzip
|
ACTION="gunzip"
|
||||||
do_recompress
|
do_recompress
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# GZipped Tar (.tgz)
|
# GZipped Tar (.tgz)
|
||||||
if test_extension "$SOURCE" tgz $TAR_XZ_EXT ; then
|
if test_extension "$SOURCE" tgz $TAR_XZ_EXT ; then
|
||||||
ACTION=gunzip
|
ACTION="gunzip"
|
||||||
do_recompress
|
do_recompress
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# BZip2
|
# BZip2
|
||||||
if test_extension "$SOURCE" bz2 ; then
|
if test_extension "$SOURCE" bz2 ; then
|
||||||
ACTION=bunzip2
|
ACTION="bunzip2"
|
||||||
do_recompress
|
do_recompress
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# BZipped Tar (.tbz)
|
# BZipped Tar (.tbz)
|
||||||
if test_extension "$SOURCE" tbz $TAR_XZ_EXT ; then
|
if test_extension "$SOURCE" tbz $TAR_XZ_EXT ; then
|
||||||
ACTION=bunzip2
|
ACTION="bunzip2"
|
||||||
do_recompress
|
do_recompress
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# BZipped Tar (.tb2)
|
# BZipped Tar (.tb2)
|
||||||
if test_extension "$SOURCE" tb2 $TAR_XZ_EXT ; then
|
if test_extension "$SOURCE" tb2 $TAR_XZ_EXT ; then
|
||||||
ACTION=bunzip2
|
ACTION="bunzip2"
|
||||||
do_recompress
|
do_recompress
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# LZMA
|
# LZMA
|
||||||
if test_extension "$SOURCE" lzma ; then
|
if test_extension "$SOURCE" lzma ; then
|
||||||
ACTION=unlzma
|
ACTION="unlzma"
|
||||||
do_recompress
|
do_recompress
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# LZMA compressed Tar (.tlz)
|
# LZMA compressed Tar (.tlz)
|
||||||
if test_extension "$SOURCE" tlz $TAR_XZ_EXT ; then
|
if test_extension "$SOURCE" tlz $TAR_XZ_EXT ; then
|
||||||
ACTION=unlzma
|
ACTION="unlzma"
|
||||||
do_recompress
|
do_recompress
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Compress
|
# Compress
|
||||||
if test_extension "$SOURCE" Z ; then
|
if test_extension "$SOURCE" Z ; then
|
||||||
ACTION=uncompress
|
ACTION="uncompress"
|
||||||
do_recompress
|
do_recompress
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Compressed Tar (.taz)
|
# Compressed Tar (.taz)
|
||||||
if test_extension "$SOURCE" taz $TAR_XZ_EXT ; then
|
if test_extension "$SOURCE" taz $TAR_XZ_EXT ; then
|
||||||
ACTION=uncompress
|
ACTION="uncompress"
|
||||||
do_recompress
|
do_recompress
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# XZ
|
# XZ
|
||||||
if test_extension "$SOURCE" xz ; then
|
if test_extension "$SOURCE" xz ; then
|
||||||
echo "Skipping source file « $DEST »: has already .xz suffix!" >&2
|
echo "Skipping source file « $DEST »: has already .xz suffix!" >&2
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# XZipped Tar (.txz)
|
# XZipped Tar (.txz)
|
||||||
if test_extension "$SOURCE" txz $TAR_XZ_EXT ; then
|
if test_extension "$SOURCE" txz $TAR_XZ_EXT ; then
|
||||||
echo "Skipping source file « $DEST »: seems to be a XZipped Tar archive (.txz suffix)!" >&2
|
echo "Skipping source file « $DEST »: seems to be a XZipped Tar archive (.txz suffix)!" >&2
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Uncompressed file: fall back to simple compression
|
# Uncompressed file: fall back to simple compression
|
||||||
echo "Compressing « $SOURCE » to xz…"
|
echo "Compressing « $SOURCE » to xz…"
|
||||||
xz $COMPRESSION_LEVEL "$SOURCE"
|
xz $COMPRESSION_LEVEL "$SOURCE"
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# tabssh.sh, Copyright © 2013 Matteo Cypriani <mcy@lm7.fr>
|
# tabssh.sh, Copyright © 2013, 2019 Matteo Cypriani <mcy@lm7.fr>
|
||||||
# (Formerly named cluster-ssh.sh)
|
# (Formerly named cluster-ssh.sh)
|
||||||
#
|
#
|
||||||
# This program is free software. It comes without any warranty, to
|
# This program is free software. It comes without any warranty, to
|
||||||
|
@ -56,9 +56,14 @@ elif [ $# -ne 1 ] ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check dependencies
|
# Check dependencies
|
||||||
SCREEN=$(command -v screen)
|
TMUX_CMD=$(command -v tmux)
|
||||||
if [ -z "$SCREEN" ] ; then
|
SCREEN_CMD=$(command -v screen)
|
||||||
err "GNU screen is required by this script."
|
if [ -n "$TMUX_CMD" ] ; then
|
||||||
|
echo "tmux is available, we'll be using it."
|
||||||
|
elif [ -n "$SCREEN_CMD" ] ; then
|
||||||
|
echo "tmux is not available, we'll be using GNU screen instead."
|
||||||
|
else
|
||||||
|
err "Either tmux or GNU screen is required by this script."
|
||||||
exit $EXIT_DEPENDENCY
|
exit $EXIT_DEPENDENCY
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -82,6 +87,10 @@ fi
|
||||||
# Create the screen tabs
|
# Create the screen tabs
|
||||||
while read -r HOST ; do
|
while read -r HOST ; do
|
||||||
SSH="ssh ${LOGIN}${HOST}"
|
SSH="ssh ${LOGIN}${HOST}"
|
||||||
# shellcheck disable=SC2086
|
if [ -n "$TMUX_CMD" ] ; then
|
||||||
$SCREEN -t "$SSH" $SSH
|
$TMUX_CMD new-window -d -n "$SSH" -- "$SSH"
|
||||||
|
else
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
$SCREEN_CMD -t "$SSH" $SSH
|
||||||
|
fi
|
||||||
done <"$HOSTS"
|
done <"$HOSTS"
|
||||||
|
|
Loading…
Reference in New Issue