-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinstall.sh
More file actions
87 lines (70 loc) · 2.41 KB
/
install.sh
File metadata and controls
87 lines (70 loc) · 2.41 KB
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
#!/bin/sh
set -e
# Check if running on a Kindle
if ! { [ -f "/etc/prettyversion.txt" ] || [ -d "/mnt/us" ] || pgrep "lipc-daemon" >/dev/null; }; then
echo -n "This script must run on a Kindle device. Do you want to run it anyway? [y/N]: "
read -r kindle_override_choice
if [ "$kindle_override_choice" = "y" ] || [ "$kindle_override_choice" = "Y" ]; then
:
else
exit 1
fi
fi
# Variables
API_URL="https://api.github.com/repos/justrals/KindleFetch/commits"
REPO_URL="https://github.com/justrals/KindleFetch/archive/refs/heads/main.zip"
ZIP_FILE="/mnt/us/repo.zip"
EXTRACTED_DIR="/mnt/us/KindleFetch-main"
INSTALL_DIR="/mnt/us/extensions/kindlefetch"
CONFIG_FILE="$INSTALL_DIR/bin/kindlefetch_config"
TEMP_CONFIG="/mnt/us/kindlefetch_config"
ZLIB_COOKIES_FILE="$INSTALL_DIR/bin/zlib_cookies.txt"
TEMP_ZLIB_COOKIES_FILE="/mnt/us/zlib_cookies.txt"
VERSION_FILE="$INSTALL_DIR/bin/.version"
get_version() {
api_response=$(curl -s -H "Accept: application/vnd.github.v3+json" "$API_URL") || {
echo "Warning: Failed to fetch version from GitHub API" >&2
echo "unknown"
return
}
latest_sha=$(echo "$api_response" | grep -m1 '"sha":' | cut -d'"' -f4 | cut -c1-7)
if [ -n "$latest_sha" ]; then
echo "${latest_sha}"
fi
}
if [ -f "$CONFIG_FILE" ]; then
echo "Backing up existing config..."
cp -f "$CONFIG_FILE" "$TEMP_CONFIG"
fi
if [ -f "$ZLIB_COOKIES_FILE" ]; then
echo "Backing up existing zlib cookies..."
cp -f "$ZLIB_COOKIES_FILE" "$TEMP_ZLIB_COOKIES_FILE"
fi
echo "Downloading KindleFetch..."
curl -s -L -o "$ZIP_FILE" "$REPO_URL"
echo "Download complete."
echo "Extracting files..."
unzip -o "$ZIP_FILE" -d "/mnt/us"
echo "Extraction complete."
rm -f "$ZIP_FILE"
echo "Removing old installation..."
rm -rf "$INSTALL_DIR"
echo "Installing KindleFetch..."
mkdir -p "$INSTALL_DIR"
mv -f "$EXTRACTED_DIR/kindlefetch"/* "$INSTALL_DIR/"
echo "Installation successful."
echo "Creating version file..."
VERSION=$(get_version)
mkdir -p "$INSTALL_DIR/bin"
echo "$VERSION" > "$VERSION_FILE"
if [ -f "$TEMP_CONFIG" ]; then
echo "Restoring configuration..."
mv -f "$TEMP_CONFIG" "$CONFIG_FILE"
fi
if [ -f "$TEMP_ZLIB_COOKIES_FILE" ]; then
echo "Restoring zlib cookies..."
mv -f "$TEMP_ZLIB_COOKIES_FILE" "$ZLIB_COOKIES_FILE"
fi
echo "Cleaning up..."
rm -rf "$EXTRACTED_DIR"
echo "KindleFetch installation completed successfully. Version: $VERSION"