summarylogtreecommitdiffstats
path: root/wg++
blob: 9ea7f3a757b665c1ae564d0a3ee401772b38bf96 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash

# Webgrabber+Plus has never meant to be installed into Unix operating system. It
# was meant to be used as a folder, where user has RW access. The below script
# was needed in order to make it act like a proper application, installed into
# the operating system.
#
# http://www.webgrabplus.com/content/solved-command-line-option-specifying-config-file-name

CONFIG_DIR=~/wg++
EXECUTABLE=$(basename $0)

print_help () {
	echo -e "Usage:"
	echo -e "\t$EXECUTABLE - Uses default '$CONFIG_DIR' configuration directory. Will be created if missing."
	echo -e "\t$EXECUTABLE <path> - Path to configuration directory."
	echo -e "\t$EXECUTABLE --help - Show help screen."
	echo -e "\t"
	echo -e "Configuration template is stored in '/usr/share/wg++'. Copy it to your preferred location:"
	echo -e "\tcp -R /usr/share/wg++ /path/to/<configuration_directory>"
}

# Check if user supplied any arguments
if [ $# -eq 0 ]; then
	#### User did not provide any arguments to wg++ ####

	# Use default config dir "$CONFIG_DIR"
	if [ ! -d "$CONFIG_DIR" ]; then
		cp -R /usr/share/wg++ "$CONFIG_DIR"
		if [ -d "$CONFIG_DIR" ]; then
			echo "Configuration folder '$CONFIG_DIR' created! Run '$EXECUTABLE' again to use it."
			echo "For more information, see '$EXECUTABLE --help'."
			exit 0
		else
			echo "Failed to create configuration folder '$CONFIG_DIR'!"
			print_help
			exit 1
		fi
	fi

	# Check if "$CONFIG_DIR" contains configuration file
	if [ ! -f "$CONFIG_DIR/WebGrab++.config.xml" ]; then
		echo "Some configuration files are missing from '$CONFIG_DIR' directory!"
		print_help
		exit 1
	fi

	# Double check if user can read/write "$CONFIG_DIR"
	if [ ! -r "$CONFIG_DIR/WebGrab++.config.xml" ] || [ ! -w "$CONFIG_DIR/WebGrab++.config.xml" ]; then
		echo "You do not have read/write access in '$CONFIG_DIR'."
		print_help
		exit 1
	fi

	mono /opt/wg++/bin/WebGrab+Plus.exe "$CONFIG_DIR"
else
	#### User provided arguments to wg++ ####

	# Check if there is 1 argument. Exit if more
	if [ $# -ge 2 ]; then
		echo "Invalid path! You need to provide a path to WebGrabber+Plus configuration directory."
		print_help
		exit 1
	fi

	# Check if user asked for help
	if [ "$1" == "-h" ] || [ "$1" == "-H" ] || [ "$1" == "--help" ] || [ "$1" == "--HELP" ]; then
		print_help
		exit 0
	fi

	# Check if given parameter is existing directory
	if [ ! -d "$1" ]; then
		echo "Invalid path! You need to provide a path to WebGrabber+Plus configuration directory."
		print_help
		exit 1
	fi

	# Check if directory contains configuration file
	if [ ! -f "$1/WebGrab++.config.xml" ]; then
		echo "Wrong path! Your provided path does not contain configuration files."
		print_help
		exit 1
	fi

	# Check if user has read/write access to given path
	if [ ! -r "$1/WebGrab++.config.xml" ] || [ ! -w "$1/WebGrab++.config.xml" ]; then
		echo "You do not have read/write access to your given directory."
		print_help
		exit 1
	fi

	mono /opt/wg++/bin/WebGrab+Plus.exe "$1"
fi