├── .gitignore ├── README.md └── nativefier-appimage /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nativefier-appimage 2 | 3 | A tool to generate AppImages of a website using [Nativefier](https://github.com/jiahaog/nativefier). 4 | 5 | ``` 6 | Usage : 7 | nativefier-appimage -- name --url --icon 8 | 9 | : Name of the application. 10 | : Url of the webpage to package. 11 | : Path to the icon file. 12 | ``` 13 | 14 | # Examples 15 | 16 | ``` 17 | nativefier-appimage --name Nitrux --url https://nxos.org --icon nx-logo.png 18 | ``` 19 | 20 | # Requirements 21 | - npm. 22 | - FUSE. 23 | 24 | # Issues 25 | If you find problems with the contents of this repository please create an issue. 26 | 27 | ©2020 Nitrux Latinoamericana S.C. 28 | -------------------------------------------------------------------------------- /nativefier-appimage: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################################################################################################################# 4 | # The license used for this file and its contents is: BSD-3-Clause # 5 | # # 6 | # Copyright <2020> > # 7 | # Copyright <2023-2024> > # 8 | # # 9 | # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: # 10 | # # 11 | # 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. # 12 | # # 13 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer # 14 | # in the documentation and/or other materials provided with the distribution. # 15 | # # 16 | # 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software # 17 | # without specific prior written permission. # 18 | # # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # 20 | # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS # 21 | # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # 22 | # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # 23 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # 24 | ############################################################################################################################################################################# 25 | 26 | set -euo pipefail 27 | 28 | 29 | # -- Function to display help text. 30 | 31 | show_help() { 32 | cat << EOF 33 | Usage: ${0##*/} [-h] [-v] --name --url --icon [--extra ] 34 | 35 | -h, --help Display this help and exit 36 | -v, --version Output version information and exit 37 | --name Name of the application 38 | --url URL of the webpage to package 39 | --icon Icon of the appimage 40 | --extra Extra nativefier options 41 | EOF 42 | } 43 | 44 | 45 | # -- Function to print version. 46 | 47 | show_version() { 48 | echo "nativefier-appimage version 1.2" 49 | } 50 | 51 | 52 | # -- Function to print error messages. 53 | 54 | print_error() { 55 | echo "Error: $1" >&2 56 | exit 1 57 | } 58 | 59 | 60 | # -- URL and Path validation function. 61 | 62 | validate_url() { 63 | local url="$1" 64 | if ! [[ $url =~ ^https?://[a-zA-Z0-9./?=_-]+$ ]]; then 65 | print_error "Invalid URL: $url" 66 | fi 67 | } 68 | 69 | validate_path() { 70 | local path="$1" 71 | if ! [ -e "$path" ]; then 72 | print_error "Invalid path: $path" 73 | fi 74 | } 75 | 76 | 77 | # -- Additional options for Nativefier. 78 | 79 | extra_nativefier_opts="--enable-es3-apis --ignore-gpu-blacklist" 80 | 81 | 82 | # -- Parse arguments. 83 | 84 | while :; do 85 | if [ -z "${1:-}" ]; then 86 | break 87 | fi 88 | case $1 in 89 | -h|--help) 90 | show_help 91 | exit 92 | ;; 93 | -v|--version) 94 | show_version 95 | exit 96 | ;; 97 | --name) 98 | if [ -n "${2:-}" ]; then 99 | name=$2 100 | shift 101 | else 102 | print_error "--name requires a non-empty option argument." 103 | fi 104 | ;; 105 | --url) 106 | if [ -n "${2:-}" ]; then 107 | url=$2 108 | shift 109 | else 110 | print_error "--url requires a non-empty option argument." 111 | fi 112 | ;; 113 | --icon) 114 | if [ -n "${2:-}" ]; then 115 | icon=$2 116 | shift 117 | else 118 | print_error "--icon requires a non-empty option argument." 119 | fi 120 | ;; 121 | --extra) 122 | if [ -n "${2:-}" ]; then 123 | extra_nativefier_opts=$2 124 | shift 125 | else 126 | print_error "--extra requires a non-empty option argument." 127 | fi 128 | ;; 129 | --) 130 | shift 131 | break 132 | ;; 133 | *) 134 | break 135 | esac 136 | shift 137 | done 138 | 139 | 140 | # -- Validate required arguments. 141 | 142 | [ -z "${name:-}" ] && print_error "Missing required argument: --name" 143 | [ -z "${url:-}" ] && print_error "Missing required argument: --url" 144 | [ -z "${icon:-}" ] && print_error "Missing required argument: --icon" 145 | 146 | 147 | # -- Check for dependencies. 148 | 149 | command -v npx >/dev/null 2>&1 || print_error "npx command not found. Please install it." 150 | command -v wget >/dev/null 2>&1 || print_error "wget command not found. Please install it." 151 | 152 | 153 | # -- Function to download or copy icon. 154 | 155 | process_icon() { 156 | local icon_path="$1" 157 | local icon_name 158 | icon_name=$(basename "$icon_path" | cut -d '?' -f 1) || print_error "Failed to process icon name from $icon_path" 159 | 160 | if [[ "$icon_path" = http* ]]; then 161 | echo "Downloading $icon_name from $icon_path" 162 | wget -q -O "$icon_name" "$icon_path" || print_error "Failed to download icon from $icon_path" 163 | elif [ -e "$icon_path" ]; then 164 | echo "Copying $icon_name from $icon_path" 165 | cp "$icon_path" "./$icon_name" || print_error "Failed to copy icon from $icon_path" 166 | else 167 | print_error "Invalid icon URL/path. Please provide a valid HTTP link or a local path." 168 | fi 169 | } 170 | 171 | 172 | # -- Function to create desktop entry and AppRun script. 173 | 174 | create_desktop_entry() { 175 | local app_name="$1" 176 | local icon_name="$2" 177 | 178 | { 179 | echo "[Desktop Entry]" 180 | echo "Name=$app_name" 181 | echo "Exec=AppRun %U $extra_nativefier_opts" 182 | echo "Terminal=false" 183 | echo "Type=Application" 184 | echo "Icon=${icon_name%.*}" 185 | echo "X-AppImage-Version=1.0.0" 186 | echo "Categories=Utility;" 187 | } > "$app_name.desktop" 188 | 189 | { 190 | echo "#!/bin/bash" 191 | echo "exec \"\$APPDIR/$app_name\"" 192 | } > AppRun 193 | chmod +x ./AppRun 194 | } 195 | 196 | 197 | # -- Check for existing AppDir and create AppImage. 198 | 199 | create_appimage() { 200 | local app_name="$1" 201 | local app_url="$2" 202 | local icon_path="$3" 203 | local extra_nativefier_opts="$4" 204 | 205 | if [ -d "$app_name.AppDir" ]; then 206 | echo "WARNING: \`$app_name.AppDir\` directory already exists. Deleting it." 207 | rm -rf "$app_name.AppDir" || print_error "Failed to remove existing AppDir." 208 | rm -rf "$app_name-$(uname --machine).AppImage" || print_error "Failed to remove existing AppImage." 209 | fi 210 | 211 | npx nativefier -n "$app_name" -p linux "$app_url" "$extra_nativefier_opts" || print_error "Failed to create AppDir with nativefier." 212 | mv "$app_name"-linux-* "$app_name.AppDir" || print_error "Failed to move AppDir." 213 | 214 | cd "$app_name.AppDir/" || print_error "Failed to change directory to $app_name.AppDir." 215 | 216 | process_icon "$icon_path" 217 | create_desktop_entry "$app_name" "$(basename "$icon_path" | cut -d '?' -f 1)" 218 | 219 | cp "$(basename "$icon_path" | cut -d '?' -f 1)" "resources/app/icon.png" || print_error "Failed to replace icon.png" 220 | 221 | cd - 222 | 223 | if [ ! -e /tmp/appimagetool ]; then 224 | echo "Downloading appimagetool..." 225 | wget -O /tmp/appimagetool "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" \ 226 | || print_error "Failed to download appimagetool." 227 | chmod +x /tmp/appimagetool 228 | fi 229 | 230 | /tmp/appimagetool "$app_name.AppDir" || print_error "Failed to create AppImage." 231 | 232 | echo "Removing temporary AppDir..." 233 | cd .. || print_error "Failed to change directory for AppDir removal." 234 | rm -rf "$app_name.AppDir" || print_error "Failed to remove AppDir." 235 | } 236 | 237 | 238 | # -- Main execution. 239 | 240 | create_appimage "$name" "$url" "$icon" "$extra_nativefier_opts" 241 | --------------------------------------------------------------------------------