-
Notifications
You must be signed in to change notification settings - Fork 1
/
tarmk
executable file
·48 lines (44 loc) · 1.08 KB
/
tarmk
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
#!/bin/sh
#
# NAME
#
# tarmk - extract tarballs and run make
#
# SYNOPSIS
#
# tarmk [-m] <file> [<arg>...]
#
# OPTIONS
#
# -m, --makefile-only extract only the makefile
#
# DESCRIPTION
#
# tarmk is a simple script to extract tarballs containing a makefile
# into a temporary directory and run make with optional arguments.
# This way, tarmk functions as a rudimentary package installer, e.g.,
# to install sic (a simple IRC client), one could do
#
# $ wget https://dl.suckless.org/tools/sic-1.2.tar.gz
# $ tarmk sic-1.2.tar.gz install
#
# DEPENDENCIES
#
# mktemp(1) and tar(1)
#
set -e
exdir=$(mktemp -d)
trap 'cd / && rm -rf "$exdir" >/dev/null 2>&1' EXIT
trap 'exit 2' HUP INT QUIT TERM
case "$1" in
-m|--makefile-only)
shift; path="$(tar -tf "$1" | grep -i makefile | head -n 1)"
tar -C "$exdir" -xvf "$1" "$path" ;;
-*|"")
echo >&2 "usage: ${0##*/} [-m] <file> [<arg>...]"
exit 1 ;;
*)
tar -C "$exdir" -xvf "$1" ;;
esac
makefile=$(find "$exdir" -type f -iname 'makefile' -print -quit)
shift; cd "${makefile%/*}" && make "$@"