Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: code cleanup #418

Merged
merged 2 commits into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 53 additions & 40 deletions docs/linux/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -257,43 +257,47 @@ install_dependencies() {
esac
}
download_and_install_gtk() {
# Function: create_launch_script_with_gtk
#
# Purpose:
# This function creates a launch script for the Phoenix Code application that sets the required
# GTK library paths in the LD_LIBRARY_PATH environment variable. The launch script ensures that
# the Phoenix Code application uses the correct GTK libraries, which are included in the
# application's installation directory.
#
# Parameters:
# - binary_path: The path to the directory containing the Phoenix Code binary.
# - binary_name: The name of the Phoenix Code binary file.
#
# Behavior:
# 1. The function renames the original Phoenix Code binary to append ".real" to its name.
# 2. It then creates a new launch script with the original binary name in the same directory.
# 3. The launch script sets the LD_LIBRARY_PATH environment variable to include the path to the
# GTK libraries located in the same directory as the binary.
# 4. The launch script executes the original Phoenix Code binary (now renamed) with any
# arguments passed to the script.
# 5. The function sets the appropriate executable permissions on the launch script.
#
# Usage:
# This function should be called after the Phoenix Code binary and its required GTK libraries
# have been installed. It ensures that the application uses the correct libraries when launched.
#
# Example:
# create_launch_script_with_gtk "/path/to/phoenix-code" "phoenix-code"
#
# Notes:
# - This function assumes that the GTK libraries are located in a subdirectory named "gtk" within
# the same directory as the Phoenix Code binary.
# - The function requires the mv, chmod, and cat commands to be available in the environment.
# - This piece of code should only be executed if the package manager does not distribute
# libgtk or if the version provided by the package manager is not compatible with Phoenix Code.

local GTK_URL="https://github.com/phcode-dev/dependencies/releases/download/v1.0.1/gtk.tar.xz"
local WEBKIT2GTK_URL="https://github.com/phcode-dev/dependencies/releases/download/v1.0.1/webkit2gtk-4.0.tar.xz"
# Function: create_launch_script_with_gtk
#
# Purpose:
# This function creates a launch script for the Phoenix Code application that sets the required
# GTK library paths in the LD_LIBRARY_PATH environment variable. The launch script ensures that
# the Phoenix Code application uses the correct GTK libraries, which are included in the
# application's installation directory.
#
# Parameters:
# - binary_path: The path to the directory containing the Phoenix Code binary.
# - binary_name: The name of the Phoenix Code binary file.
#
# Behavior:
# 1. The function renames the original Phoenix Code binary to append ".real" to its name.
# 2. It then creates a new launch script with the original binary name in the same directory.
# 3. The launch script sets the LD_LIBRARY_PATH environment variable to include the path to the
# GTK libraries located in the same directory as the binary.
# 4. The launch script executes the original Phoenix Code binary (now renamed) with any
# arguments passed to the script.
# 5. The function sets the appropriate executable permissions on the launch script.
#
# Usage:
# This function should be called after the Phoenix Code binary and its required GTK libraries
# have been installed. It ensures that the application uses the correct libraries when launched.
#
# Example:
# create_launch_script_with_gtk "/path/to/phoenix-code" "phoenix-code"
#
# Notes:
# - This function assumes that the GTK libraries are located in a subdirectory named "gtk" within
# the same directory as the Phoenix Code binary.
# - The function requires the mv, chmod, and cat commands to be available in the environment.
# - This piece of code should only be executed if the package manager does not distribute
# libgtk or if the version provided by the package manager is not compatible with Phoenix Code.

local URL_PREFIX="https://github.com/phcode-dev/dependencies/releases/download/v1.0.2/"
local GTK_FILE="gtk.tar.xz"
local WEBKIT2GTK_FILE="webkit2gtk-4.0.tar.xz"

local GTK_URL="${URL_PREFIX}${GTK_FILE}"
local WEBKIT2GTK_URL="${URL_PREFIX}${WEBKIT2GTK_FILE}"

echo -e "${YELLOW}Downloading GTK from $GTK_URL...${RESET}"
local destination="$TMP_DIR/$BINARY_NAME"
Expand All @@ -304,22 +308,31 @@ download_and_install_gtk() {
exit 1
}
echo "Extracting GTK..."
tar -xJf "$TMP_DIR/gtk.tar.xz" -C "$destination" || {
tar -xJf "$TMP_DIR/$GTK_FILE" -C "$destination" || {
echo -e "${RED}Failed to extract GTK. The downloaded file might be corrupt.${RESET}"
exit 1
}

if [ ! -d "/usr/lib/x86_64-linux-gnu/webkit2gtk-4.0" ]; then
echo -e "${YELLOW}Downloading WebKit2GTK from $WEBKIT2GTK_URL...${RESET}"
wget $WGET_OPTS "$TMP_DIR/webkit2gtk-4.0.tar.xz" "$WEBKIT2GTK_URL" || {
wget $WGET_OPTS "$TMP_DIR/$WEBKIT2GTK_FILE" "$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" || {
tar -xJf "$TMP_DIR/$WEBKIT2GTK_FILE" -C "$TMP_DIR" || {
echo -e "${RED}Failed to extract WebKit2GTK. The downloaded file might be corrupt.${RESET}"
exit 1
}

# Inform the user that the next steps require administrative access
echo "The installation of dependencies requires administrative access. You may be prompted to enter your password."

# Check if the script can execute sudo commands without interaction
if ! sudo -n true 2>/dev/null; then
echo "Please enter your password to proceed with the installation of dependencies."
fi

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}"
Expand Down
Loading