Skip to content
Draft
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
/updates_list.txt
/updates_list.txt
/apps/app_categories
/etc/accent
/etc/editor
/etc/express-updates
/etc/pi-apps-import
/etc/theme
130 changes: 127 additions & 3 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ logo() {

# Function to install an app
install_app() {
local app_directory="$1"
local app_directory="$(get_app_directory "$2")"
local selected_app_name="$2"
local installed_file="$HOME/.linstore/installed"
local temp_script=$(mktemp)
Expand Down Expand Up @@ -73,7 +73,7 @@ open_app() {

# Function to install an app
installation_script() {
local app_directory="$1"
local app_directory="$(get_app_directory "$2")"
local selected_app_name="$2"
local installed_file="$HOME/.linstore/installed"

Expand All @@ -97,7 +97,7 @@ installation_script() {

# Function to uninstall an app
uninstall_app() {
local app_directory="$1"
local app_directory="$(get_app_directory "$2")"
local selected_app_name="$2"
local uninstalled_file="$HOME/.linstore/uninstalled"
local temp_script=$(mktemp)
Expand Down Expand Up @@ -166,6 +166,124 @@ search_apps() {
fi
}

cache_categories() {
# $1 - apps dir
# $2 - include Pi-Apps?
yad --title="LinStore" \
--class="LinStore" \
--center --borders=10 \
--text "Generating app cache..." \
--no-buttons &

if [ -e "${1}/app_categories" ]; then
rm -f "${1}/app_categories"
fi

for app_dir in "${1}"/*; do
app_name=$(basename "${app_dir}")
if [ -e "${1}/$app_name/category" ]; then
echo "$app_name|$(cat "${1}/$app_name/category")" >> "${1}/app_categories"
fi
done

if [[ "$2" == "TRUE" ]]; then
if [ -e "$HOME/pi-apps/etc/categories" ]; then
while IFS= read -r line; do
app_name=$(echo "$line" | awk -F'|' '{print $1}')
category=$(grep -r "$(echo "$line" | awk -F'|' '{print $2}')" etc/mapping | head -n1 | awk -F'|' '{print $2}')
echo "$app_name|$category" >> "${1}/app_categories"
done < "$HOME/pi-apps/etc/categories"
fi
fi

sort "${1}/app_categories" > "${1}/app_categories.tmp"
mv "${1}/app_categories.tmp" "${1}/app_categories"

pkill -f "yad*"
}

get_categories() {
cat etc/categories
}

get_apps_in_category() {
local category="$1"
grep "|$category$" etc/categories | cut -d'|' -f1
}

get_app_description() {
app_name="$1"
description_file="apps/$app_name/description"
if [ -e "$description_file" ]; then
cat "$description_file"
elif [ -e "$HOME/pi-apps/apps/$app_name/description" ]; then
cat "$HOME/pi-apps/apps/$app_name/description"
else
echo "No description available."
fi
}
get_app_creator() {
app_name="$1"
creator_file="apps/$app_name/creator"
if [ -e "$creator_file" ]; then
cat "$creator_file"
elif [ -e "$HOME/pi-apps/apps/$app_name/credits" ]; then
cat "$HOME/pi-apps/apps/$app_name/credits"
else
echo "No description available."
fi
}
get_app_website() {
app_name="$1"
website_file="apps/$app_name/website"
if [ -e "$website_file" ]; then
cat "$website_file"
else
echo "No description available."
fi
}
get_app_directory() {
app_name="$1"
if [ -d "apps/$app_name" ]; then
echo "apps/$app_name"
elif [ -d "$HOME/pi-apps/apps/$app_name" ]; then
echo "$HOME/pi-apps/apps/$app_name"
else
echo ""
fi
}

install_packages() {
packages="$@"
sudo apt update > /dev/null 2>&1

for package in $packages; do
if [[ "$package" == http* ]]; then
echo "Downloading and installing $package..."
wget --no-check-certificate "$package" -O /tmp/package.deb > /dev/null 2>&1
sudo dpkg -i /tmp/package.deb > /dev/null 2>&1
rm -r /tmp/package.deb
elif [[ "$package" == *.deb ]]; then
echo "Installing $package using dpkg..."
sudo dpkg -i "$package" > /dev/null 2>&1
else
echo "Installing $package using apt..."

sudo apt install "$package" -y > /dev/null 2>&1
fi
done
}

git_clone() {
if [ -z "$2" ]; then
local directory=$(basename "$1")
else
local directory="$2"
fi

git clone "$1" "$directory"
}

update() {
pkill -f "yad*"
./api info "Updating LinStore..."
Expand All @@ -192,6 +310,12 @@ information() {
printf '\033[1;104;30m INFO:\033[0;104m %s \033[0m\n' "$msg" >&2
}

export -f install_packages
export -f error
export -f warning
export -f information
export -f git_clone

# Main logic to handle command line arguments
if [[ $1 == "search" ]]; then
search_apps
Expand Down
146 changes: 31 additions & 115 deletions gui
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source api

APP_STORE_NAME="LinStore"
APP_STORE_WIDTH=320
APP_STORE_HEIGHT=600
Expand Down Expand Up @@ -74,98 +76,6 @@ list_piapps() {
fi
}

read_categories() {
while read -r category; do
categories["$category"]=""
done <etc/categories

for app_dir in "${1}"/*; do
app_name=$(basename "${app_dir}")

if [ ! -e "${1}/$app_name/category" ]; then
escaped_app_name=$(echo "$app_name" | sed 's/([\/.^$*+?|{}\[])/\\&/g')
data=$(grep -E "$escaped_app_name" etc/piapps-categories | awk -F"|" '{print $2}')
if [ -n "$data" ]; then
data2=$(grep -E "$data" etc/mapping | awk -F"|" '{print $2}')
if [ -n "$data2" ]; then
echo "$data2" > "${1}/$app_name/category"
category_file="${1}/$app_name/category"
else
continue
fi
else
continue
fi
fi

category_file="${1}/$app_name/category"
install_script="$app_dir/install"

# Check if the install script or architecture-specific install scripts exist for this app
if [ -e "$install_script" ]; then
while IFS= read -r app_in_category; do
# Make sure $app_in_category is not empty before accessing the array
if [ -n "$app_in_category" ]; then
if [ -n "${categories[$app_in_category]}" ]; then
categories["$app_in_category"]+=" $app_name"
category_apps["$app_in_category"]+="|$app_name"
else
categories["$app_in_category"]="$app_name"
category_apps["$app_in_category"]="$app_name"
fi
fi
break
done <"$category_file"
else
architecture=$(cat ~/.linstore/architecture.txt)
install_script_arch="install-$architecture"

if [ -e "$app_dir/$install_script_arch" ]; then
while IFS= read -r app_in_category; do
# Make sure $app_in_category is not empty before accessing the array
if [ -n "$app_in_category" ]; then
if [ -n "${categories[$app_in_category]}" ]; then
categories["$app_in_category"]+=" $app_name"
category_apps["$app_in_category"]+="|$app_name"
else
categories["$app_in_category"]="$app_name"
category_apps["$app_in_category"]="$app_name"
fi
fi
break
done <"$category_file"
fi
fi
done
}

get_app_description() {
app_name="$1"
description_file="apps/$app_name/description"
if [ -e "$description_file" ]; then
cat "$description_file"
else
echo "No description available."
fi
}
get_app_creator() {
app_name="$1"
creator_file="apps/$app_name/creator"
if [ -e "$creator_file" ]; then
cat "$creator_file"
else
echo "No description available."
fi
}
get_app_website() {
app_name="$1"
website_file="apps/$app_name/website"
if [ -e "$website_file" ]; then
cat "$website_file"
else
echo "No description available."
fi
}
theme_get() {
website_file="etc/theme"
if [ -e "$website_file" ]; then
Expand Down Expand Up @@ -222,8 +132,8 @@ app_details_page() {

local selected_app_name="${1//|/}"
selected_app_name=$(echo "$selected_app_name" | sed 's/<[^>]*>//g')
local app_directory="apps/$selected_app_name"
local app_icon="$app_directory/icon-48.png"
local app_directory="$(get_app_directory "$selected_app_name")"
local app_icon="$app_directory/icon-64.png"
local description=$(get_app_description "$selected_app_name")
local creator=$(get_app_creator "$selected_app_name")
local website=$(get_app_website "$selected_app_name")
Expand Down Expand Up @@ -284,33 +194,40 @@ show_apps_in_category() {
formatted_apps=()
if [ "$1" == "All Apps" ]; then
title="All Apps"
for app_dir in apps/*; do
app_name=$(basename "$app_dir")
if [ -e "$app_dir/install" ] || [ -e "$app_dir/install-$(cat ~/.linstore/architecture.txt)" ]; then
app_icon="apps/$app_name/icon-24.png"
while IFS= read -r line; do
app_name=$(echo "$line" | awk -F'|' '{print $1}')
app_dir="apps/$app_name"
if [ -e "$app_dir/install" ] || [ -e "$app_dir/install-$(cat ~/.linstore/architecture.txt)" ] \
|| [ -e "$HOME/pi-apps/apps/$app_name/install-$(cat ~/.linstore/architecture.txt)" ] \
|| [ -e "$HOME/pi-apps/apps/$app_name/install" ]; then
app_icon="$(get_app_directory "$app_name")/icon-24.png"
formatted_apps+=("$app_icon")
if [ -e "$HOME/.linstore/installscripts/$app_name" ]; then
formatted_apps+=("<span fgcolor=\"$ACCENT\">$app_name</span>")
else
formatted_apps+=("$app_name")
fi
fi
done
done < "apps/app_categories"
else
apps_in_category="${category_apps["$1"]}"
title="Apps in $1 Category"
#formatted_apps=()

IFS='|' read -r -a app_list <<<"$apps_in_category"
for app in "${app_list[@]}"; do
app_icon="apps/$app/icon-24.png"
formatted_apps+=("$app_icon")
if [ -e "$HOME/.linstore/installscripts/$app" ]; then
formatted_apps+=("<span fgcolor=\"$ACCENT\">$app</span>")
else
formatted_apps+=("$app")
while IFS= read -r line; do
[[ $(echo "$line" | awk -F'|' '{print $2}') == "$1" ]] || continue
app=$(echo "$line" | awk -F'|' '{print $1}')
if [ -e "apps/$app/install" ] || [ -e "apps/$app/install-$(cat ~/.linstore/architecture.txt)" ] \
|| [ -e "$HOME/pi-apps/apps/$app/install-$(cat ~/.linstore/architecture.txt)" ] \
|| [ -e "$HOME/pi-apps/apps/$app/install" ]; then
app_icon="$(get_app_directory "$app")/icon-24.png"
formatted_apps+=("$app_icon")
if [ -e "$HOME/.linstore/installscripts/$app" ]; then
formatted_apps+=("<span fgcolor=\"$ACCENT\">$app</span>")
else
formatted_apps+=("$app")
fi
fi
done
done < "apps/app_categories"
fi

GTK_THEME="${theme}" GDK_BACKEND=x11 $YAD_COMMAND --text "<big><b>$title</b></big>" --geometry=${APP_STORE_WIDTH}x${APP_STORE_HEIGHT}+${categoryPos}+${categoryPosY} --center --columns="2" \
Expand All @@ -330,13 +247,8 @@ show_apps_in_category() {
}

show_app_store() {
read_categories "apps"
if [[ "$use_piapps" == "TRUE" ]]; then
read_categories "/home/${USER}/pi-apps/apps"
fi

# Sort categories alphabetically and format with newlines
sorted_categories=$(printf '%s\n' "${!categories[@]}" | sort)
sorted_categories=$(printf '%s\n' "$(get_categories)" | sort)

list_items=()
list_items=("images/categories/All Apps.png" "All Apps")
Expand Down Expand Up @@ -373,6 +285,10 @@ show_app_store() {
fi
}

if [ ! -e apps/app_categories ]; then
cache_categories "apps" "$(list_piapps)"
fi

if [[ $1 == "" ]]; then
./api logo
./api buildinfo
Expand Down
3 changes: 3 additions & 0 deletions settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source api

APP_STORE_DIRECTORY="apps"
CATEGORIES_FILE="etc/categories"
THEMES_DIRECTORY="/usr/share/themes"
Expand Down Expand Up @@ -139,6 +141,7 @@ show_settings() {

import_from_piapps=$(echo "$fixed_settings" | awk -F '|' '{print $5}')
echo $import_from_piapps > "etc/pi-apps-import"
cache_categories "apps" "$(cat "etc/pi-apps-import" 2> /dev/null || echo FALSE)"

express_updates=$(echo "$fixed_settings" | awk -F '|' '{print $6}')
echo $express_updates > "etc/express-updates"
Expand Down
Loading