make: added a makefile for proper installation

This commit is contained in:
Jesse Bryan 2017-09-04 05:55:30 -05:00
parent 12e48cc3f2
commit 3c8167cb2d
3 changed files with 61 additions and 27 deletions

26
Makefile Normal file
View file

@ -0,0 +1,26 @@
PREFIX ?= /usr
MANDIR ?= $(PREFIX)/share/man
SYSCONFDIR ?= /etc
all:
@echo "Run 'make install' to install gsu."
install:
@echo "Making directories..."
mkdir -p $(DESTDIR)$(PREFIX)/bin
mkdir -p $(DESTDIR)$(MANDIR)/man1
mkdir -p $(DESTDIR)$(SYSCONFDIR)/gsu
@echo -e "\nInstalling binaries..."
sed "s|SYSCONFDIR|$(SYSCONFDIR)/gsu|g" < gsu > $(DESTDIR)$(PREFIX)/bin/gsu
chmod 755 $(DESTDIR)$(PREFIX)/bin/gsu
@echo -e "\nInstalling man page and config file..."
cp -p gsu.1 $(DESTDIR)$(MANDIR)/man1/gsu.1
cp -p config/config.conf $(DESTDIR)$(SYSCONFDIR)/gsu/config.conf
uninstall:
@echo "Removing files..."
rm -rf $(DESTDIR)$(PREFIX)/bin/gsu
rm -rf $(DESTDIR)$(MANDIR)/man1/gsu.1
rm -rf $(DESTDIR)$(SYSCONFDIR)/gsu

42
gsu
View file

@ -13,14 +13,12 @@ GENERAL OPTIONS
-v, --version Show the current version
-u, --upload Upload after running the utility
-n, --nocursor Hide the cursor
-s, --screenshot Take a screenshot
-v, --video Record a video of the screen
-m, --video Record a video of the screen
-g, --gif Record a video and convert it to the gif format
SCREENSHOT OPTIONS
-n, --nocursor Hide the cursor (screenshot only)
VIDEO OPTIONS
-c, --countdown NUM Countdown before recording"
@ -32,6 +30,13 @@ print_version() {
exit 0
}
print_not_int() {
regex=$(echo "$1" | sed -e "s/^-\{1,2\}//")
echo "gsu: value for '$regex' is not an integer"
exit 1
}
print_invalid_option() {
regex=$(echo "$1" | sed -e "s/^-\{1,2\}//")
@ -65,15 +70,19 @@ get_args() {
case "$1" in
"-h" | "--help") print_help ;;
"-v" | "--version") print_version ;;
"-u" | "--upload") upload="$1" ;;
"-s" | "--screenshot") set_type "screenshot" ;;
"-v" | "--video") set_type "video" ;;
"-m" | "--video") set_type "video" ;;
"-g" | "--gif") set_type "gif" ;;
"-n" | "--nocursor") nocursor="-u"; draw_mouse="-draw_mouse 0" ;;
"-n" | "--nocursor") nocursor="-u" ;;
"-c" | "--countdown") countdown_enable="$2" ;;
"-c" | "--countdown")
if ! [[ $2 =~ ^[0-9]+$ ]]; then
print_not_int "$1"
fi
countdown_enable="$2"
;;
-*) print_invalid_option "$1" ;;
@ -95,15 +104,18 @@ get_args() {
get_config() {
mkdir -p "$config_path"
if [[ -f "$config_path/config.conf" ]]; then
source "$config_path/config.conf"
if [[ ! -f "$config_path/config.conf" ]]; then
if [[ -f "SYSCONFDIR/config.conf" ]]; then
cp "SYSCONFDIR/config.conf" "$config_path"
elif [[ -f "config/config.conf" ]]; then
cp "config/config.conf" "$config_path"
source "$config_path/config.conf"
else
echo "gsu: unable to find the config file"
exit 1
fi
fi
source "$config_path/config.conf"
}
set_type() {
@ -171,15 +183,13 @@ take_video() {
print_manually_quit
fi
echo "Press [q] or [Ctrl+C] to stop recording."
if [[ ! -z "$countdown_enable" ]]; then
countdown "$countdown_enable" "Handing control over to ffmpeg in COUNTNUM seconds."
fi
echo "Recording..."
echo "Press [q] or [Ctrl+C] to stop recording."
local cmd=$(ffmpeg -y -f alsa -i pulse -r 30 -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -c:v libx264 -crf 18 -preset:v ultrafast -c:a aac -b:a 192k -loglevel error "$output" 2>&1>/dev/null)
local cmd=$(ffmpeg -y -f alsa -i pulse -r 30 -f x11grab $draw_mouse -s "$W"x"$H" -i :0.0+$X,$Y -c:v libx264 -crf 18 -preset:v ultrafast -c:a aac -b:a 192k -loglevel error "$output" 2>&1>/dev/null)
if [[ -z "$cmd" ]]; then
echo "Stopped recording."

10
gsu.1
View file

@ -19,20 +19,18 @@ Show the current version
\fB\-u\fR, \fB\-\-upload\fR
Upload after running the utility
.TP
\fB\-n\fR, \fB\-\-nocursor\fR
Hide the cursor
.TP
\fB\-s\fR, \fB\-\-screenshot\fR
Take a screenshot
.TP
\fB\-v\fR, \fB\-\-video\fR
\fB\-m\fR, \fB\-\-video\fR
Record a video of the screen
.TP
\fB\-g\fR, \fB\-\-gif\fR
Record a video and convert it to the gif format
.PP
SCREENSHOT OPTIONS
.TP
\fB\-n\fR, \fB\-\-nocursor\fR
Hide the cursor (screenshot only)
.PP
VIDEO OPTIONS
.TP
\fB\-c\fR, \fB\-\-countdown\fR NUM