install.sh (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
#!/usr/bin/env bash
set -euo pipefail
# Configuration
APP_NAME="EMessage"
SERVER_URL="https://updater.machinetele.com"
# Detect platform
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) GOOS="linux" ;;
Darwin) GOOS="darwin" ;;
*) echo "Unsupported OS: $OS"; exit 1 ;;
esac
case "$ARCH" in
x86_64|amd64) GOARCH="amd64" ;;
aarch64|arm64) GOARCH="arm64" ;;
i386|i686) GOARCH="386" ;;
armv7l) GOARCH="arm" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
PLATFORM="${GOOS}-${GOARCH}"
echo "Checking for ${APP_NAME} updates for ${PLATFORM}..."
echo "Server: ${SERVER_URL}"
# Function to cleanup temp files
cleanup() {
rm -rf "$TMP_DIR"
}
trap cleanup ERR EXIT
if [[ "$GOOS" == "darwin" ]]; then
# --- macOS: download and install .app bundle from darwin-app ---
MANIFEST_URL="${SERVER_URL}/${APP_NAME}/darwin-app.json"
echo "Looking for macOS bundle manifest at ${MANIFEST_URL}"
JSON=$(curl -sf "${MANIFEST_URL}") || {
echo "Platform macOS download not available (no install manifest at ${MANIFEST_URL})"
exit 1
}
# Parse version and sha256
if command -v jq &>/dev/null; then
VERSION=$(echo "$JSON" | jq -r '.Version')
SHA256=$(echo "$JSON" | jq -r '.Sha256')
else
VERSION=$(echo "$JSON" | grep -o '"Version":"[^"]*"' | cut -d'"' -f4)
SHA256=$(echo "$JSON" | grep -o '"Sha256":"[^"]*"' | cut -d'"' -f4)
fi
if [[ -z "$VERSION" || -z "$SHA256" ]]; then
echo "Failed to parse macOS install manifest."
exit 1
fi
echo "Latest macOS bundle version: ${VERSION}"
# Download the versioned darwin-app tarball
BUNDLE_URL="${SERVER_URL}/${APP_NAME}/${VERSION}/darwin-app"
TMP_DIR=$(mktemp -d)
TMP_TAR="${TMP_DIR}/${APP_NAME}.tar"
echo "Downloading ${BUNDLE_URL}..."
curl -sfL "${BUNDLE_URL}" -o "${TMP_TAR}" || {
echo "Download failed."
exit 1
}
# Verify SHA256
computed=$(sha256sum "${TMP_TAR}" | cut -d' ' -f1)
if [[ "$computed" != "$SHA256" ]]; then
echo "Hash mismatch! Expected $SHA256, got $computed"
exit 1
fi
# Determine installation directory
if [[ $EUID -eq 0 ]]; then
APP_INSTALL_DIR="/Applications"
else
APP_INSTALL_DIR="${HOME}/Applications"
mkdir -p "$APP_INSTALL_DIR"
fi
# Extract the .app bundle (tar, not compressed)
echo "Extracting to ${APP_INSTALL_DIR}..."
tar xf "${TMP_TAR}" -C "$APP_INSTALL_DIR" || {
echo "Extraction failed."
exit 1
}
# The archive should contain a .app directory
if [[ ! -d "${APP_INSTALL_DIR}/${APP_NAME}.app" ]]; then
echo "Error: Archive did not contain ${APP_NAME}.app"
ls -la "${APP_INSTALL_DIR}"
exit 1
fi
echo "${APP_NAME} ${VERSION} installed to ${APP_INSTALL_DIR}/${APP_NAME}.app"
echo "The auto-updater will handle future updates inside the bundle."
else
# --- Linux: download binary and create desktop entry (unchanged) ---
MANIFEST_URL="${SERVER_URL}/${APP_NAME}/${PLATFORM}.json"
echo "Checking for Linux binary at ${MANIFEST_URL}"
JSON=$(curl -sf "${MANIFEST_URL}") || {
echo "Platform ${PLATFORM} is not supported (no manifest found at ${MANIFEST_URL})"
exit 1
}
# Parse version and sha256
if command -v jq &>/dev/null; then
VERSION=$(echo "$JSON" | jq -r '.Version')
SHA256=$(echo "$JSON" | jq -r '.Sha256')
else
VERSION=$(echo "$JSON" | grep -o '"Version":"[^"]*"' | cut -d'"' -f4)
SHA256=$(echo "$JSON" | grep -o '"Sha256":"[^"]*"' | cut -d'"' -f4)
fi
if [[ -z "$VERSION" || -z "$SHA256" ]]; then
echo "Failed to parse Linux binary manifest."
exit 1
fi
echo "Latest Linux version: ${VERSION}"
# Download binary
BINARY_URL="${SERVER_URL}/${APP_NAME}/${VERSION}/${PLATFORM}.gz"
TMP_DIR=$(mktemp -d)
TMP_GZ="${TMP_DIR}/${APP_NAME}.gz"
echo "Downloading ${BINARY_URL}..."
curl -sfL "${BINARY_URL}" -o "${TMP_GZ}" || {
echo "Download failed."
exit 1
}
# Verify SHA256
echo "${SHA256} ${TMP_GZ}" | sha256sum -c --quiet 2>/dev/null || {
echo "Hash mismatch! Binary may be corrupted."
exit 1
}
# Decompress
gunzip -c "${TMP_GZ}" > "${TMP_DIR}/${APP_NAME}" || {
echo "Decompression failed."
exit 1
}
chmod +x "${TMP_DIR}/${APP_NAME}"
# Install binary
if [[ $EUID -eq 0 ]]; then
INSTALL_DIR="/usr/local/bin"
else
# Prefer ~/.local/bin, else ~/bin
if [[ -d "${HOME}/.local/bin" ]]; then
INSTALL_DIR="${HOME}/.local/bin"
elif [[ -d "${HOME}/bin" ]]; then
INSTALL_DIR="${HOME}/bin"
else
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
fi
cp "${TMP_DIR}/${APP_NAME}" "${INSTALL_DIR}/${APP_NAME}"
echo "Binary installed to ${INSTALL_DIR}/${APP_NAME}"
# --- Linux desktop entry with icon ---
ICON_URL="${SERVER_URL}/${APP_NAME}/appicon.png"
ICON_DIR="${HOME}/.local/share/icons/hicolor/256x256/apps"
mkdir -p "$ICON_DIR"
if curl -sfL "${ICON_URL}" -o "${ICON_DIR}/${APP_NAME}.png"; then
echo "App icon downloaded."
else
echo "Warning: Could not download icon (${ICON_URL})."
ICON_DIR="" # will skip icon in desktop file
fi
DESKTOP_DIR="${HOME}/.local/share/applications"
mkdir -p "$DESKTOP_DIR"
DESKTOP_FILE="${DESKTOP_DIR}/${APP_NAME}.desktop"
cat > "$DESKTOP_FILE" <<EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=${APP_NAME}
Comment=Electronic Message client
Exec=${INSTALL_DIR}/${APP_NAME}
Icon=${ICON_DIR:+${ICON_DIR}/${APP_NAME}.png}
Terminal=false
Categories=Network;InstantMessaging;
StartupNotify=true
EOF
chmod +x "$DESKTOP_FILE"
echo "Desktop entry created: ${DESKTOP_FILE}"
fi
echo ""
echo "✔ ${APP_NAME} ${VERSION} installed successfully!"
|