Skip to content

Commit da2f541

Browse files
author
KIvanow
committed
RI-6690 splitting the script into different scenarios
1 parent eab2f40 commit da2f541

File tree

1 file changed

+70
-17
lines changed

1 file changed

+70
-17
lines changed

scripts/deb-after-install.sh

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,85 @@
11
#!/bin/bash
2-
set -ex
2+
set -e
33

44
OLD_INSTALL_PATH="/opt/Redis Insight"
55
NEW_INSTALL_PATH="/opt/redisinsight"
66
DESKTOP_FILE="/usr/share/applications/redisinsight.desktop"
77

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"
1137
exit 0
1238
fi
1339

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
1861

1962
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
2265
fi
2366

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
2872

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
3275
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

Comments
 (0)