Skip to content
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
153 changes: 144 additions & 9 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ logo() {

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

Expand Down Expand Up @@ -73,8 +73,8 @@ open_app() {

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

if [ -e "$app_directory/install" ]; then
Expand All @@ -97,8 +97,8 @@ installation_script() {

# Function to uninstall an app
uninstall_app() {
local app_directory="$1"
local selected_app_name="$2"
local app_directory="$(get_app_directory "$1")"
local selected_app_name="$1"
local uninstalled_file="$HOME/.linstore/uninstalled"
local temp_script=$(mktemp)

Expand Down Expand Up @@ -166,6 +166,133 @@ 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
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
echo "$app_name|$(cat "${1}/$app_name/category")" >> "${1}/app_categories"
fi
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}')
app_dir="$HOME/pi-apps/apps/$app_name"
category=$(grep -r "$(echo "$line" | awk -F'|' '{print $2}')" etc/mapping | head -n1 | awk -F'|' '{print $2}')
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
echo "$app_name|$category" >> "${1}/app_categories"
fi
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,15 +319,23 @@ 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
export -f get_app_directory
export -f get_categories

# Main logic to handle command line arguments
if [[ $1 == "search" ]]; then
search_apps
elif [[ $1 == "install" ]]; then
install_app "$2" "$3"
install_app "$2"
elif [[ $1 == "whatscript" ]]; then
installation_script "$2" "$3"
installation_script "$2"
elif [[ $1 == "uninstall" ]]; then
uninstall_app "$2" "$3"
uninstall_app "$2"
elif [[ $1 == "logo" ]]; then
logo
elif [[ $1 == "error" ]]; then
Expand Down
99 changes: 57 additions & 42 deletions createapp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ select_category_pane() {
--window-icon="images/logo/logo-64.png" --class="LinStore" \
--text="<big><b>Choose a category</b></big>\nLinStore organises apps by category, which allows users to quickly find related apps easier.\nPlease choose a category for your app:" \
--field="Category:" \
--width="525" --height="550" --center --on-top --borders=10 --columns=1 "${category_list[@]}" \
--width="525" --height="550" --center --borders=10 --columns=1 "${category_list[@]}" \
--list --column="Icon:IMG" --column="Categories" --column="Description" --no-headers \
--button="<b>Cancel</b>!gtk-cancel":1 \
--button="<b>Next</b>!go-next":0 | awk -F '|' '{print $2}')
Expand Down Expand Up @@ -63,7 +63,7 @@ create_new_app_pane() {
--field="ARM 64-bit (aarch64):CHK" "" \
--field=":LBL" "" \
--field="<b>Separate or combined install scripts?</b>:CB" 'Combined (all architectures in one)!Separate' \
--width="525" --height="550" --center --on-top --borders=10 --separator="|" \
--width="525" --height="550" --center --borders=10 --separator="|" \
--button="<b>Cancel</b>!gtk-cancel":1 \
--button="<b>Next</b>!go-next":0)

Expand Down Expand Up @@ -104,7 +104,7 @@ create_new_app_pane() {
--text="<big><b>App Assets</b></big>\nYour app needs assets in LinStore, which is currently limited to the app's logo/icon.\nSelect these assets here:" \
--field=":LBL" "" \
--field="<b>Icon/logo</b>:SFL" "" \
--width="525" --height="550" --center --on-top --borders=10 --separator="|" \
--width="525" --height="550" --center --borders=10 --separator="|" \
--button="<b>Cancel</b>!gtk-cancel":1 \
--button="<b>Next</b>!go-next":0)

Expand All @@ -120,52 +120,67 @@ create_new_app_pane() {
convert "$icon_file" -resize 24x24 "$app_directory/icon-24.png"
convert "$icon_file" -resize 16x16 "$app_directory/icon-16.png"
fi


# Create or update the install scripts based on user preferences
if [[ "$separate_scripts" == "Combined (all architectures in one)" ]]; then
touch "$app_directory/install" &
else
if [ "$install_x64" == "TRUE" ]; then
touch "$app_directory/install-x64" &
fi
if [ "$install_x86" == "TRUE" ]; then
touch "$app_directory/install-x86" &
fi
if [ "$install_32" == "TRUE" ]; then
touch "$app_directory/install-32" &
fi
if [ "$install_64" == "TRUE" ]; then
touch "$app_directory/install-64" &
fi
fi

touch "$app_directory/uninstall" &

edit_scripts_pane "$app_directory"
}

edit_scripts_pane() {
app_directory="$1"
editor=$(get_editor)
buttons=()
for file in "$app_directory"/*; do
[ -f "$file" ] || continue
if [[ "$(basename "$file")" == "install"* ]]; then
buttons+=("--field= <b>$(basename "$file")</b>!images/button/install.png:BTN" "$editor \"$file\"")
elif [[ "$(basename "$file")" == "uninstall"* ]]; then
buttons+=("--field= <b>$(basename "$file")</b>!images/button/uninstall.png:BTN" "$editor \"$file\"")
fi
done

yad --form \
--title="Create New App" \
--image="images/logo/logo-64.png" --image-on-top \
--window-icon="images/logo/logo-64.png" --class="LinStore" \
--text="<big><b>Installer Scripts</b></big>\nYour app has been created!" \
--text="<big><b>Edit App Scripts</b></big>\nEdit your app's install and uninstall scripts." \
--field=":LBL" "" \
--field="You now need to write an Installer and an Uninstaller script. These are the scripts executed when users click \"Install\" and \"Uninstall\" in LinStore.\n\nIf you would like to create these now, press 'Next'. Else, press 'Cancel'.:LBL" "" \
--width="525" --height="550" --center --on-top --borders=10 --separator="|" \
--field="Listed below are the scripts used by LinStore when installing or uninstalling your app. Click on one to create or edit it.:LBL" "" \
"${buttons[@]}" \
--width="525" --height="550" --center --borders=10 --separator="|" \
--button="<b>Cancel</b>!gtk-cancel":1 \
--button="<b>Next</b>!go-next":0 > /dev/null 2>&1
--button="<b>Next</b>!go-next":0 > /dev/null 2>&1

# Create or update the install scripts based on user preferences
if [ $? -eq 0 ]; then
if [[ "$separate_scripts" == "Combined (all architectures in one)" ]]; then
gedit "$app_directory/install" &
else
if [ "$install_x64" == "TRUE" ]; then
gedit "$app_directory/install-x64" &
fi
if [ "$install_x86" == "TRUE" ]; then
gedit "$app_directory/install-x86" &
fi
if [ "$install_32" == "TRUE" ]; then
gedit "$app_directory/install-32" &
fi
if [ "$install_64" == "TRUE" ]; then
gedit "$app_directory/install-64" &
fi
fi

gedit "$app_directory/uninstall"
wait
elif [ $? -eq 252 ]; then
echo $?
yad --form \
--title="Create New App" \
--image="images/logo/logo-64.png" --image-on-top \
--window-icon="images/logo/logo-64.png" --class="LinStore" \
--text="<big><b>Thank you!</b></big>\nThank you for using LinStore's app creation wizard." \
--field=":LBL" "" \
--field="<b>Next Steps:</b>\nSubmit your app for addition to LinStore's app library. You can do this by 'zipping' the new app's directory and uploading it to an issue at <a href='https://github.com/techguy16/LinStore'>our GitHub</a>.\n\nIf you do not wish to do so, you can still distribute your app's zip file by specifying to your users to use LinStore's 'Import App' function.:LBL" "" \
--width="525" --height="550" --center --borders=10 --separator="|" \
--button="<b>Exit</b>!window-close":0 > /dev/null 2>&1
fi

yad --form \
--title="Create New App" \
--image="images/logo/logo-64.png" --image-on-top \
--window-icon="images/logo/logo-64.png" --class="LinStore" \
--text="<big><b>Thank you!</b></big>\nThank you for using LinStore's app creation wizard." \
--field=":LBL" "" \
--field="<b>Next Steps:</b>\nSubmit your app for addition to LinStore's app library. You can do this by 'zipping' the new app's directory and uploading it to an issue at <a href='https://github.com/techguy16/LinStore'>our GitHub</a>.\n\nIf you do not wish to do so, you can still distribute your app's zip file by specifying to your users to use LinStore's 'Import App' function.:LBL" "" \
--width="525" --height="550" --center --on-top --borders=10 --separator="|" \
--button="<b>Exit</b>!window-close":0 > /dev/null 2>&1

}

welcome() {
Expand All @@ -176,7 +191,7 @@ welcome() {
--text="<big><b>App Creator</b></big>\nWelcome to the LinStore's app creator!" \
--field=":LBL" "" \
--field="<b>What is this?</b>\nThis is a wizard that will guide you through the necessary steps in order to create an app to be displayed in LinStore.\n\nIf you're ready, press 'Next'.\nIf you got here by accident, press 'Cancel'.:LBL" "" \
--width="525" --height="550" --center --on-top --borders=10 --separator="|" \
--width="525" --height="550" --center --borders=10 --separator="|" \
--button="<b>Cancel</b>!gtk-cancel":1 \
--button="<b>Next</b>!go-next":0 > /dev/null 2>&1
if [ $? -eq 0 ]; then
Expand All @@ -196,7 +211,7 @@ import_zip_file() {
--field=":LBL" "" \
--field="Some app developers distribute ZIP files to let you import into LinStore.\n\nTo import such a ZIP file, select it below and we'll import it for you.:LBL" "" \
--field="<b>ZIP File: </b>:SFL" "" \
--width="525" --height="550" --center --on-top --borders=10 --separator="|" \
--width="525" --height="550" --center --borders=10 --separator="|" \
--button="<b>Cancel</b>!gtk-cancel":1 \
--button="<b>Next</b>!go-next":0 | awk -F '|' '{print $3}')

Expand Down
Loading