Skip to content

Commit

Permalink
allow changing webroot in configure step (closes #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nunzio Tocci committed Feb 10, 2018
1 parent 9cb01f1 commit bb3e149
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 57 deletions.
90 changes: 48 additions & 42 deletions src/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
BINARY = pgmanage
CONFIGS = -c config/pgmanage.conf -d config/pgmanage-connections-test.conf -n true -t 300
WEBROOTS = -r ./web_root
INSTALL_DEPS = @prefix@/sbin/ @prefix@/etc/$(BINARY)/ @prefix@/etc/pgmanage/pgmanage.conf @prefix@/etc/pgmanage/pgmanage-connections.conf
TEST_CONFIGS = -c config/pgmanage.conf -d config/pgmanage-connections-test.conf -n true -t 300
TEST_WEBROOTS = -r ./web_root
PREFIX = @prefix@
WEBROOT = @webroot@
INSTALL_DEPS = $(PREFIX)/sbin/ \
$(PREFIX)/etc/pgmanage/ \
$(PREFIX)/etc/pgmanage/pgmanage.conf \
$(PREFIX)/etc/pgmanage/pgmanage-connections.conf
SOCK_DIR_PARAMETER = @sock_dir_parameter@

VERSION = \"$(shell cat ../VERSION)\"
Expand All @@ -10,8 +14,12 @@ CFLAGS = -O3 -g \
-fno-strict-aliasing
LDFLAGS = @LDFLAGS@
CPPFLAGS = @CPPFLAGS@ \
-I../db_framework_pq -I../ -I. -I../dependencies/tre/include -I../dependencies/libev \
-DVERSION=$(VERSION) -DPGMANAGE_PREFIX=\"@prefix@\"
-I../db_framework_pq \
-I../ \
-I. \
-I../dependencies/tre/include \
-I../dependencies/libev \
-DVERSION=$(VERSION) -DPGMANAGE_PREFIX=\"$(PREFIX)\"
V=0

common_SOURCES = $(filter-out util_getopt.c, $(filter-out util_strptime.c, $(wildcard *.c)))
Expand All @@ -20,15 +28,13 @@ db_framework_pq_SOURCES = $(wildcard ../db_framework_pq/*.c)
pgmanage_SOURCES = $(sort $(common_SOURCES) $(db_framework_pq_SOURCES))
pgmanage_OBJECTS = $(pgmanage_SOURCES:.c=.o)



libev_SOURCES = ../dependencies/libev/ev.c
libev_OBJECTS = $(libev_SOURCES:.c=.o)

.PHONY: all all-format destroy check

# this needs to be at the top to be the default target
all: $(BINARY)
all: pgmanage
@echo
@echo "Compilation Successful"

Expand All @@ -42,16 +48,16 @@ else
endif

#### BUILDING
$(BINARY): $(libev_OBJECTS) $(pgmanage_OBJECTS)
pgmanage: $(libev_OBJECTS) $(pgmanage_OBJECTS)
ifeq ($(V), 1)
$(CC) $(libev_OBJECTS) $(pgmanage_OBJECTS) $(LDFLAGS) $(CFLAGS) -o ./$(BINARY)
$(CC) $(libev_OBJECTS) $(pgmanage_OBJECTS) $(LDFLAGS) $(CFLAGS) -o ./pgmanage
else
@echo " CCLD $(BINARY)"
@$(CC) $(libev_OBJECTS) $(pgmanage_OBJECTS) $(LDFLAGS) $(CFLAGS) -o ./$(BINARY)
@echo " CCLD pgmanage"
@$(CC) $(libev_OBJECTS) $(pgmanage_OBJECTS) $(LDFLAGS) $(CFLAGS) -o ./pgmanage
endif

all-format:
cd ..; ./cleanup_format.sh; cd $(BINARY)
cd ..; ./cleanup_format.sh; cd pgmanage
$(MAKE) all

$(pgmanage_OBJECTS): %.o: %.c
Expand All @@ -64,43 +70,43 @@ endif

#### CLEAN
clean:
rm -f $(pgmanage_OBJECTS) $(libev_OBJECTS) ../check/*.o $(BINARY)
rm -f $(pgmanage_OBJECTS) $(libev_OBJECTS) ../check/*.o pgmanage
@echo
@echo "Clean Successful"

#### INSTALL
@prefix@/sbin/:
mkdir -p @prefix@/sbin/
$(PREFIX)/sbin/:
mkdir -p $(PREFIX)/sbin/

@prefix@/etc/$(BINARY)/:
mkdir -p @prefix@/etc/$(BINARY)/
$(PREFIX)/etc/pgmanage/:
mkdir -p $(PREFIX)/etc/pgmanage/

@prefix@/etc/$(BINARY)/$(BINARY).conf: @prefix@/etc/$(BINARY)/ config/$(BINARY).conf
test -f @prefix@/etc/$(BINARY)/$(BINARY).conf || install config/$(BINARY).conf @prefix@/etc/$(BINARY)/$(BINARY).conf;
$(PREFIX)/etc/pgmanage/pgmanage.conf: $(PREFIX)/etc/pgmanage/ config/pgmanage.conf
test -f $(PREFIX)/etc/pgmanage/pgmanage.conf || install config/pgmanage.conf $(PREFIX)/etc/pgmanage/pgmanage.conf;

@prefix@/etc/$(BINARY)/$(BINARY)-connections.conf: @prefix@/etc/$(BINARY)/ config/$(BINARY)-connections.conf
test -f @prefix@/etc/$(BINARY)/$(BINARY)-connections.conf || install config/$(BINARY)-connections.conf @prefix@/etc/$(BINARY)/$(BINARY)-connections.conf;
$(PREFIX)/etc/pgmanage/pgmanage-connections.conf: $(PREFIX)/etc/pgmanage/ config/pgmanage-connections.conf
test -f $(PREFIX)/etc/pgmanage/pgmanage-connections.conf || install config/pgmanage-connections.conf $(PREFIX)/etc/pgmanage/pgmanage-connections.conf;

install: $(INSTALL_DEPS)
mkdir -p @prefix@/etc/$(BINARY)/web_root/$(BINARY) @prefix@/sbin @prefix@/@MANDIR@/man1
cp -rf ./web_root/$(BINARY)/* @prefix@/etc/$(BINARY)/web_root/$(BINARY)/
install config/$(BINARY).conf @prefix@/etc/$(BINARY)/$(BINARY).conf.example
install config/$(BINARY)-connections.conf @prefix@/etc/$(BINARY)/$(BINARY)-connections.conf.example
install $(BINARY) @prefix@/sbin/
install man/man1/pgmanage.1 @prefix@/@MANDIR@/man1/pgmanage.1
mkdir -p $(WEBROOT)/pgmanage $(PREFIX)/sbin $(PREFIX)/@MANDIR@/man1
cp -rf ./web_root/pgmanage/* $(WEBROOT)/pgmanage/
install config/pgmanage.conf $(PREFIX)/etc/pgmanage/pgmanage.conf.example
install config/pgmanage-connections.conf $(PREFIX)/etc/pgmanage/pgmanage-connections.conf.example
install pgmanage $(PREFIX)/sbin/
install man/man1/pgmanage.1 $(PREFIX)/@MANDIR@/man1/pgmanage.1
@echo
@echo "Installation Successful"

uninstall:
rm @prefix@/sbin/$(BINARY)
rm -rf @prefix@/etc/$(BINARY)/web_root/
rm -rf @prefix@/etc/$(BINARY)/*.example
rm $(PREFIX)/sbin/pgmanage
rm -rf $(WEBROOT)/
rm -rf $(PREFIX)/etc/pgmanage/*.example
@echo
@echo "Uninstall Successful"

destroy:
rm @prefix@/sbin/$(BINARY)
rm -rf @prefix@/etc/$(BINARY)
rm $(PREFIX)/sbin/pgmanage
rm -rf $(PREFIX)/etc/pgmanage
@echo
@echo "Destroy Successful"
@echo "NOTE: Even though all configuration files have been destroyed, your sql files have been preserved. They should be in you home folder under .pgmanage"
Expand Down Expand Up @@ -137,41 +143,41 @@ test-common:
sleep 3

test: test-common
./$(BINARY) $(CONFIGS) $(WEBROOTS) -d config/pgmanage-connections-test.conf -l info || \
./pgmanage $(TEST_CONFIGS) $(TEST_WEBROOTS) -d config/pgmanage-connections-test.conf -l info || \
{ kill `cat postgres.pid`; rm postgres.pid; rm -rf data_test; exit 1; }

test-ssl: test-common
./$(BINARY) $(CONFIGS) $(WEBROOTS) -d config/pgmanage-connections-test.conf -j ../ssl/self.crt -k ../ssl/self.key -l info || \
./pgmanage $(TEST_CONFIGS) $(TEST_WEBROOTS) -d config/pgmanage-connections-test.conf -j ../ssl/self.crt -k ../ssl/self.key -l info || \
{ kill `cat postgres.pid`; rm postgres.pid; rm -rf data_test; exit 1; }

gdb: test-common
echo "run" > temp_gdb_commands
gdb -x temp_gdb_commands --args ./$(BINARY) $(CONFIGS) $(WEBROOTS) -d config/pgmanage-connections-test.conf -l info || \
gdb -x temp_gdb_commands --args ./pgmanage $(TEST_CONFIGS) $(TEST_WEBROOTS) -d config/pgmanage-connections-test.conf -l info || \
{ kill `cat postgres.pid`; rm postgres.pid; rm -rf data_test; exit 1; }
rm temp_gdb_commands

gdb-ssl: test-common
echo "run" > temp_gdb_commands
gdb -x temp_gdb_commands --args ./$(BINARY) $(CONFIGS) $(WEBROOTS) -d config/pgmanage-connections-test.conf -j ../ssl/self.crt -k ../ssl/self.key -l info || \
gdb -x temp_gdb_commands --args ./pgmanage $(TEST_CONFIGS) $(TEST_WEBROOTS) -d config/pgmanage-connections-test.conf -j ../ssl/self.crt -k ../ssl/self.key -l info || \
{ kill `cat postgres.pid`; rm postgres.pid; rm -rf data_test; exit 1; }
rm temp_gdb_commands

lldb: test-common
echo "run" > temp_lldb_commands
lldb -s temp_lldb_commands -- ./$(BINARY) $(CONFIGS) $(WEBROOTS) -d config/pgmanage-connections-test.conf -l info || \
lldb -s temp_lldb_commands -- ./pgmanage $(TEST_CONFIGS) $(TEST_WEBROOTS) -d config/pgmanage-connections-test.conf -l info || \
{ kill `cat postgres.pid`; rm postgres.pid; rm -rf data_test; exit 1; }
rm temp_lldb_commands

lldb-ssl: test-common
echo "run" > temp_lldb_commands
lldb -s temp_lldb_commands -- ./$(BINARY) $(CONFIGS) $(WEBROOTS) -d config/pgmanage-connections-test.conf -j ../ssl/self.crt -k ../ssl/self.key -l info || \
lldb -s temp_lldb_commands -- ./pgmanage $(TEST_CONFIGS) $(TEST_WEBROOTS) -d config/pgmanage-connections-test.conf -j ../ssl/self.crt -k ../ssl/self.key -l info || \
{ kill `cat postgres.pid`; rm postgres.pid; rm -rf data_test; exit 1; }
rm temp_lldb_commands

valgrind: test-common
valgrind --leak-check=full --track-fds=yes --track-origins=yes --show-reachable=yes --suppressions=../valgrind/mac_suppressions.txt --num-callers=100 ./$(BINARY) $(CONFIGS) $(WEBROOTS) -d config/pgmanage-connections-test.conf -l none || \
valgrind --leak-check=full --track-fds=yes --track-origins=yes --show-reachable=yes --suppressions=../valgrind/mac_suppressions.txt --num-callers=100 ./pgmanage $(TEST_CONFIGS) $(TEST_WEBROOTS) -d config/pgmanage-connections-test.conf -l none || \
{ kill `cat postgres.pid`; rm postgres.pid; rm -rf data_test; exit 1; }

valgrind-ssl: test-common
valgrind --leak-check=full --track-fds=yes --track-origins=yes --show-reachable=yes --suppressions=../valgrind/mac_suppressions.txt --num-callers=100 ./$(BINARY) $(CONFIGS) $(WEBROOTS) -d config/pgmanage-connections-test.conf -j ../ssl/self.crt -k ../ssl/self.key -l none || \
valgrind --leak-check=full --track-fds=yes --track-origins=yes --show-reachable=yes --suppressions=../valgrind/mac_suppressions.txt --num-callers=100 ./pgmanage $(TEST_CONFIGS) $(TEST_WEBROOTS) -d config/pgmanage-connections-test.conf -j ../ssl/self.crt -k ../ssl/self.key -l none || \
{ kill `cat postgres.pid`; rm postgres.pid; rm -rf data_test; exit 1; }
2 changes: 1 addition & 1 deletion src/common_websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void WS_readFrame_step2(EV_P, ev_io *w, int revents) {
if (int_avail < WEBSOCKET_HEADER_LENGTH) {
bol_error_state = false;
SFREE(buf);
client_message->int_ioctl_count += 1;
client_message->int_ioctl_count += (uint8_t)1;
if (client_message->int_ioctl_count > 100) {
goto error;
}
Expand Down
4 changes: 2 additions & 2 deletions src/config/pgmanage.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# man pgmanage

# Link to file with list of connections.
# connection_file = /usr/local/etc/pgmanage/pgmanage-connections.conf
connection_file = /usr/local/etc/pgmanage/pgmanage-connections.conf

# When set to true, allow users to connect to a custom connection string from the login screen.
# allow_custom_connections = false
Expand All @@ -21,7 +21,7 @@
# login_timeout = 0

# Location of the web_root where the pgManage pages are.
# web_root = /usr/local/etc/pgmanage/web_root
web_root = /usr/local/etc/pgmanage/web_root

# Where the the sql tabs are stored.
# sql_root = ~/.pgmanage/sql
Expand Down
34 changes: 34 additions & 0 deletions src/config/pgmanage.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# For a full explanation of your options, please consult the man page for pgManage.
#
# man pgmanage

# Link to file with list of connections.
connection_file = @prefix@/etc/pgmanage/pgmanage-connections.conf

# When set to true, allow users to connect to a custom connection string from the login screen.
# allow_custom_connections = false

# Port number for pgmanage to listen on.
# pgmanage_port = 8080

# When set to true, a user must be a superuser to login. False means everyone can login.
# super_only = false

# Unless a user has this group, they can't login. No group means that no group is required to login.
# login_group =

# Number of seconds of inactivity before user is automatically logged out. 3600 seconds is 1 hour.
# login_timeout = 0

# Location of the web_root where the pgManage pages are.
web_root = @webroot@

# Where the the sql tabs are stored.
# sql_root = ~/.pgmanage/sql

# Cert and key file for https. If you have tls cert and key files, pgmanage will only listen on https. Otherwise pgmanage listens on http.
# tls_cert =
# tls_key =

# Verbosity of logs. Log level can be error, warn, notice, info.
# log_level = error
51 changes: 39 additions & 12 deletions src/configure
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
#!/bin/sh

usage() { echo "Usage: $0 [ -p <install-prefix> | --prefix <install-prefix>]" 1>&2; exit 1; }
usage() {
echo "usage: ./configure [ options ]" 1>&2;
echo " -p <path>, --prefix <path> set install prefix (default /usr/local)" 1>&2;
echo " -w <path>, --webroot <path> set webroot folder (default /usr/local/etc/pgmanage/web_root)" 1>&2;
}

PREFIX="/usr/local"
WEBROOT="@prefix@/etc/pgmanage/web_root"

case $1 in
-p) PREFIX=$2;;
--prefix=*) PREFIX=$(echo $1 | awk '{ print substr($0, 10)}');;
"") break;;
*) usage;;
esac
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
-p|--prefix)
PREFIX="$2"
shift # past argument
shift # past value
;;
-w|--webroot)
WEBROOT="$2"
shift # past argument
shift # past value
;;
*)
echo "Unknown argument: $key" 1>&2;
usage
exit 1
;;
esac
done

printf "checking for compiler..."
echo "int main() {" > test.c
Expand Down Expand Up @@ -270,6 +291,7 @@ echo "$has_new_sock_directory_parameter_postgres"
sed -e "s|@sock_dir_parameter@|$directory_parameter|g" \
-e "s|@LDFLAGS@|$LDFLAGS|g" \
-e "s|@CPPFLAGS@|$CPPFLAGS|g" \
-e "s|@webroot@|$WEBROOT|g" \
-e "s|@prefix@|$PREFIX|g" \
-e "s|@MANDIR@|$MANDIR|g" \
-e "s|@libev_CPPFLAGS@|$libev_CPPFLAGS|g" \
Expand All @@ -278,21 +300,26 @@ sed -e "s|@sock_dir_parameter@|$directory_parameter|g" \
-e "s|@make@|$MAKE|g" < Makefile.in > Makefile

#### CONFIGURE MAN PAGE
sed -e "s/@prefix@/\/usr\/local/g" < man/man1/pgmanage.1.in > man/man1/pgmanage.1
sed -e "s|@webroot@|$WEBROOT|g" \
-e "s|@prefix@|$PREFIX|g" < man/man1/pgmanage.1.in > man/man1/pgmanage.1

#### CONFIGURE CONFIG FILE
sed -e "s|@webroot@|$WEBROOT|g" \
-e "s|@prefix@|$PREFIX|g" < config/pgmanage.conf.in >config/pgmanage.conf

echo
echo
echo " #############################################################"
echo " # #"
echo " # Thank you for choosing pgmanage! #"
echo " # Thank you for choosing pgmanage! #"
echo " # #"
echo " # If you have any trouble installing pgmanage, #"
echo " # If you have any trouble installing pgmanage, #"
echo " # don't hesitate to email nunzio@workflowproducts.com #"
echo " # or call 817-503-9545 CST #"
echo " # for free support #"
echo " # NOTICE: You are about to compile the WEB SERVER #"
echo " # version of pgManage. The desktop version is easier! #"
echo " # version of pgManage. The desktop version is easier! #"
echo " # You can get it at: #"
echo " # https://github.com/pgManage/pgManage/releases #"
echo " # https://github.com/pgManage/pgManage/releases #"
echo " # #"
echo " #############################################################"
Binary file added src/pgmanage
Binary file not shown.

0 comments on commit bb3e149

Please sign in to comment.