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

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

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

if [[ ${#@} != 2 || $1 =~ ^-h$|^--help$ || $2 =~ ^-h$|^--help$ ]]; then
  usage
fi

software=$1
config=$2

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

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

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

cd "$BUILDDIR/$software"
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/$software/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: