aboutsummaryrefslogtreecommitdiff
path: root/sbrename
blob: 9031674c10cf546540c4ad9b91430783a51cda78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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