summarylogtreecommitdiffstats
path: root/suckless-rebuild
blob: 213a9a743aebf72290a442a54a2b23992907004f (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
#!/usr/bin/env bash

DESTDIR=~/.suckless
BUILDDIR=~/.suckless-build

usage() {
  echo "Usage: suckless-rebuild st <config.h>"
  exit 1
}

if [[ ${#@} != 2 || $1 =~ ^-h$|^--help$ || $2 =~ ^-h$|^--help$ ]]; then
  echo "Usage: suckless-rebuild st <config.h>"
  exit 1
fi

tool=$1
config=$2

if [[ ! $tool =~ ^st$ ]]; then
  echo "Unknown suckless tool '$tool'."
  exit 1
fi
if [[ ! -d /usr/src/$tool ]]; then
  echo "'an9wer-$tool' may not be installed."
  exit 1
fi
if [[ ! -f $config ]]; then
  echo "'$config' is not a regular file."
  exit 1
fi

if [[ -e $BUILDDIR/$tool ]]; then
  temp=$(mktemp -u -d /tmp/$tool.XXXXX)
  mv "$BUILDDIR/$tool" "$temp"
fi

mkdir -p "$BUILDDIR"
cp -r /usr/src/st "$BUILDDIR/$tool"
cp -f "$config" "$BUILDDIR/$tool"

cd "$BUILDDIR/$tool"
if make &> build.log && make PREFIX="$DESTDIR" install &> build.log; then
  echo "Done! Recommend to add '~/.suckless/bin' to \$PATH to use new builded st."
else
  echo "Some error occurred, check '$BUILDDIR/$tool/build.log' to find more."
fi
if [[ -v temp ]]; then
  sed -i "1i The last built directory was moved to $temp\n" build.log
fi

# vim: set filetype=sh: