aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorwinter2025-01-18 22:41:17 +0000
committerwinter2025-01-18 22:49:41 +0000
commitf1a48c521472bde1c8668e29f8c5c792e1dd9f9f (patch)
tree21b89bf89204371de7a94042d8ed3d02c29d8516
parent5d55ae009cab1fe82f456111585d20795f4e865a (diff)
init script & fix the version info thing
yeah so turns out $Id$ is not what it seems
-rw-r--r--.gitignore3
-rw-r--r--README.md3
-rwxr-xr-xbin/init19
-rwxr-xr-xbin/update-version9
-rw-r--r--misc/.gitattributes1
-rw-r--r--misc/get_version.php14
6 files changed, 35 insertions, 14 deletions
diff --git a/.gitignore b/.gitignore
index b066bf3..c441512 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
vendor/
config.ini
-upload/* \ No newline at end of file
+upload/*
+VERSION \ No newline at end of file
diff --git a/README.md b/README.md
index a2db5e5..2081be0 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,8 @@ you should have:
the basic steps for setup are:
-1. run `composer install`
+1. run `bin/init` (which will install composer things and update the internal
+ version info)
2. edit config.ini as appropriate
3. set up the database with `bin/migrate`
4. run the development server with `bin/devserver <port>`, or set it up with
diff --git a/bin/init b/bin/init
new file mode 100755
index 0000000..61d5fdd
--- /dev/null
+++ b/bin/init
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+cd "$(dirname "$0")"/.. || exit 1
+
+if ! command -v composer >/dev/null; then
+ echo 'You need composer installed! https://getcomposer.org/download/' >/dev/stderr
+ exit 1
+fi
+
+if [ -d .git ]; then
+ # seems likely we are running inside a git clone rather than an exported archive
+ # install the hook so that version info is updated on every commit/checkout
+ ln -s ../../bin/update-version .git/hooks/post-commit
+ ln -s ../../bin/update-version .git/hooks/post-checkout
+ # and run it now
+ bin/update-version
+fi
+
+composer install && echo 'Done! Now edit config.ini to your liking, and then run bin/migrate'
diff --git a/bin/update-version b/bin/update-version
new file mode 100755
index 0000000..b9b3d21
--- /dev/null
+++ b/bin/update-version
@@ -0,0 +1,9 @@
+#!/bin/bash
+cd "$(dirname "$0")" || exit 1
+[ -L "$(basename "$0")" ] && cd "$(dirname "$(readlink "$(basename "$0")")")"
+if ! git describe --tags 2>/dev/null > ../VERSION; then
+ printf 'git ' > ../VERSION
+ git rev-parse --short HEAD >> ../VERSION
+fi
+printf 'stored version: '
+cat ../VERSION \ No newline at end of file
diff --git a/misc/.gitattributes b/misc/.gitattributes
deleted file mode 100644
index e383d5c..0000000
--- a/misc/.gitattributes
+++ /dev/null
@@ -1 +0,0 @@
-get_version.php ident export-subst \ No newline at end of file
diff --git a/misc/get_version.php b/misc/get_version.php
index 8d48b4a..e9c255a 100644
--- a/misc/get_version.php
+++ b/misc/get_version.php
@@ -1,21 +1,13 @@
<?php
-// because of the values in .gitattributes, these should get modified according
-// to the current commit (on any checkout) and/or ref (in archive exports)
-// don't touch these yourself even if they look wrong!
-const __GIT_ID_INFO__ = '$Id$';
-const __GIT_REF_INFO__ = '$Format:%D$';
+const __VERSION_FILE = __DIR__ . '/../VERSION';
/**
* Gets a version identifier for the currently checked out version of the software
* @return string
*/
function get_version(): string {
- if (str_contains(__GIT_REF_INFO__, 'tag: ')) {
- return explode(',', explode('tag: ', __GIT_REF_INFO__, 2)[1], 2)[0];
- }
- // have to do this janky string thing to stop git replacing this one as well :3
- if (__GIT_ID_INFO__ != '$' . 'Id$') {
- return 'git ' . substr(__GIT_ID_INFO__, 5, 10);
+ if (is_readable(__VERSION_FILE)) {
+ return trim(file_get_contents(__VERSION_FILE));
}
return 'unknown';
} \ No newline at end of file