diff options
Diffstat (limited to 'sbrename')
-rwxr-xr-x | sbrename | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/sbrename b/sbrename new file mode 100755 index 0000000..9031674 --- /dev/null +++ b/sbrename @@ -0,0 +1,73 @@ +#!/bin/bash + +NAME=$( echo "$0" | sed 's,.*/,,' ) + +# Trim trailing slash from SRC and DEST, if present +SRC="$( echo "$1" | sed 's,/$,,' )" +DEST="$( echo "$2" | sed 's,/$,,' )" + +if [ ! -d "$SRC" ]; then + if [ -e "$SRC" ]; then + echo "$NAME: $SRC is not a directory" + else + echo "$NAME: $SRC not found or can't access" + fi + SRC="" +fi + +if [ "$SRC" = "" -o "$DEST" = "" ]; then + cat <<EOF +$NAME - rename a SlackBuild + +Usage: $NAME slackbuild_dir new_name + +slackbuild_dir must be a directory containing at least a SlackBuild +script, named after the directory (e.g. directory foo must contain +foo.SlackBuild). It may also contain a README, .info file, and/or +slack-desc. All these files that exist will be updated, replacing the +old name with the new, and the directory will be renamed to the new name +as well. + +The original directory's contents will be saved to slackbuild_dir.bak +rather than being deleted, in case anything goes wrong. + +The renamed files will probably need some editing before they can be +used. In particular, the commands to extract the source and cd into the +source directory will be using the new name (which won't work with the +old source). +EOF + exit 1 +fi + +if [ -e "$DEST" ]; then + echo "$NAME: $DEST already exists" + exit 1 +fi + +set -e + +cp -a "$SRC" "$DEST" +mv "$SRC" "$SRC.bak" + +cd "$DEST" + +if [ -e "$SRC.SlackBuild" ]; then + sed "/^ *P[RK]GNAM=/s,$SRC,$DEST," "$SRC.SlackBuild" > "$DEST.SlackBuild" + rm -f "$SRC.SlackBuild" + chmod 755 "$DEST.SlackBuild" +fi + +if [ -e slack-desc ]; then + sed -i "s,^$SRC,$DEST," slack-desc + newindent="$(echo $DEST|sed 's,., ,g')" + sed -i "s,^ *\(|--*handy.*\),$newindent\1," slack-desc +fi + +if [ -e README ]; then + sed -i "s,$SRC,$DEST,g" README +fi + +if [ -e "$SRC.info" ]; then + sed "/^PRGNAM=/s,$SRC,$DEST," "$SRC.info" > "$DEST.info" + rm -f "$SRC.info" +fi |