Skip to content

Commit

Permalink
feat: support for ubuntu 24.04
Browse files Browse the repository at this point in the history
  • Loading branch information
charlypa committed May 26, 2024
1 parent ecf63a7 commit e4f0600
Showing 1 changed file with 70 additions and 26 deletions.
96 changes: 70 additions & 26 deletions docs/linux/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ DESKTOP_DIR=$HOME/.local/share/applications # Directory for desktop entries
GITHUB_REPO="phcode-dev/phoenix-desktop"
API_URL="https://api.github.com/repos/$GITHUB_REPO/releases/latest"
ICON_URL="https://updates.phcode.io/icons/phoenix_icon.png"
GTK_URL="https://github.com/phcode-dev/dependencies/releases/download/v1.0.0/gtk.tar.xz"
WEBKIT2GTK_URL="https://github.com/phcode-dev/dependencies/releases/download/v1.0.0/webkit2gtk-4.0.tar.xz"
INSTALL_DIR="$HOME/.phoenix-code"
LINK_DIR="$HOME/.local/bin"
DESKTOP_ENTRY_NAME="PhoenixCode.desktop"
Expand Down Expand Up @@ -90,18 +92,10 @@ check_ubuntu_version() {
if [ -f /etc/os-release ]; then
. /etc/os-release
if [[ "$ID" = "ubuntu" && "$VERSION_ID" = "24.04" ]]; then
local latestFileUrl
latestFileUrl=$(grep -oP 'https://[^"]*latest\.json' "$TMP_DIR/latest_release.json")
WGET_OPTS=$(configure_wget_options)

wget $WGET_OPTS "$TMP_DIR/latest.json" "$latestFileUrl" || {
echo -e "${RED}Failed to download the latestFile. Please check your internet connection and try again.${RESET}"
}
echo -e "${RED}Ubuntu 24.04 LTS is not currently supported by this installation script.${RESET}"
echo -e "${YELLOW}Please use an earlier version of Ubuntu for the time being. Check back later for updates.${RESET}"
exit 1
return 0 # Ubuntu 24.04 detected
fi
fi
return 1 # Not Ubuntu 24.04
}
# Create Invocation Script Function
#
Expand Down Expand Up @@ -235,6 +229,59 @@ install_dependencies() {
;;
esac
}

download_and_install_gtk() {
echo -e "${YELLOW}Downloading GTK from $GTK_URL...${RESET}"
local destination="$TMP_DIR/phoenix-code"
WGET_OPTS=$(configure_wget_options)

wget $WGET_OPTS "$TMP_DIR/gtk.tar.xz" "$GTK_URL" || {
echo -e "${RED}Failed to download GTK. Please check your internet connection and try again.${RESET}"
exit 1
}
echo "Extracting GTK..."
tar -xJf "$TMP_DIR/gtk.tar.xz" -C "$destination" || {
echo -e "${RED}Failed to extract GTK. The downloaded file might be corrupt.${RESET}"
exit 1
}

echo -e "${YELLOW}Downloading WebKit2GTK from $WEBKIT2GTK_URL...${RESET}"
wget $WGET_OPTS "$TMP_DIR/webkit2gtk-4.0.tar.xz" "$WEBKIT2GTK_URL" || {
echo -e "${RED}Failed to download WebKit2GTK. Please check your internet connection and try again.${RESET}"
exit 1
}
echo "Extracting WebKit2GTK..."
tar -xJf "$TMP_DIR/webkit2gtk-4.0.tar.xz" -C "$TMP_DIR" || {
echo -e "${RED}Failed to extract WebKit2GTK. The downloaded file might be corrupt.${RESET}"
exit 1
}
echo "Installing WebKit2GTK..."
sudo cp -r "$TMP_DIR/webkit2gtk-4.0" /usr/lib/x86_64-linux-gnu/ || {
echo -e "${RED}Failed to install WebKit2GTK. Please check the permissions and try again.${RESET}"
exit 1
}
echo -e "${GREEN}WebKit2GTK installed successfully.${RESET}"
}


create_launch_script_with_gtk() {
local binary_path="$1"
local binary_name="phoenix-code"

local realBin="$binary_path/$binary_name.real"
mv "$binary_path/$binary_name" "$realBin"
echo "Creating a launch script for Phoenix Code with GTK libraries..."
cat > "$binary_path/$binary_name" <<EOF
#!/bin/bash
SCRIPT_DIR=\$(dirname "\$(readlink -f "\$0")")
export LD_LIBRARY_PATH=\$SCRIPT_DIR/gtk:\$LD_LIBRARY_PATH
exec \$SCRIPT_DIR/$binary_name.real "\$@"
EOF
chmod +x "$binary_path/$binary_name"

echo -e "Launch script created at: $binary_path/$binary_name"
}

# Verify and Install Dependencies Function
#
# Purpose:
Expand Down Expand Up @@ -276,29 +323,26 @@ install_dependencies() {
# application to run properly.
#
verify_and_install_dependencies() {
cd "$TMP_DIR/phoenix-code"
# Ensure the binary is executable
chmod +x "./phoenix-code"
# First attempt to verify the application launch
if ./phoenix-code --runVerify; then
if "$TMP_DIR/phoenix-code/phoenix-code" --runVerify; then
echo "Application launch verification successful."
return 0 # Exit the function successfully if verification succeeds
return 0
else
# Check Ubuntu version for compatibility
check_ubuntu_version
echo "Initial verification failed. Attempting to install dependencies..."
install_dependencies # Function to install required dependencies
if check_ubuntu_version; then
echo -e "${YELLOW}Ubuntu 24.04 detected. Attempting to download and install GTK and WebKit2GTK...${RESET}"
download_and_install_gtk
create_launch_script_with_gtk "$TMP_DIR/phoenix-code"
else
echo "Initial verification failed. Attempting to install dependencies..."
install_dependencies
fi
fi

# Second attempt to verify the application launch after installing dependencies
if ./phoenix-code --runVerify; then
if "$TMP_DIR/phoenix-code/phoenix-code" --runVerify; then
echo "Application launch verification successful after installing dependencies."
cd -
return 0 # Exit the function successfully if verification succeeds
return 0
else
echo "Verification failed even after installing dependencies. Please check the application requirements or contact support."
cd -
return 1 # Return an error code to indicate failure
return 1
fi
}
# Set Phoenix Code as the default application for specified MIME types
Expand Down

0 comments on commit e4f0600

Please sign in to comment.