Skip to content

Commit

Permalink
Install more conventionally
Browse files Browse the repository at this point in the history
The current move script does not work for M1 macs, or for anybody with a
custom homebrew prefix. There's also no need for the extra step if the
extension is exposed at a conventional location which homebrew can link
into place.
  • Loading branch information
sj26 committed May 28, 2021
1 parent d767e66 commit 2adaefd
Showing 1 changed file with 36 additions and 31 deletions.
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

0 comments on commit 2adaefd

Please sign in to comment.