-
Notifications
You must be signed in to change notification settings - Fork 0
/
CL_RePoster_Mac_Installer.sh
executable file
·127 lines (110 loc) · 4.09 KB
/
CL_RePoster_Mac_Installer.sh
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
#!/bin/bash
# Define variables
TEMP_DIR=$(mktemp -d)
PROFILE_PATH="$HOME"
DROPBOX_URL="https://dl.dropboxusercontent.com/scl/fi/q8fsxx6mxm3ml5h5cam4t/CraigsList_RePoster_darwin.zip?rlkey=kh5vw02z87jkllfrg12llfzch&dl=1&raw=1"
ZIP_FILE="$TEMP_DIR/CraigsList_RePoster.zip"
EXTRACT_PATH="$PROFILE_PATH/CraigsList_RePoster"
LOG_FILE="$TEMP_DIR/download_extract_log.txt"
ICON_PATH="$EXTRACT_PATH/assets/img/icons/mac/icon.icns"
SHORTCUT_NAME="CraigsList RePoster"
APP_NAME="CraigsList RePoster.app"
APP_PATH="$HOME/Desktop/$APP_NAME"
# Function to clean up previous installation files
cleanup_previous_installation() {
[ -f "$LOG_FILE" ] && rm "$LOG_FILE"
[ -d "$EXTRACT_PATH" ] && rm -rf "$EXTRACT_PATH"
[ -d "$APP_PATH" ] && rm -rf "$APP_PATH"
# Ensure the temporary directory is empty
find "$TEMP_DIR" -mindepth 1 -delete
}
# Display message function
display_message() {
osascript -e "display dialog \"$1\" buttons {\"OK\"} default button \"OK\""
}
# Download and extract function
download_and_extract() {
echo "Downloading CraigsList RePoster..."
if curl -L -o "$ZIP_FILE" "$DROPBOX_URL" 2>&1 | tee -a "$LOG_FILE"; then
echo "Download complete. Extracting files..."
mkdir -p "$EXTRACT_PATH"
if unzip "$ZIP_FILE" -d "$TEMP_DIR" 2>&1 | tee -a "$LOG_FILE"; then
echo "Extraction complete."
mv "$TEMP_DIR/CraigsList_RePoster/"* "$EXTRACT_PATH"
else
echo "An error occurred during extraction. Check the log file for details: $LOG_FILE"
cat "$LOG_FILE"
exit 1
fi
else
echo "An error occurred during download. Check the log file for details: $LOG_FILE"
cat "$LOG_FILE"
exit 1
fi
}
# Check if installation was successful
installation_successful() {
if [ -f "$EXTRACT_PATH/bin/node" ]; then
return 0
else
echo "Node file not found in expected location: $EXTRACT_PATH/bin/node"
return 1
fi
}
# Create launch script function
create_launch_script() {
mkdir -p "$APP_PATH/Contents/MacOS"
mkdir -p "$APP_PATH/Contents/Resources"
echo "APPL????" > "$APP_PATH/Contents/PkgInfo"
cat << EOF > "$APP_PATH/Contents/Info.plist"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>$SHORTCUT_NAME</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.$SHORTCUT_NAME</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleExecutable</key>
<string>run.sh</string>
<key>CFBundleIconFile</key>
<string>icon</string>
</dict>
</plist>
EOF
cat << EOF > "$APP_PATH/Contents/MacOS/run.sh"
#!/bin/bash
cd "$EXTRACT_PATH"
NODE_ENV=production "$EXTRACT_PATH/bin/node" "$EXTRACT_PATH/node_modules/electron/cli.js" "$EXTRACT_PATH" > /dev/null 2>&1 &
EOF
chmod +x "$APP_PATH/Contents/MacOS/run.sh"
# Copy the icon to the application bundle
if [ -f "$ICON_PATH" ]; then
cp "$ICON_PATH" "$APP_PATH/Contents/Resources/icon.icns"
fi
# Ensure Electron uses the custom icon
ELECTRON_APP_PATH="$EXTRACT_PATH/node_modules/electron/dist/Electron.app"
if [ -d "$ELECTRON_APP_PATH" ]; then
cp "$ICON_PATH" "$ELECTRON_APP_PATH/Contents/Resources/electron.icns"
plutil -replace CFBundleName -string "$SHORTCUT_NAME" "$ELECTRON_APP_PATH/Contents/Info.plist"
touch "$ELECTRON_APP_PATH"
fi
# Refresh Finder to recognize the new icon
touch "$APP_PATH"
# killall Finder
}
# Main script execution
cleanup_previous_installation
display_message "This script will now download and install CraigsList RePoster and create a desktop shortcut for it."
download_and_extract
if installation_successful; then
create_launch_script
display_message "CraigsList RePoster is now installed. You can launch it from the desktop shortcut."
else
display_message "An error occurred during the installation. Node file not found in the expected location."
cat "$LOG_FILE"
fi
# Exit the script and leave the terminal open
exit 0