aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2025-05-06 20:46:25 +0300
committerMunyoki Kilyungi2025-05-06 20:46:25 +0300
commitc16600ea5bdf7bab75c7105c173e8351422e9663 (patch)
treebd506d3bc024f3e5fb4de37cce496d9079c64663
parenta79e1d05969f85ea38f341028d37a1385a3d33b6 (diff)
downloadgn-machines-c16600ea5bdf7bab75c7105c173e8351422e9663.tar.gz
Add "--init-container" option.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rwxr-xr-xgenenetwork-local-container.sh316
1 files changed, 159 insertions, 157 deletions
diff --git a/genenetwork-local-container.sh b/genenetwork-local-container.sh
index 5cf4655..0f873a7 100755
--- a/genenetwork-local-container.sh
+++ b/genenetwork-local-container.sh
@@ -79,180 +79,182 @@ if [ -z "${HOME:-}" ]; then
exit 1
fi
-log "INFO" "Creating system directories..."
-for dir in "${SYSTEM_DIRECTORIES[@]}"; do
- # Check if directory exists and is accessible
- if [ -d "$dir" ]; then
- if [ -w "$dir" ]; then
- log "DEBUG" "Directory exists and is writable: $dir"
- else
- log "WARNING" "Directory exists but is not writable: $dir. Making this writable"
- sudo chown -R "$USER" "$dir"
- fi
- continue
- fi
+if [ "$1" = "--init-container" ]; then
+ log "INFO" "Creating system directories..."
+ for dir in "${SYSTEM_DIRECTORIES[@]}"; do
+ # Check if directory exists and is accessible
+ if [ -d "$dir" ]; then
+ if [ -w "$dir" ]; then
+ log "DEBUG" "Directory exists and is writable: $dir"
+ else
+ log "WARNING" "Directory exists but is not writable: $dir. Making this writable"
+ sudo chown -R "$USER" "$dir"
+ fi
+ continue
+ fi
- # Attempt to create directory
- log "INFO" "Creating directory: $dir"
- if [ -w "$(dirname "$dir")" ]; then
- # Parent directory is writable, try without sudo
- if ! mkdir -p "$dir"; then
- log "ERROR" "Failed to create directory without sudo: $dir"
- exit 1
- fi
- else
- # Parent directory requires root, use sudo
- if ! sudo mkdir -p "$dir"; then
- log "ERROR" "Failed to create directory with sudo: $dir"
- exit 1
- fi
- # Set ownership to current user if created with sudo
- if ! sudo chown "$USER:$USER" "$dir"; then
- log "WARNING" "Failed to set ownership for: $dir"
- fi
- fi
-done
-
-# Check and copy configuration files
-log "INFO" "Checking and copying configuration files..."
-for src in "${!FILE_MAPPINGS[@]}"; do
- dest="${FILE_MAPPINGS[$src]}"
- log "INFO" "Processing $src -> $dest"
+ # Attempt to create directory
+ log "INFO" "Creating directory: $dir"
+ if [ -w "$(dirname "$dir")" ]; then
+ # Parent directory is writable, try without sudo
+ if ! mkdir -p "$dir"; then
+ log "ERROR" "Failed to create directory without sudo: $dir"
+ exit 1
+ fi
+ else
+ # Parent directory requires root, use sudo
+ if ! sudo mkdir -p "$dir"; then
+ log "ERROR" "Failed to create directory with sudo: $dir"
+ exit 1
+ fi
+ # Set ownership to current user if created with sudo
+ if ! sudo chown "$USER:$USER" "$dir"; then
+ log "WARNING" "Failed to set ownership for: $dir"
+ fi
+ fi
+ done
- # Check if source file exists
- if [ ! -f "$src" ]; then
- log "ERROR" "Source file does not exist: $src"
- exit 1
- fi
+ # Check and copy configuration files
+ log "INFO" "Checking and copying configuration files..."
+ for src in "${!FILE_MAPPINGS[@]}"; do
+ dest="${FILE_MAPPINGS[$src]}"
+ log "INFO" "Processing $src -> $dest"
- # Check if destination file exists
- if [ ! -f "$dest" ]; then
- log "INFO" "Destination file does not exist, copying $src to $dest"
- mkdir -p "$(dirname "$dest")"
- if ! cp "$src" "$dest"; then
- log "ERROR" "Failed to copy $src to $dest"
+ # Check if source file exists
+ if [ ! -f "$src" ]; then
+ log "ERROR" "Source file does not exist: $src"
exit 1
- fi
- continue
- fi
+ fi
- # Compare files using diff
- log "INFO" "Comparing $src with $dest"
- if diff_output=$(diff -u "$dest" "$src" 2>&1); then
- log "INFO" "Files $src and $dest are identical"
- else
- log "INFO" "Differences found between $src and $dest:"
- echo "$diff_output" >&2
- log "INFO" "Copying $src to $dest"
- if ! cp "$src" "$dest"; then
- log "ERROR" "Failed to copy $src to $dest"
- exit 1
- fi
- fi
-done
+ # Check if destination file exists
+ if [ ! -f "$dest" ]; then
+ log "INFO" "Destination file does not exist, copying $src to $dest"
+ mkdir -p "$(dirname "$dest")"
+ if ! cp "$src" "$dest"; then
+ log "ERROR" "Failed to copy $src to $dest"
+ exit 1
+ fi
+ continue
+ fi
+
+ # Compare files using diff
+ log "INFO" "Comparing $src with $dest"
+ if diff_output=$(diff -u "$dest" "$src" 2>&1); then
+ log "INFO" "Files $src and $dest are identical"
+ else
+ log "INFO" "Differences found between $src and $dest:"
+ echo "$diff_output" >&2
+ log "INFO" "Copying $src to $dest"
+ if ! cp "$src" "$dest"; then
+ log "ERROR" "Failed to copy $src to $dest"
+ exit 1
+ fi
+ fi
+ done
-is_git_repository() {
- local dir="$1"
- # Check for standard repository
- if [ -d "$dir/.git" ]; then
- if [ -f "$dir/.git/HEAD" ] && [ -d "$dir/.git/refs" ]; then
- log "DEBUG" "Detected standard Git repository: $dir"
+ is_git_repository() {
+ local dir="$1"
+ # Check for standard repository
+ if [ -d "$dir/.git" ]; then
+ if [ -f "$dir/.git/HEAD" ] && [ -d "$dir/.git/refs" ]; then
+ log "DEBUG" "Detected standard Git repository: $dir"
+ return 0
+ else
+ log "ERROR" "Directory $dir/.git exists but is not a valid Git repository"
+ return 1
+ fi
+ # Check for bare repository
+ elif [ -f "$dir/HEAD" ] && [ -d "$dir/refs" ] && [ -d "$dir/objects" ]; then
+ log "DEBUG" "Detected bare Git repository: $dir"
return 0
- else
- log "ERROR" "Directory $dir/.git exists but is not a valid Git repository"
+ else
+ log "ERROR" "$dir exists but is not a Git repository (neither standard nor bare)"
return 1
- fi
- # Check for bare repository
- elif [ -f "$dir/HEAD" ] && [ -d "$dir/refs" ] && [ -d "$dir/objects" ]; then
- log "DEBUG" "Detected bare Git repository: $dir"
- return 0
- else
- log "ERROR" "$dir exists but is not a Git repository (neither standard nor bare)"
- return 1
- fi
-}
-# Clone GeneNetwork projects
-log "INFO" "Cloning GeneNetwork projects..."
-for project_entry in "${GN_PROJECTS[@]}"; do
- IFS=':' read -r project repo_url <<< "$project_entry"
- dir="$BASE_DIR/$project"
- if [ ! -d "$dir" ]; then
- log "INFO" "Cloning $project from $repo_url to $dir"
- if ! git clone "$repo_url" "$dir"; then
- log "ERROR" "Failed to clone $project"
+ fi
+ }
+ # Clone GeneNetwork projects
+ log "INFO" "Cloning GeneNetwork projects..."
+ for project_entry in "${GN_PROJECTS[@]}"; do
+ IFS=':' read -r project repo_url <<< "$project_entry"
+ dir="$BASE_DIR/$project"
+ if [ ! -d "$dir" ]; then
+ log "INFO" "Cloning $project from $repo_url to $dir"
+ if ! git clone "$repo_url" "$dir"; then
+ log "ERROR" "Failed to clone $project"
+ exit 1
+ fi
+ else
+ log "DEBUG" "Directory exists, skipping clone: $dir"
+ if ! is_git_repository "$dir"; then
+ log "ERROR" "$dir exists but is not a Git repository"
+ exit 1
+ fi
+ fi
+ done
+
+ FLASK_SESSION="$BASE_DIR/genenetwork2/flask_session"
+ log "INFO" "Checking FLASK_SESSION directory: $FLASK_SESSION"
+ if [ ! -d "$FLASK_SESSION" ]; then
+ log "INFO" "Creating FLASK_SESSION directory: $FLASK_SESSION"
+ if ! mkdir -p "$FLASK_SESSION"; then
+ log "ERROR" "Failed to create FLASK_SESSION directory: $FLASK_SESSION"
exit 1
- fi
+ fi
else
- log "DEBUG" "Directory exists, skipping clone: $dir"
- if ! is_git_repository "$dir"; then
- log "ERROR" "$dir exists but is not a Git repository"
- exit 1
- fi
+ log "DEBUG" "FLASK_SESSION directory already exists: $FLASK_SESSION"
fi
-done
-FLASK_SESSION="$BASE_DIR/genenetwork2/flask_session"
-log "INFO" "Checking FLASK_SESSION directory: $FLASK_SESSION"
-if [ ! -d "$FLASK_SESSION" ]; then
- log "INFO" "Creating FLASK_SESSION directory: $FLASK_SESSION"
- if ! mkdir -p "$FLASK_SESSION"; then
- log "ERROR" "Failed to create FLASK_SESSION directory: $FLASK_SESSION"
- exit 1
+
+ # Verify container SCM file exists
+ if [ ! -f "$CONTAINER_SCM" ]; then
+ log "ERROR" "Container SCM file not found: $CONTAINER_SCM"
+ exit 1
fi
-else
- log "DEBUG" "FLASK_SESSION directory already exists: $FLASK_SESSION"
-fi
+ # Create Guix system container
+ log "INFO" "Creating Guix system container..."
+ SHARE_OPTS=(
+ "--share=$BASE_DIR/var/log=/var/log"
+ "--share=$BASE_DIR/var/genenetwork=/var/genenetwork"
+ "--share=$BASE_DIR/etc/genenetwork/conf=/etc/genenetwork/conf"
+ "--share=$BASE_DIR/etc/genenetwork=/etc/genenetwork"
+ "--share=$BASE_DIR/var/lib/redis=/var/lib/redis"
+ "--share=$BASE_DIR/var/lib/virtuoso=/var/lib/virtuoso"
+ "--share=$BASE_DIR/genenetwork2=/genenetwork2"
+ "--share=$BASE_DIR/genenetwork3=/genenetwork3"
+ "--share=$BASE_DIR/gn-auth=/gn-auth"
+ "--share=$BASE_DIR/var/lib/xapian=/var/lib/xapian"
+ "--share=$BASE_DIR/var/lib/genenetwork-sqlite=/var/lib/genenetwork-sqlite"
+ "--share=$BASE_DIR/var/lib/genenetwork-gnqa=/var/lib/genenetwork-gnqa"
+ "--share=/tmp/local-container=/tmp"
+ "--share=$BASE_DIR/gn-docs=/var/lib/gn-docs"
+ "--share=/run/mysqld=/run/mysqld"
+ )
-# Verify container SCM file exists
-if [ ! -f "$CONTAINER_SCM" ]; then
- log "ERROR" "Container SCM file not found: $CONTAINER_SCM"
- exit 1
-fi
+ container_script=$(guix system container \
+ --network \
+ --load-path=. \
+ --verbosity=3 \
+ "${SHARE_OPTS[@]}" \
+ "$CONTAINER_SCM")
-# Create Guix system container
-log "INFO" "Creating Guix system container..."
-SHARE_OPTS=(
- "--share=$BASE_DIR/var/log=/var/log"
- "--share=$BASE_DIR/var/genenetwork=/var/genenetwork"
- "--share=$BASE_DIR/etc/genenetwork/conf=/etc/genenetwork/conf"
- "--share=$BASE_DIR/etc/genenetwork=/etc/genenetwork"
- "--share=$BASE_DIR/var/lib/redis=/var/lib/redis"
- "--share=$BASE_DIR/var/lib/virtuoso=/var/lib/virtuoso"
- "--share=$BASE_DIR/genenetwork2=/genenetwork2"
- "--share=$BASE_DIR/genenetwork3=/genenetwork3"
- "--share=$BASE_DIR/gn-auth=/gn-auth"
- "--share=$BASE_DIR/var/lib/xapian=/var/lib/xapian"
- "--share=$BASE_DIR/var/lib/genenetwork-sqlite=/var/lib/genenetwork-sqlite"
- "--share=$BASE_DIR/var/lib/genenetwork-gnqa=/var/lib/genenetwork-gnqa"
- "--share=/tmp/local-container=/tmp"
- "--share=$BASE_DIR/gn-docs=/var/lib/gn-docs"
- "--share=/run/mysqld=/run/mysqld"
-)
-
-container_script=$(guix system container \
- --network \
- --load-path=. \
- --verbosity=3 \
- "${SHARE_OPTS[@]}" \
- "$CONTAINER_SCM")
+ log $container_script
-log $container_script
+ # Create symbolic links
+ log "INFO" "Creating symbolic links..."
+ if ! sudo ln -sf "$container_script" "$CONTAINER_BIN"; then
+ log "ERROR" "Failed to create symbolic link: $CONTAINER_BIN"
+ exit 1
+ fi
-# Create symbolic links
-log "INFO" "Creating symbolic links..."
-if ! sudo ln -sf "$container_script" "$CONTAINER_BIN"; then
- log "ERROR" "Failed to create symbolic link: $CONTAINER_BIN"
- exit 1
-fi
+ if ! sudo ln -sf "$container_script" "$GC_ROOT"; then
+ log "ERROR" "Failed to create GC root link: $GC_ROOT"
+ exit 1
+ fi
-if ! sudo ln -sf "$container_script" "$GC_ROOT"; then
- log "ERROR" "Failed to create GC root link: $GC_ROOT"
- exit 1
+ log "INFO" "Setup completed successfully!"
+ log "INFO" "Container script: $container_script"
+ log "INFO" "Run with: $CONTAINER_BIN"
+ log "INFO" "Email: test@development.user"
+ log "INFO" "Password: testpasswd"
fi
-
-log "INFO" "Setup completed successfully!"
-log "INFO" "Container script: $container_script"
-log "INFO" "Run with: $CONTAINER_BIN"
-log "INFO" "Email: test@development.user"
-log "INFO" "Password: testpasswd"