Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install more conventionally #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 36 additions & 31 deletions timescaledb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,58 @@ class Timescaledb < Formula
version "2.3.0"
sha256 "baa8a60230320838c6d5d143846c14edc5238e2979ed2408a980280f05a81b3e"

depends_on "postgresql"

depends_on "cmake" => :build
depends_on "postgresql" => :build
depends_on "openssl" => :build
depends_on "xz" => :build
depends_on "timescaledb-tools" => :recommended

option "with-oss-only", "Build TimescaleDB with only Apache-2 licensed code"

def install
ossvar = ""
if build.with?("oss-only")
ossvar = " -DAPACHE_ONLY=1"
end
system "./bootstrap -DREGRESS_CHECKS=OFF -DPROJECT_INSTALL_METHOD=\"brew\"#{ossvar}"
system "cd ./build && make"
system "cd ./build && make install DESTDIR=#{buildpath}/stage"
libdir = `pg_config --pkglibdir`
sharedir = `pg_config --sharedir`
`touch timescaledb_move.sh`
`chmod +x timescaledb_move.sh`
`echo "#!/bin/bash" >> timescaledb_move.sh`
`echo "echo 'Moving files into place...'" >> timescaledb_move.sh`
`echo "/usr/bin/install -c -m 755 \\\$(find #{lib} -name timescaledb*.so) #{libdir.strip}/" >> timescaledb_move.sh`
`echo "/usr/bin/install -c -m 644 #{share}/timescaledb/* #{sharedir.strip}/extension/" >> timescaledb_move.sh`
`echo "echo 'Success.'" >> timescaledb_move.sh`
bin.install "timescaledb_move.sh"
(lib/"timescaledb").install Dir["stage/**/lib/*"]
(share/"timescaledb").install Dir["stage/**/share/postgresql*/extension/*"]
system "./bootstrap -DREGRESS_CHECKS=OFF -DPROJECT_INSTALL_METHOD=\"brew\"#{" -DAPACHE_ONLY=1" if build.with?("oss-only")}"

(buildpath/"build").cd do
system "make"

# CMake installs the files into DESTDIR/$HOMEBREW_PREFIX, so stage it and then unwrap it
stage = buildpath/"stage"
stage.mkdir

system "make install DESTDIR=#{stage}"

# Something like:
# /var/tmp/abc123/stage/usr/local
#
# which contains files like
# /var/tmp/abc123/stage/usr/local/lib/postgresql/timescaledb.so
#
stage_prefix = (stage/HOMEBREW_PREFIX.to_s.delete_prefix("/"))

prefix.install stage_prefix.children
end
end

test do
system "test", "-e", "#{lib}/timescaledb/timescaledb.so"
system "test", "-e", "#{lib}/postgresql/timescaledb.so"
end

def caveats
pgvar = `find /usr/local/var/postgres* -name "postgresql.conf" | head -n 1`
s = "RECOMMENDED: Run 'timescaledb-tune' to update your config settings for TimescaleDB.\n\n"
s += " timescaledb-tune --quiet --yes\n\n"
<<~EOS
RECOMMENDED: Run 'timescaledb-tune' to update your config settings for TimescaleDB.

timescaledb-tune --quiet --yes --conf-path #{var/"postgres/postgresql.conf"}

IF NOT, you'll need to make sure to update #{var/"postgres/postgresql.conf"}
to include the extension:

shared_preload_libraries = 'timescaledb'

s += "IF NOT, you'll need to make sure to update #{pgvar.strip}\nto include the extension:\n\n"
s += " shared_preload_libraries = 'timescaledb'\n\n"
If PostgreSQL is installed via Homebrew, restart it:

s += "To finish the installation, you will need to run:\n\n"
s += " timescaledb_move.sh\n\n"
brew services restart postgresql

s += "If PostgreSQL is installed via Homebrew, restart it:\n\n"
s += " brew services restart postgresql\n\n"
s
EOS
end
end