- Actually enable curl to download files.
curl does not handle HTTP redirects and does not give proper exit codes on HTTP statuses indicating errors unless explicitly told to. Since http://pm4linux.sourceforge.net/installer/download.php issues a redirect, this essentially meant that curl would not download the file pointed to. Also, in case of server errors, it would notify the user. This was fixed by using the -L and -f flags. - Fix some compatibility issues with a Linux system that I use.
If the system graces us by keeping (or redeclaring) the XAUTHORITY variable, then the variable inherited from the non-root user will not be used. Copying the value of XAUTHORITY blatantly caused problems on a CentOS 6 install with Xfce and xdm as the actual path of XAUTHORITY for the root user was different than the non-root user. - Make use of "fold" for userdocs/README
... so that devs don't have to word wrap this file manually. Note that the word wrapping happens when a copy of this file is put into the *.tar.bz2. - Rename some cryptically named functions.
Self explanatory. - Add command line switches to enable changing of URLs and to disable minification and cleanup.
Added the switches --base-url, --no-minify and --no-cleanup for the above respective functions. The last two are useful for debugging and the first one is to provide a formal way of changing the URL rather than just passing it as the first arg of the compile script. - Make the necessary documentation changes for the former discussed change.
Self explanatory.
Code: Select all
diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -1,21 +1,18 @@
-# README for pminstaller source
+# README for PM4Linux-installer source
---
+PM4Linux-installer, also referred to as pminstaller, is a program that is meant
+to ease installation of the Pale Moon binaries on Linux, made available on
+pm4linux.sourceforge.net.
+
## Compiling from source
To compile from source, type in the following:
./compile
-You can use a custom hostname/IP address instead of always having to contact
-Sourceforge:
-
- ./compile 10.0.2.2
-
-You can also specify a directory in this manner:
-
- ./compile 10.0.2.2/foo
+A full list of options can be retrieved by executing `./compile --help`.
## Technical details
@@ -40,7 +37,7 @@ following manner:
+-----------------------------------+
| <--minified contents of sfx.sh--> |
- +-----[xz compressed tar data]------|
+ |-----[xz compressed tar data]------|
|bin/ |
| [...] |
|tools/ |
diff --git a/compile b/compile
--- a/compile
+++ b/compile
@@ -2,21 +2,66 @@
# Compile the scripts into a single self-extracting script and package it within a *.tar.bz2
+show_help () {
+ echo "Usage: $0 [OPTIONS]"
+ cat << EOM
+Compile the scripts into a single self-extracting script and package it within a
+*.tar.bz2.
+
+Options:
+--base-url=URL Use a custom base URL instead of the default
+--no-minify Don't minify scripts
+--no-cleanup Don't remove temporary files from build/ directory.
+
+EOM
+}
+
+show_error_msg () {
+ echo "Argument not recognised: $1"
+ echo "Please type $0 --help for help."
+}
+
# Exit on most errors
set -e
unset CDPATH
+while [[ ! -z "$1" ]]; do
+ case "$1" in
+ --base-url=*)
+ base_url="$(echo "$1" | sed -r 's|^--base-url=||g;s|/$||g')"
+ if [[ ! $base_url =~ ^(https?|ftp)://[a-z0-9_.]+/.*$ ]]; then
+ echo "The base URL is not valid!"
+ exit 1
+ fi
+ shift
+ ;;
+ --no-minify)
+ no_minify=1
+ shift
+ ;;
+ --no-cleanup)
+ no_cleanup=1
+ shift
+ ;;
+ --help)
+ show_help
+ exit 0
+ ;;
+ *)
+ show_error_msg "$1"
+ exit 1
+ esac
+done
+
pkgfileslist=("bin" "tools" "files" "installer.sh")
sfxscript="sfx.sh"
readmefile="userdocs/README"
installer="pminstaller.sh"
archive="pminstaller.tar.bz2"
-if [[ -z "$1" ]]; then
- pm_hostname="pm4linux.sourceforge.net"
-else
- pm_hostname="$1"
+if [[ -z "$base_url" ]]; then
+ base_url="http://pm4linux.sourceforge.net"
fi
cd "$(dirname "$0")"
@@ -28,24 +73,27 @@ fi
echo "Copying required files..."
mkdir build
-cp -rv ${pkgfileslist[@]} "$sfxscript" "$readmefile" build/
+cp -rv ${pkgfileslist[@]} "$sfxscript" build/
+fold -w 80 -s "$readmefile" > build/"$(basename "$readmefile")"
cd build
# Perform required substitutions
echo "Perform required substitutions in the script(s)..."
-sed "s|__HOSTNAME__|$pm_hostname|g" installer.sh > installer.sh.1
+sed "s|__BASE_URL__|$base_url|g" installer.sh > installer.sh.1
mv installer.sh.1 installer.sh
# Minify scripts
-echo "Minifying scripts..."
-while read filename; do
- if head -n 1 "$filename" | grep -E '^#!/bin/(ba)?sh' &> /dev/null; then
- echo "Minifying $filename..."
- # bash_obfus seems to have some problems with stripping indented comments, so...
- "$selfdir/bash_obfus.plx" -i "$filename" -o /dev/stdout -C -F | grep -Ev '^#[^!]' > "$filename.1"
- mv "$filename.1" "$filename"
- fi
-done < <(find . -type f ! -wholename "*/files/*")
+if [[ -z $no_minify ]]; then
+ echo "Minifying scripts..."
+ while read filename; do
+ if head -n 1 "$filename" | grep -E '^#!/bin/(ba)?sh' &> /dev/null; then
+ echo "Minifying $filename..."
+ # bash_obfus seems to have some problems with stripping indented comments, so...
+ "$selfdir/bash_obfus.plx" -i "$filename" -o /dev/stdout -C -F | grep -Ev '^#[^!]' > "$filename.1"
+ mv "$filename.1" "$filename"
+ fi
+ done < <(find . -type f ! -wholename "*/files/*")
+fi
# Set permissions
echo "Setting permissions for files in SFX archive..."
@@ -68,4 +116,6 @@ mv "$installer.1" "$installer"
echo "Packaging installer within tarball..."
chmod -v 755 "$installer"
tar --verbose --numeric-owner --group=0 --owner=0 -cjf "$archive" "$(basename "$readmefile")" "$installer"
-find . ! -name "$archive" -delete
+if [[ -z $no_cleanup ]]; then
+ find . ! -name "$archive" -delete
+fi
diff --git a/installer.sh b/installer.sh
--- a/installer.sh
+++ b/installer.sh
@@ -15,7 +15,7 @@ cd "$(dirname "$0")"
installer_dir="$(pwd)"
lockfile_name="/tmp/pminstaller.lock"
-pm_hostname="__HOSTNAME__"
+base_url="__BASE_URL__"
PATH="$installer_dir/bin/$mtype:$installer_dir/tools:$PATH"
pm_archive="$installer_dir/palemoon.tar.bz2"
@@ -61,7 +61,7 @@ stdoutparser ()
}
# Checks if Pale Moon is installed
-pmcheck ()
+pm_is_installed ()
{
which palemoon || [[ -d /opt/palemoon ]] || [[ -d /usr/lib/palemoon ]]
}
@@ -208,20 +208,20 @@ pmupdate_main ()
}
# Retrieve Pale Moon archive
-arch_download ()
+archive_download ()
{
- gwget "http://$pm_hostname/installer/download.php?v=$1&a=$mtype" "$pm_archive"
+ gwget "$base_url/installer/download.php?v=$1&a=$mtype" "$pm_archive"
}
# Retrieve latest version info
-showlatest ()
+get_latest_version ()
{
- gwget "http://$pm_hostname/installer/latest.php" "$installer_dir/latest"
+ gwget "$base_url/installer/latest.php" "$installer_dir/latest"
cat "$installer_dir/latest"
}
# Check version number validity
-versionvalid ()
+is_version_valid ()
{
[[ "$1" =~ ^([0-9]+\.)+[0-9ab]+$ ]]
}
@@ -229,7 +229,7 @@ versionvalid ()
# User facing install operations
pminstall ()
{
- if pmcheck; then
+ if pm_is_installed; then
dlg_e "Another version of Pale Moon is already installed. Please uninstall it first and then install the version you need."
return
fi
@@ -246,16 +246,16 @@ pminstall ()
0)
case "$pm_ver" in
Latest*)
- pm_ver="$(showlatest)"
+ pm_ver="$(get_latest_version)"
- if ! versionvalid "$pm_ver"; then
+ if ! is_version_valid "$pm_ver"; then
dlg_e "The latest version number could not be retrieved!"
else
break
fi
;;
*)
- if ! versionvalid "$pm_ver"; then
+ if ! is_version_valid "$pm_ver"; then
dlg_e "The indicated version number is invalid."
else
break
@@ -266,7 +266,7 @@ pminstall ()
esac
done
- if arch_download "$pm_ver"; then
+ if archive_download "$pm_ver"; then
pminstall_main >& 1 | stdoutparser | dlg_pw "Installing Pale Moon..." applications-system
else
dlg_e "The installation was aborted as the necessary files could not be retrieved."
@@ -276,7 +276,7 @@ pminstall ()
# User facing uninstall operations
pmremove ()
{
- if ! pmcheck; then
+ if ! pm_is_installed; then
dlg_e "Pale Moon is not installed on your computer."
return
fi
@@ -294,20 +294,20 @@ view_license ()
# User facing update operations
pmupdate ()
{
- if ! pmcheck; then
+ if ! pm_is_installed; then
dlg_e "Pale Moon is not installed on your computer."
return
else
- pm_ver="$(showlatest)"
+ pm_ver="$(get_latest_version)"
pm_ver_inst="$(grep -E '^Version=' /opt/palemoon/application.ini | grep -Eo '([0-9]+\.)+[0-9ab]+$')"
- if ! versionvalid "$pm_ver"; then
+ if ! is_version_valid "$pm_ver"; then
dlg_e "The latest version number could not be retrieved!"
return
elif [[ -z "$pm_ver_inst" ]]; then
dlg_e "The version information for the installed version of Pale Moon could not be retrieved. Please reinstall Pale Moon."
elif [[ "$pm_ver_inst" != "$pm_ver" ]]; then
dlg_q "Version $pm_ver is available, would you like to update Pale Moon now?" --button=gtk-yes --button=gtk-no || return
- if arch_download "$pm_ver"; then
+ if archive_download "$pm_ver"; then
pmupdate_main >& 1 | stdoutparser | dlg_pw "Updating Pale Moon..." system-software-update
else
dlg_e "The update was aborted as the necessary files could not be retrieved."
diff --git a/tools/gwget b/tools/gwget
--- a/tools/gwget
+++ b/tools/gwget
@@ -8,8 +8,7 @@ fi
if which wget &>/dev/null; then
wget "$1" -O "$2" 2>&1 | sed -u 's/^[a-zA-Z\-].*//; s/.* \{1,2\}\([0-9]\{1,3\}\)%.*/\1\n#Downloading... \1%/; s/^20[0-9][0-9].*/#Done./' | yad --window-icon=applications-internet --image=gtk-save --geometry=500 --progress --percentage=0 --title "Downloading files..." --text "$(echo "$1" | sed 's/&/&\;/g')" --auto-close --auto-kill --button=gtk-cancel
elif which curl &>/dev/null; then
- # curl support is very much experimental and does not support being cancelled!
- curl "$1" -o "$2" 2>&1 | stdbuf -oL tr '\r' '\n' | sed -ur 's/^\s*([0-9]+).*/\1\n#Downloading... \1%/' | yad --window-icon=applications-internet --image=gtk-save --geometry=500 --progress --percentage=0 --title "Downloading files..." --text "$(echo "$1" | sed 's/&/&\;/g')" --auto-close --no-buttons
+ curl -Lf "$1" -o "$2" 2>&1 | stdbuf -oL tr '\r' '\n' | sed -ur 's/^\s*([0-9]+).*/\1\n#Downloading... \1%/' | yad --window-icon=applications-internet --image=gtk-save --geometry=500 --progress --percentage=0 --title "Downloading files..." --text "$(echo "$1" | sed 's/&/&\;/g')" --auto-close --no-buttons
else
exit 2
fi
diff --git a/tools/runasroot b/tools/runasroot
--- a/tools/runasroot
+++ b/tools/runasroot
@@ -17,10 +17,14 @@ dlg_e ()
create_tmp_script ()
{
tmp_script=$(mktemp /tmp/runasroot.XXXXXXXXX)
- printf "#!/bin/bash\nexport DISPLAY='$DISPLAY'\nexport XAUTHORITY='$XAUTHORITY'\nexec \"\$@\"" >> $tmp_script
+ printf "\
+#!/bin/bash
+export DISPLAY='$DISPLAY'
+[[ -z \$XAUTHORITY ]] && export XAUTHORITY='$XAUTHORITY'
+exec \"\$@\"" >> $tmp_script
chmod +x $tmp_script
}
-
+
if [[ -z "$1" ]]; then
echo "Usage: $0 [command]"
exit 0
diff --git a/userdocs/README b/userdocs/README
--- a/userdocs/README
+++ b/userdocs/README
@@ -5,34 +5,21 @@
## Using the installer
- Extract the contents of the archive to your home directory.
-- Run the "pminstaller.sh" script from the file manager by double clicking on
- it. If, however, this does not work for a some reason, then, type the
- following in the terminal:
+- Open a terminal emulator window, type the following and hit enter.
~/pminstaller.sh
- (Assuming the "pminstaller.sh" script is placed in the home directory, as
- instructed above).
+ (Assuming the "pminstaller.sh" script is placed in the home directory, as instructed above).
- Follow the on-screen prompts and continue.
Note:
-- The installer may not run on some "lightweight" distributions since the
- standard command line tools use busybox (which does not implement all features
- of the required command line tools).
-- If the installer does not run because the built-in copy of yad complains about
- being unable to load a particular library, then you clearly do not have the
- the basic dependencies required for any recent Mozilla based product. Please
- update the related libraries and try again.
-- If you have any specialised requirements that the installer does not serve out
- of the box, then please use the command line instructions in the
- [pm4linux wiki](http://pm4linux.sf.net/wiki) for installing Pale Moon.
+- The installer may not run on some "lightweight" distributions since the standard command line tools use busybox (which does not implement all features of the required command line tools).
+- If the installer does not run because the built-in copy of yad complains about being unable to load a particular library, then you clearly do not have the basic dependencies required for any recent Mozilla based product. Please update the related libraries and try again.
+- If you have any specialised requirements that the installer does not serve out of the box, then please use the command line instructions in the [pm4linux wiki](http://pm4linux.sf.net/wiki) for installing Pale Moon.
## Support
-Some help documentation is available on the [pm4linux wiki]
-(http://pm4linux.sf.net/wiki). You can also discuss them in the dedicated Linux
-board of the [Pale Moon forum](http://forum.palemoon.org/).
+Some help documentation is available on the [pm4linux wiki] (http://pm4linux.sf.net/wiki). You can also discuss them in the dedicated Linux board of the [Pale Moon forum](http://forum.palemoon.org/).
-Please note that support is not provided for old versions of the installer.
-Please use the latest version of the installer at all times.
+Please note that support is not provided for old versions of the installer. Please use the latest version of the installer at all times.