Skip to content

Commit

Permalink
Refactor generated PKG to include a precompiled Immich release
Browse files Browse the repository at this point in the history
  • Loading branch information
zebrapurring committed Nov 30, 2024
1 parent a26140d commit 33ed4c3
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 255 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.DS_Store

# Build artifacts
/dist/
/output/
188 changes: 0 additions & 188 deletions Scripts/build.sh

This file was deleted.

10 changes: 10 additions & 0 deletions Scripts/config.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
IMMICH_TAG="v1.121.0"

IMMICH_INSTALL_DIR="/opt/immich"
IMMICH_SETTINGS_DIR="$IMMICH_INSTALL_DIR/etc"
IMMICH_APP_DIR="$IMMICH_INSTALL_DIR/share"
IMMICH_MEDIA_DIR="$IMMICH_INSTALL_DIR/var/db"

IMMICH_HOME_DIR="$IMMICH_INSTALL_DIR/home"
IMMICH_USER="immich"
IMMICH_GROUP="immich"
10 changes: 0 additions & 10 deletions Scripts/config.sh

This file was deleted.

76 changes: 76 additions & 0 deletions Scripts/configureimmich.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/sh

set -eux

# Create logs directory
mkdir -p /var/log/immich
chown -R "$IMMICH_USER:$IMMICH_GROUP" /var/log/immich

# Create media directory
mkdir -p "$IMMICH_MEDIA_DIR"

# Create custom start scripts
mkdir -p "$IMMICH_SETTINGS_DIR"
cat <<EOF > "$IMMICH_APP_DIR/start.sh"
#!/bin/sh
set -eu
set -a
. "$IMMICH_SETTINGS_DIR/immich_server.env"
set +a
cd "$IMMICH_APP_DIR"
exec node ./dist/main "\$@"
EOF
chmod 700 "$IMMICH_APP_DIR/start.sh"

cat <<EOF > "$IMMICH_APP_DIR/machine-learning/start.sh"
#!/bin/sh
set -eu
set -a
. "$IMMICH_SETTINGS_DIR/immich_server.env"
set +a
cd "$IMMICH_APP_DIR/machine-learning"
. ./venv/bin/activate
: "\${MACHINE_LEARNING_HOST:=127.0.0.1}"
: "\${MACHINE_LEARNING_PORT:=3003}"
: "\${MACHINE_LEARNING_WORKERS:=1}"
: "\${MACHINE_LEARNING_WORKER_TIMEOUT:=120}"
exec gunicorn app.main:app \\
-k app.config.CustomUvicornWorker \\
-w "\$MACHINE_LEARNING_WORKERS" \\
-b "\$MACHINE_LEARNING_HOST:\$MACHINE_LEARNING_PORT" \\
-t "\$MACHINE_LEARNING_WORKER_TIMEOUT" \\
--log-config-json log_conf.json \\
--graceful-timeout 0
EOF
chmod 700 "$IMMICH_APP_DIR/machine-learning/start.sh"

if [ ! -f "$IMMICH_SETTINGS_DIR/immich_server.env" ]; then
cp "$IMMICH_SETTINGS_DIR/build_info.env" "$IMMICH_SETTINGS_DIR/immich_server.env"
cat <<EOF >> "$IMMICH_SETTINGS_DIR/immich_server.env"
# Network binding
IMMICH_HOST="0.0.0.0"
IMMICH_PORT="2283"
# Production settings
NO_COLOR="false"
NODE_ENV="production"
IMMICH_ENV="production"
# Paths configuration
IMMICH_MEDIA_LOCATION="$IMMICH_MEDIA_DIR"
IMMICH_BUILD_DATA="$IMMICH_APP_DIR/build"
# Database connection
DB_HOSTNAME="localhost"
DB_USERNAME="immich"
DB_DATABASE_NAME="immich"
DB_PASSWORD="$POSTGRES_PASSWORD"
DB_VECTOR_EXTENSION="pgvector"
# Redis connection
REDIS_HOSTNAME="localhost"
EOF
fi

# Adjust permissions
chown -R "$IMMICH_USER:$IMMICH_GROUP" "$IMMICH_INSTALL_DIR"
6 changes: 3 additions & 3 deletions Scripts/configurepostgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fi
DB_PASSWORD="$1"

psql-17 postgres << EOF
create database immich;
create user immich with encrypted password '$DB_PASSWORD';
grant all privileges on database immich to immich;
CREATE DATABASE immich;
CREATE USER immich WITH ENCRYPTED PASSWORD '$DB_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE immich TO immich;
ALTER USER immich WITH SUPERUSER;
EOF
10 changes: 0 additions & 10 deletions Scripts/createpaths.sh

This file was deleted.

2 changes: 1 addition & 1 deletion Scripts/createuser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eux

echo "INFO: create user"

if dscl . -list /Users/immich > /dev/null 2>&1; then
if dscl . -list "/Users/$IMMICH_USER" > /dev/null 2>&1; then
# User already exists
exit
fi
Expand Down
3 changes: 3 additions & 0 deletions Scripts/installdaemons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ set -eux

echo "INFO: install daemons"

launchctl bootout system /Library/LaunchDaemons/com.immich.plist || true
launchctl bootout system /Library/LaunchDaemons/com.immich.machine.learning.plist || true

launchctl bootstrap system /Library/LaunchDaemons/com.immich.plist
launchctl bootstrap system /Library/LaunchDaemons/com.immich.machine.learning.plist
9 changes: 4 additions & 5 deletions Scripts/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

set -eux

set -a
# shellcheck disable=SC1091
. "$(pwd)/config.sh"
. "$(pwd)/config.env"
set +a

# Configure logging
install_logfile="/tmp/immich-install.log"
Expand All @@ -14,11 +16,8 @@ echo "Running postinstall as $(whoami)"
# Create immich user
"$(pwd)/createuser.sh"

# Create required directories
"$(pwd)/createpaths.sh"

# Build Immich application
"$(pwd)/build.sh"
"$(pwd)/configureimmich.sh"

# Install Launchd daemons
"$(pwd)/installdaemons.sh"
14 changes: 8 additions & 6 deletions Scripts/preinstall
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
set -eux

# Generate database password
DB_PASSWORD="$(uuidgen)"
if ! grep -q "^export DB_PASSWORD=" "$(pwd)/config.sh"; then
echo "export DB_PASSWORD=\"$DB_PASSWORD\"" >> "$(pwd)/config.sh"
POSTGRES_PASSWORD="$(dd if=/dev/urandom bs=1 count=100 status=none | md5 -q)"
if ! grep -q "^POSTGRES_PASSWORD" "$(pwd)/config.env"; then
echo "POSTGRES_PASSWORD=\"$POSTGRES_PASSWORD\"" >> "$(pwd)/config.env"
fi

set -a
# shellcheck disable=SC1091
. "$(pwd)/config.sh"
. "$(pwd)/config.env"
set +a

# Configure logging
install_logfile="/tmp/immich-install.log"
Expand All @@ -21,7 +23,7 @@ echo "Running preinstall as $(whoami)"
# Install dependencies
"$(pwd)/installdependencies.sh"
homebrew_bindir="$(su -l "$USER" -c "which brew" | xargs -I {} dirname "{}")"
echo "export PATH=\"$homebrew_bindir:\$PATH\"" >> "$(pwd)/config.sh"
echo "PATH=\"$homebrew_bindir:\$PATH\"" >> "$(pwd)/config.env"

# Configure database
"$(pwd)/configurepostgres.sh" "$DB_PASSWORD"
"$(pwd)/configurepostgres.sh" "$POSTGRES_PASSWORD"
Loading

0 comments on commit 33ed4c3

Please sign in to comment.