-
Notifications
You must be signed in to change notification settings - Fork 40
This script can be added to the warehouse #229
Description
This second version handles internet connectivity well; if there is no internet connection, it skips the step and fetches the Panda file directly. Look carefully, there are two versions.
1- This script downloads the application from Flathub, installs it on the device if it is not already present, then takes the program from the local Flatpak repository in the system /var/lib/flatpak/repo or ~/.local/share/flatpak/repo, automatically detects the location of the Flatpak application whether it is in system or user, and converts it into a Bundle file, building the bundle file.
Copy the Bash Script Code completely from beginning to end, paste it into the terminal, press the Enter key, and then grant it permissions.
✅ 1 Code Bash Script 👇👇
sudo tee /usr/local/bin/flatpak_bundle << 'EOF'
#!/usr/bin/env bash
Loop to restart the program upon completion
while true; do
clear # Clear the screen to start a new reload process
echo "=========================================="
echo " Flatpak Local Bundle Builder (v4) 🚀"
echo "=========================================="
# Determine the current working path for saving
# Current Directory for saving
OUTPUT_DIR=$(pwd)
echo "Current Directory: $OUTPUT_DIR"
# Request the package ID from the user and avoid hidden spaces
# Enter ID (Application or Runtime)
read -rp "Enter ID (Application or Runtime): " RAW_INPUT
# Clean input from any hidden characters or extra spaces to prevent Invalid ID errors
TARGET_ID=$(echo "$RAW_INPUT" | xargs | awk '{print $NF}')
if [ -z "$TARGET_ID" ]; then
echo "❌ Error: ID is required."
sleep 2
continue
fi
echo "🔍 Checking installation..."
# Checking installed versions
INSTALLED_DATA=$(flatpak list --all --columns=application,branch,installation | grep -w "^$TARGET_ID")
# If the app is not installed, check connectivity first, then try to download
if [ -z "$INSTALLED_DATA" ]; then
# Use curl for checking to ensure connectivity accuracy and update languages exclusively
echo "🌐 Checking connectivity via curl..."
# Verify the ability to actually access the Flathub website within a 5-second timeframe
if curl -s --head --connect-timeout 5 https://google.com > /dev/null; then
echo "📥 App not found locally. Attempting to download from Flathub..."
flatpak install -y flathub "$TARGET_ID"
# Re-verify the installation after attempting
INSTALLED_DATA=$(flatpak list --all --columns=application,branch,installation | grep -w "^$TARGET_ID")
else
echo "❌ Error: Offline. Cannot download ($TARGET_ID) without internet."
sleep 3
continue
fi
fi
# Error if package is not found (in case installation fails despite having internet)
if [ -z "$INSTALLED_DATA" ]; then
echo "------------------------------------------"
echo "❌ Error: The package ($TARGET_ID) is not installed and could not be downloaded."
echo "⚠️ Please check the App ID or Flathub availability."
echo "------------------------------------------"
read -rp "Do you want to try another ID? [Y/n] : " RETRY
[[ "$RETRY" =~ ^[Nn]$ ]] && break || continue
fi
# A variable to track the internet connection status for subsequent updates
IS_OFFLINE=false
# Re-verify to ensure connection stability before updating languages
if curl -s --head --connect-timeout 5 https://google.com > /dev/null; then
echo "✅ Online: Updating subpaths and languages..."
flatpak update -y --subpath= --subpath=/ "$TARGET_ID" || echo "⚠️ Subpath update failed."
else
echo "⚠️ Offline: Skipping update, proceeding with local files..."
IS_OFFLINE=true
fi
# Handling multiple branches and displaying them within a coordinated box selecting a branch
# Intelligent processing to merge system/user paths for each branch to prevent duplication
FORMATTED_LIST=$(echo "$INSTALLED_DATA" | awk '{
if (map[$2] == "") map[$2] = $3;
else if (map[$2] !~ $3) map[$2] = map[$2] "/" $3;
} END {
for (br in map) print br, map[br]
}')
COUNT=$(echo "$FORMATTED_LIST" | wc -l)
if [ "$COUNT" -gt 1 ]; then
echo "⚠️ Multiple branches found:"
echo "┌──────────────────────────────────────────────────────────┐"
# Display branches without duplication with system/user merged in one line
echo "$FORMATTED_LIST" | while read -r br loc; do
printf "│ Branch: %-50s │\n" "$br $loc"
done
echo "└──────────────────────────────────────────────────────────┘"
read -rp "Enter Branch Name: " SELECTED_BRANCH
FINAL_LOC=$(echo "$FORMATTED_LIST" | grep "^$SELECTED_BRANCH " | awk '{print $2}')
else
# Automatic selection if there is only one branch
SELECTED_BRANCH=$(echo "$FORMATTED_LIST" | awk '{print $1}')
FINAL_LOC=$(echo "$FORMATTED_LIST" | awk '{print $2}')
echo "✨ Auto-selected Branch: $SELECTED_BRANCH ($FINAL_LOC)"
fi
# Technical Data & Repo Path Extraction
FULL_INFO_REF="$TARGET_ID//$SELECTED_BRANCH"
# Repo Path Determination (system or user)
if [[ "$FINAL_LOC" == *"system"* ]]; then
REPO="/var/lib/flatpak/repo"
APP_INFO=$(flatpak info --system "$FULL_INFO_REF")
else
REPO="$HOME/.local/share/flatpak/repo"
APP_INFO=$(flatpak info --user "$FULL_INFO_REF")
fi
FULL_REF=$(echo "$APP_INFO" | grep "Ref:" | awk '{print $2}')
TYPE=$(echo "$FULL_REF" | cut -d'/' -f1)
ARCH=$(echo "$FULL_REF" | cut -d'/' -f3)
VERSION=$(echo "$APP_INFO" | grep "Version:" | awk '{print $2}' | tr -d ' ')
VERSION=${VERSION:-latest}
# Prepare the output file in the current folder
OUTPUT_FILE="${TARGET_ID}_${VERSION}_${ARCH}_${SELECTED_BRANCH}.flatpak"
OUTPUT_PATH="$OUTPUT_DIR/$OUTPUT_FILE"
# Building the bundle
RUNTIME_FLAG=""
[ "$TYPE" = "runtime" ] && RUNTIME_FLAG="--runtime"
echo "------------------------------------------"
echo "📍 Repo Path: $REPO"
echo "📦 Type: $TYPE | Branch: $SELECTED_BRANCH"
echo "------------------------------------------"
echo "🚀 Building bundle The package is being built; please wait..."
if flatpak build-bundle $RUNTIME_FLAG "$REPO" "$OUTPUT_PATH" "$TARGET_ID" "$SELECTED_BRANCH" --arch="$ARCH"; then
echo
echo "--------------------------------------"
echo "✅ Bundle created successfully!"
echo "💾 Location File: $OUTPUT_PATH"
echo "--------------------------------------"
else
# If the build fails and the device is offline, a detailed error message appears
echo
if [ "$IS_OFFLINE" = "true" ]; then
echo "------------------------------------------"
echo "❌ The language pack is locally incomplete. The pack cannot be created without an internet connection."
echo "🌐 You must connect to the internet first to update the package."
echo "------------------------------------------"
else
echo "❌ Error: Package build failed. Please make sure the package files are complete."
fi
fi
echo
read -rp "Do you want to enter a new App ID? [Y/n]: " ANSWER
[[ "$ANSWER" =~ ^[Nn]$ ]] && break
done
echo "👋 Exiting..."
EOF
Create a true second copy named flatpak_b in the same folder
sudo cp /usr/local/bin/flatpak_bundle /usr/local/bin/flatpak_b
Grant execution permissions to both files to ensure they work as system commands using the following command
sudo chmod +x /usr/local/bin/flatpak_bundle /usr/local/bin/flatpak_b
Now you can try running it by typing flatpak_bundle or flatpak_b in the terminal to make sure.
2- This script does not download anything if it does not find the program installed; it only informs you of that and does not install it automatically. It only updates the Subpaths languages before building to ensure that the Bundle file contains everything you need. I kept the command flatpak update --subpath because it is very important for making Flatpak collect the application's language and translation files before converting them into a Bundle to ensure they work correctly when transferring to another device offline.
Copy the Bash Script Code completely from beginning to end, paste it into the terminal, press the Enter key, and then grant it permissions.
✅ 2 Code Bash Script 👇👇
sudo tee /usr/local/bin/flatpak_bundle << 'EOF'
#!/usr/bin/env bash
Loop to restart the program upon completion
while true; do
clear # Clear the screen to start a new reload process
echo "=========================================="
echo " Flatpak Local Bundle Builder (v4) 🚀"
echo "=========================================="
# Determine the current working path for saving
# Current Directory for saving
OUTPUT_DIR=$(pwd)
echo "Current Directory: $OUTPUT_DIR"
# Request the package ID from the user and avoid hidden spaces
# Enter ID (Application or Runtime)
read -rp "Enter ID (Application or Runtime): " RAW_INPUT
# Clean input from any hidden characters or extra spaces to prevent Invalid ID errors
TARGET_ID=$(echo "$RAW_INPUT" | xargs | awk '{print $NF}')
if [ -z "$TARGET_ID" ]; then
echo "❌ Error: ID is required."
sleep 2
continue
fi
echo "🔍 Checking installation..."
# Checking installed versions
INSTALLED_DATA=$(flatpak list --all --columns=application,branch,installation | grep -w "^$TARGET_ID")
# Error if package is not found
if [ -z "$INSTALLED_DATA" ]; then
echo "------------------------------------------"
echo "❌ Error: The package ($TARGET_ID) is not installed on your system."
echo "⚠️ Please install it first, then run this script again."
echo "------------------------------------------"
# Instead of the final exit, we move on to asking the user if they want to try another ID
read -rp "Do you want to try another ID? [Y/n]: " RETRY
[[ "$RETRY" =~ ^[Nn]$ ]] && break || continue
fi
# A variable to track the internet connection status
IS_OFFLINE=false
# Use curl for checking to ensure connectivity accuracy and update languages exclusively
echo "🌐 Checking connectivity via curl..."
# Verify the ability to actually access the Flathub website within a 5-second timeframe
if curl -s --head --connect-timeout 5 https://google.com > /dev/null; then
echo "✅ Online: Updating subpaths and languages..."
# The update command is intended for language files only to ensure a fully linguistically complete 'bundle' -y to make the update automatic
flatpak update -y --subpath= --subpath=/ "$TARGET_ID" || echo "⚠️ Subpath update failed."
else
echo "⚠️ Offline: Skipping update, proceeding with local files..."
IS_OFFLINE=true
fi
# Handling multiple branches and displaying them within a coordinated box selecting a branch
# Intelligent processing to merge system/user paths for each branch to prevent duplication
FORMATTED_LIST=$(echo "$INSTALLED_DATA" | awk '{
if (map[$2] == "") map[$2] = $3;
else if (map[$2] !~ $3) map[$2] = map[$2] "/" $3;
} END {
for (br in map) print br, map[br]
}')
COUNT=$(echo "$FORMATTED_LIST" | wc -l)
if [ "$COUNT" -gt 1 ]; then
echo "⚠️ Multiple branches found:"
echo "┌──────────────────────────────────────────────────────────┐"
# Display branches without duplication with system/user merged in one line
echo "$FORMATTED_LIST" | while read -r br loc; do
printf "│ Branch: %-50s │\n" "$br $loc"
done
echo "└──────────────────────────────────────────────────────────┘"
read -rp "Enter Branch Name: " SELECTED_BRANCH
FINAL_LOC=$(echo "$FORMATTED_LIST" | grep "^$SELECTED_BRANCH " | awk '{print $2}')
else
# Automatic selection if there is only one branch
SELECTED_BRANCH=$(echo "$FORMATTED_LIST" | awk '{print $1}')
FINAL_LOC=$(echo "$FORMATTED_LIST" | awk '{print $2}')
echo "✨ Auto-selected Branch: $SELECTED_BRANCH ($FINAL_LOC)"
fi
# Technical Data & Repo Path Extraction
FULL_INFO_REF="$TARGET_ID//$SELECTED_BRANCH"
# Repo Path Determination (system or user)
if [[ "$FINAL_LOC" == *"system"* ]]; then
REPO="/var/lib/flatpak/repo"
APP_INFO=$(flatpak info --system "$FULL_INFO_REF")
else
REPO="$HOME/.local/share/flatpak/repo"
APP_INFO=$(flatpak info --user "$FULL_INFO_REF")
fi
FULL_REF=$(echo "$APP_INFO" | grep "Ref:" | awk '{print $2}')
TYPE=$(echo "$FULL_REF" | cut -d'/' -f1)
ARCH=$(echo "$FULL_REF" | cut -d'/' -f3)
VERSION=$(echo "$APP_INFO" | grep "Version:" | awk '{print $2}' | tr -d ' ')
VERSION=${VERSION:-latest}
# Prepare the output file in the current folder
OUTPUT_FILE="${TARGET_ID}_${VERSION}_${ARCH}_${SELECTED_BRANCH}.flatpak"
OUTPUT_PATH="$OUTPUT_DIR/$OUTPUT_FILE"
# Building the bundle
RUNTIME_FLAG=""
[ "$TYPE" = "runtime" ] && RUNTIME_FLAG="--runtime"
echo "------------------------------------------"
echo "📍 Repo Path: $REPO"
echo "📦 Type: $TYPE | Branch: $SELECTED_BRANCH"
echo "------------------------------------------"
echo "🚀 Building bundle The package is being built; please wait..."
if flatpak build-bundle $RUNTIME_FLAG "$REPO" "$OUTPUT_PATH" "$TARGET_ID" "$SELECTED_BRANCH" --arch="$ARCH"; then
echo
echo "--------------------------------------"
echo "✅ Bundle created successfully!"
echo "💾 Location File: $OUTPUT_PATH"
echo "--------------------------------------"
else
# If the build fails and the device is offline, a detailed error message appears
echo
if [ "$IS_OFFLINE" = "true" ]; then
echo "------------------------------------------"
echo "❌ The language pack is locally incomplete. The pack cannot be created without an internet connection."
echo "🌐 You must connect to the internet first to update the package."
echo "------------------------------------------"
else
echo "❌ Error: Package build failed. Please make sure the package files are complete."
fi
fi
echo
read -rp "Do you want to enter a new App ID? [Y/n]: " ANSWER
[[ "$ANSWER" =~ ^[Nn]$ ]] && break
done
echo "👋 Exiting..."
EOF
Create a true second copy named flatpak_b in the same folder
sudo cp /usr/local/bin/flatpak_bundle /usr/local/bin/flatpak_b
Grant execution permissions to both files to ensure they work as system commands using the following command
sudo chmod +x /usr/local/bin/flatpak_bundle /usr/local/bin/flatpak_b
Now you can try running it by typing flatpak_bundle or flatpak_b in the terminal to make sure.
A piece of advice: if you don't like typing commands every time, install the Thunar or Dolphin file managers. They are the only ones that allow you to integrate commands into the right-click context menu easily. You can install them on any distribution and on any desktop environment. You can run the script just by right-clicking on any folder or anywhere. To choose the save location, select the action CreateFlatpakBundle in the Thunar or Dolphin file manager. A window will appear immediately asking you to enter the program's App ID and to see the progress of the download or creation.
Add the actions in the Thunar context menu all at once. Copy the entire command as it is from start to finish, put it in the terminal, then press the Enter key. That's all, enjoy it. After that, you will find the options CreateFlatpakBundle, InstallFlatpakBundle System, and InstallFlatpakBundle User in the Right-Click context menu.
✅ command 👇👇
sed -i '$d' ~/.config/Thunar/uca.xml && cat <> ~/.config/Thunar/uca.xml
application-vnd.flatpak.ref
CreateFlatpakBundle
1773996544539369-1
x-terminal-emulator -e "flatpak_bundle"
application-vnd.flatpak.ref
InstallFlatpakBundle System
1773996614581437-2
x-terminal-emulator --hold -e "flatpak install --bundle %f"
.flatpak
application-vnd.flatpak.ref
InstallFlatpakBundle User
1773996678550373-3
x-terminal-emulator --hold -e "flatpak install --user --bundle %f"
.flatpak
EOF
To apply the changes, you must close all Thunar windows and restart it, or use this command
thunar -q && nohup thunar &
Add the actions to the Dolphin context menu all at once. Copy the entire command as it is from start to finish, put it in the terminal, then click the Enter key. That's it, enjoy.
After that, you will find the options CreateFlatpakBundle, InstallFlatpakBundle System, and InstallFlatpakBundle User in the Right-Click context menu.
✅ command 👇👇
sudo tee /usr/share/kio/servicemenus/Flatpak_Manager.desktop << 'EOF'
[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
Supports folders and Flatpak files
MimeType=inode/directory;application/vnd.flatpak;
Definition of the three procedures
Actions=CreateFlatpakBundle;InstallFlatpakBundle;InstallFlatpakBundleUser;
X-KDE-Priority=TopLevel
Icon=utilities-terminal
[Desktop Action CreateFlatpakBundle]
Name=CreateFlatpakBundle
Icon=utilities-terminal
Exec=konsole --hold --workdir %f -e "flatpak_bundle"
[Desktop Action InstallFlatpakBundle]
Name=InstallFlatpakBundle - System
Icon=utilities-terminal
Exec=konsole --hold -e "flatpak install --bundle %f"
[Desktop Action InstallFlatpakBundleUser]
Name=InstallFlatpakBundle - User
Icon=utilities-terminal
Exec=konsole --hold -e "flatpak install --user --bundle %f"
EOF
Grant execute permissions to the file using the following command
sudo chmod +x /usr/share/kio/servicemenus/Flatpak_Manager.desktop