@@ -88,6 +88,33 @@ trap cleanup EXIT # Register the cleanup function to be called on script exit.
8888
8989TMP_DIR=$( mktemp -d)
9090
91+ # Check Ubuntu Version Function
92+ #
93+ # Purpose:
94+ # This function checks if the current operating system is Ubuntu 24.04. It does this by reading
95+ # the /etc/os-release file, which contains identification data for the operating system.
96+ #
97+ # Behavior:
98+ # 1. The function first checks if the /etc/os-release file exists.
99+ # 2. If the file exists, it sources the file to load the OS identification variables.
100+ # 3. It then checks if the ID variable is set to "ubuntu" and the VERSION_ID variable is set to "24.04".
101+ # 4. If both conditions are met, the function returns 0 (indicating success).
102+ # 5. If the conditions are not met, the function returns 1 (indicating failure).
103+ #
104+ # Usage:
105+ # This function can be called to determine if special handling is needed for Ubuntu 24.04, such as
106+ # installing additional libraries or making compatibility adjustments.
107+ #
108+ # Example:
109+ # if check_ubuntu_version; then
110+ # echo "Ubuntu 24.04 detected."
111+ # else
112+ # echo "Not Ubuntu 24.04."
113+ # fi
114+ #
115+ # Notes:
116+ # - This function assumes that the /etc/os-release file follows the standard format for Linux OS
117+ # identification.
91118check_ubuntu_version () {
92119 if [ -f /etc/os-release ]; then
93120 . /etc/os-release
@@ -230,10 +257,46 @@ install_dependencies() {
230257 esac
231258}
232259download_and_install_gtk () {
260+ # Function: create_launch_script_with_gtk
261+ #
262+ # Purpose:
263+ # This function creates a launch script for the Phoenix Code application that sets the required
264+ # GTK library paths in the LD_LIBRARY_PATH environment variable. The launch script ensures that
265+ # the Phoenix Code application uses the correct GTK libraries, which are included in the
266+ # application's installation directory.
267+ #
268+ # Parameters:
269+ # - binary_path: The path to the directory containing the Phoenix Code binary.
270+ # - binary_name: The name of the Phoenix Code binary file.
271+ #
272+ # Behavior:
273+ # 1. The function renames the original Phoenix Code binary to append ".real" to its name.
274+ # 2. It then creates a new launch script with the original binary name in the same directory.
275+ # 3. The launch script sets the LD_LIBRARY_PATH environment variable to include the path to the
276+ # GTK libraries located in the same directory as the binary.
277+ # 4. The launch script executes the original Phoenix Code binary (now renamed) with any
278+ # arguments passed to the script.
279+ # 5. The function sets the appropriate executable permissions on the launch script.
280+ #
281+ # Usage:
282+ # This function should be called after the Phoenix Code binary and its required GTK libraries
283+ # have been installed. It ensures that the application uses the correct libraries when launched.
284+ #
285+ # Example:
286+ # create_launch_script_with_gtk "/path/to/phoenix-code" "phoenix-code"
287+ #
288+ # Notes:
289+ # - This function assumes that the GTK libraries are located in a subdirectory named "gtk" within
290+ # the same directory as the Phoenix Code binary.
291+ # - The function requires the mv, chmod, and cat commands to be available in the environment.
292+ # - This piece of code should only be executed if the package manager does not distribute
293+ # libgtk or if the version provided by the package manager is not compatible with Phoenix Code.
294+
233295 local GTK_URL=" https://github.com/phcode-dev/dependencies/releases/download/v1.0.0/gtk.tar.xz"
234296 local WEBKIT2GTK_URL=" https://github.com/phcode-dev/dependencies/releases/download/v1.0.0/webkit2gtk-4.0.tar.xz"
297+
235298 echo -e " ${YELLOW} Downloading GTK from $GTK_URL ...${RESET} "
236- local destination=" $TMP_DIR /phoenix-code "
299+ local destination=" $TMP_DIR /$BINARY_NAME "
237300 WGET_OPTS=$( configure_wget_options)
238301
239302 wget $WGET_OPTS " $TMP_DIR /gtk.tar.xz" " $GTK_URL " || {
@@ -246,28 +309,67 @@ download_and_install_gtk() {
246309 exit 1
247310 }
248311
249- echo -e " ${YELLOW} Downloading WebKit2GTK from $WEBKIT2GTK_URL ...${RESET} "
250- wget $WGET_OPTS " $TMP_DIR /webkit2gtk-4.0.tar.xz" " $WEBKIT2GTK_URL " || {
251- echo -e " ${RED} Failed to download WebKit2GTK. Please check your internet connection and try again.${RESET} "
252- exit 1
253- }
254- echo " Extracting WebKit2GTK..."
255- tar -xJf " $TMP_DIR /webkit2gtk-4.0.tar.xz" -C " $TMP_DIR " || {
256- echo -e " ${RED} Failed to extract WebKit2GTK. The downloaded file might be corrupt.${RESET} "
257- exit 1
258- }
259- echo " Installing WebKit2GTK..."
260- sudo cp -r " $TMP_DIR /webkit2gtk-4.0" /usr/lib/x86_64-linux-gnu/ || {
261- echo -e " ${RED} Failed to install WebKit2GTK. Please check the permissions and try again.${RESET} "
262- exit 1
263- }
264- echo -e " ${GREEN} WebKit2GTK installed successfully.${RESET} "
312+ if [ ! -d " /usr/lib/x86_64-linux-gnu/webkit2gtk-4.0" ]; then
313+ echo -e " ${YELLOW} Downloading WebKit2GTK from $WEBKIT2GTK_URL ...${RESET} "
314+ wget $WGET_OPTS " $TMP_DIR /webkit2gtk-4.0.tar.xz" " $WEBKIT2GTK_URL " || {
315+ echo -e " ${RED} Failed to download WebKit2GTK. Please check your internet connection and try again.${RESET} "
316+ exit 1
317+ }
318+ echo " Extracting WebKit2GTK..."
319+ tar -xJf " $TMP_DIR /webkit2gtk-4.0.tar.xz" -C " $TMP_DIR " || {
320+ echo -e " ${RED} Failed to extract WebKit2GTK. The downloaded file might be corrupt.${RESET} "
321+ exit 1
322+ }
323+ echo " Installing WebKit2GTK..."
324+ sudo cp -r " $TMP_DIR /webkit2gtk-4.0" /usr/lib/x86_64-linux-gnu/ || {
325+ echo -e " ${RED} Failed to install WebKit2GTK. Please check the permissions and try again.${RESET} "
326+ exit 1
327+ }
328+ echo -e " ${GREEN} WebKit2GTK installed successfully.${RESET} "
329+ else
330+ echo -e " ${GREEN} WebKit2GTK already installed.${RESET} "
331+ fi
265332}
266333
267334
268335create_launch_script_with_gtk () {
336+ # Function: create_launch_script_with_gtk
337+ #
338+ # Purpose:
339+ # This function creates a launch script for the Phoenix Code application that sets the required
340+ # GTK library paths in the LD_LIBRARY_PATH environment variable. The launch script ensures that
341+ # the Phoenix Code application uses the correct GTK libraries, which are included in the
342+ # application's installation directory.
343+ #
344+ # Parameters:
345+ # - binary_path: The path to the directory containing the Phoenix Code binary.
346+ # - binary_name: The name of the Phoenix Code binary file.
347+ #
348+ # Behavior:
349+ # 1. The function renames the original Phoenix Code binary to append ".real" to its name.
350+ # 2. It then creates a new launch script with the original binary name in the same directory.
351+ # 3. The launch script sets the LD_LIBRARY_PATH environment variable to include the path to the
352+ # GTK libraries located in the same directory as the binary.
353+ # 4. The launch script executes the original Phoenix Code binary (now renamed) with any
354+ # arguments passed to the script.
355+ # 5. The function sets the appropriate executable permissions on the launch script.
356+ #
357+ # Usage:
358+ # This function should be called after the Phoenix Code binary and its required GTK libraries
359+ # have been installed. It ensures that the application uses the correct libraries when launched.
360+ #
361+ # Example:
362+ # create_launch_script_with_gtk "/path/to/phoenix-code" "phoenix-code"
363+ #
364+ # Notes:
365+ # - This function assumes that the GTK libraries are located in a subdirectory named "gtk" within
366+ # the same directory as the Phoenix Code binary.
367+ # - The function requires the mv, chmod, and cat commands to be available in the environment.
368+ # - This piece of code should only be executed if the package manager does not distribute
369+ # libgtk or if the version provided by the package manager is not compatible with Phoenix Code.
370+
269371 local binary_path=" $1 "
270- local binary_name=" phoenix-code "
372+ local binary_name=" $BINARY_NAME "
271373
272374 local realBin=" $binary_path /$binary_name .real"
273375 mv " $binary_path /$binary_name " " $realBin "
0 commit comments