|
1 | 1 | #!/bin/bash
|
2 |
| -set -ex |
| 2 | +set -e |
3 | 3 |
|
4 | 4 | OLD_INSTALL_PATH="/opt/Redis Insight"
|
5 | 5 | NEW_INSTALL_PATH="/opt/redisinsight"
|
6 | 6 | DESKTOP_FILE="/usr/share/applications/redisinsight.desktop"
|
7 | 7 |
|
8 |
| -# Skip migration if new structure already exists |
9 |
| -if [ -d "$NEW_INSTALL_PATH" ]; then |
10 |
| - echo "New path already exists. Assuming clean install or previous fix. Skipping migration." |
| 8 | +# Try to gracefully terminate any running instances |
| 9 | +if pgrep redisinsight >/dev/null; then |
| 10 | + echo "RedisInsight is running, attempting to terminate gracefully" |
| 11 | + pkill redisinsight || true |
| 12 | + # Give it a moment to shut down |
| 13 | + sleep 2 |
| 14 | +fi |
| 15 | + |
| 16 | +# Handle update case: redisinsight exists, Redis Insight exists too |
| 17 | +# This means that we are in an update scenario |
| 18 | +if [ -d "$NEW_INSTALL_PATH" ] && [ -d "$OLD_INSTALL_PATH" ]; then |
| 19 | + echo "Both old and new paths exist - handling update scenario" |
| 20 | + |
| 21 | + cp -rf "$OLD_INSTALL_PATH"/* "$NEW_INSTALL_PATH"/ || true |
| 22 | + |
| 23 | + rm -rf "$OLD_INSTALL_PATH" || true |
| 24 | + |
| 25 | + if [ -f "$DESKTOP_FILE" ]; then |
| 26 | + echo "Updating desktop file reference" |
| 27 | + sed -i "s|$OLD_INSTALL_PATH|$NEW_INSTALL_PATH|g" "$DESKTOP_FILE" || true |
| 28 | + fi |
| 29 | + |
| 30 | + # Ensure binary link and permissions |
| 31 | + ln -sf "$NEW_INSTALL_PATH/redisinsight" "/usr/bin/redisinsight" || true |
| 32 | + chmod +x "$NEW_INSTALL_PATH/redisinsight" || true |
| 33 | + chown root:root "$NEW_INSTALL_PATH/chrome-sandbox" || true |
| 34 | + chmod 4755 "$NEW_INSTALL_PATH/chrome-sandbox" || true |
| 35 | + |
| 36 | + echo "Update handled successfully" |
11 | 37 | exit 0
|
12 | 38 | fi
|
13 | 39 |
|
14 |
| -# Proceed only if old path exists |
15 |
| -if [ -d "$OLD_INSTALL_PATH" ]; then |
16 |
| - echo "Old path found. Migrating to new path..." |
17 |
| - mv "$OLD_INSTALL_PATH" "$NEW_INSTALL_PATH" |
| 40 | +# Handle simple auto-update case: only redisinsight exists |
| 41 | +if [ -d "$NEW_INSTALL_PATH" ] && [ ! -d "$OLD_INSTALL_PATH" ]; then |
| 42 | + echo "New path exists but old doesn't - likely clean install or auto-update" |
| 43 | + |
| 44 | + # Ensure binary link and permissions |
| 45 | + ln -sf "$NEW_INSTALL_PATH/redisinsight" "/usr/bin/redisinsight" || true |
| 46 | + chmod +x "$NEW_INSTALL_PATH/redisinsight" || true |
| 47 | + chown root:root "$NEW_INSTALL_PATH/chrome-sandbox" || true |
| 48 | + chmod 4755 "$NEW_INSTALL_PATH/chrome-sandbox" || true |
| 49 | + |
| 50 | + echo "Installation/update completed successfully" |
| 51 | + exit 0 |
| 52 | +fi |
| 53 | + |
| 54 | +# Handle migration case: only Redis Insight exists. |
| 55 | +#This is to ensure that if somebody updates from a very old version to a newer one, we'll still migrate it as expected |
| 56 | +if [ ! -d "$NEW_INSTALL_PATH" ] && [ -d "$OLD_INSTALL_PATH" ]; then |
| 57 | + echo "Old path found but new doesn't exist - migrating to new path" |
| 58 | + |
| 59 | + # Simply move the directory |
| 60 | + mv "$OLD_INSTALL_PATH" "$NEW_INSTALL_PATH" || true |
18 | 61 |
|
19 | 62 | if [ -f "$DESKTOP_FILE" ]; then
|
20 |
| - echo "Updating desktop file" |
21 |
| - sed -i "s|$OLD_INSTALL_PATH|$NEW_INSTALL_PATH|g" "$DESKTOP_FILE" |
| 63 | + echo "Updating desktop file reference" |
| 64 | + sed -i "s|$OLD_INSTALL_PATH|$NEW_INSTALL_PATH|g" "$DESKTOP_FILE" || true |
22 | 65 | fi
|
23 | 66 |
|
24 |
| - ln -sf "$NEW_INSTALL_PATH/redisinsight" "/usr/bin/redisinsight" |
25 |
| - chmod +x "$NEW_INSTALL_PATH/redisinsight" |
26 |
| - chown root:root "$NEW_INSTALL_PATH/chrome-sandbox" |
27 |
| - chmod 4755 "$NEW_INSTALL_PATH/chrome-sandbox" |
| 67 | + # Ensure binary link and permissions |
| 68 | + ln -sf "$NEW_INSTALL_PATH/redisinsight" "/usr/bin/redisinsight" || true |
| 69 | + chmod +x "$NEW_INSTALL_PATH/redisinsight" || true |
| 70 | + chown root:root "$NEW_INSTALL_PATH/chrome-sandbox" || true |
| 71 | + chmod 4755 "$NEW_INSTALL_PATH/chrome-sandbox" || true |
28 | 72 |
|
29 |
| - echo "Migration completed" |
30 |
| -else |
31 |
| - echo "Neither old nor new path exists. Unexpected state. Skipping." |
| 73 | + echo "Migration completed successfully" |
| 74 | + exit 0 |
32 | 75 | fi
|
| 76 | + |
| 77 | +# Neither directory exists - unexpected state |
| 78 | +echo "Neither old nor new path exists. This is an unexpected state." |
| 79 | +echo "Creating new installation directory as a fallback" |
| 80 | +mkdir -p "$NEW_INSTALL_PATH" || true |
| 81 | + |
| 82 | +# Always set up the binary link |
| 83 | +ln -sf "$NEW_INSTALL_PATH/redisinsight" "/usr/bin/redisinsight" || true |
| 84 | + |
| 85 | +echo "Post-installation completed with warnings" |
0 commit comments