From 9084d9c441da99ce3bde22a0cd74e14a4b659881 Mon Sep 17 00:00:00 2001 From: Payam Zahedi Date: Wed, 1 Nov 2023 13:43:44 +0330 Subject: [PATCH 1/4] update kiosk command now it will also support relative path --- snapp_installer | 102 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 27 deletions(-) diff --git a/snapp_installer b/snapp_installer index 7735995..ca04c1a 100644 --- a/snapp_installer +++ b/snapp_installer @@ -223,31 +223,36 @@ flutter build linux --release echo return 1 fi - + set -e local app_path="$1" - # Check if the provided path exists - if [ ! -e "$app_path" ]; then - echo "File or directory does not exist: $app_path" + if ! is_executable_file_valid "$app_path"; then return 1 fi - # Check if the provided path is a regular file (not a directory) - if [ ! -f "$app_path" ]; then - echo "Not a regular file: $app_path" - return 1 - fi + # Use realpath to get the absolute path + absolute_path=$(realpath "$app_path") - # Check if the file is executable - if [ -x "$app_path" ]; then - echo "Provided File is a valid executable: $app_path" - else - echo "File is not executable: $app_path" - return 1 + echo "Provided File is a valid path: $app_path" + + # Check if the file is absolute path + # If not, try to replace the relative path with the absolute path + if [ "$absolute_path" != "$app_path" ]; then + echo "But its not absolute path" + echo "Try to replace the relative path with the absolute path" + echo + if ! is_executable_file_valid "$absolute_path"; then + echo "The absolute path is not valid: $absolute_path" + return 1 + fi + app_path="$absolute_path" + echo "New path for the excutable file: $app_path" fi + echo + print_seperator if ! check_autologin; then echo "Autologin is disabled we have to enable it." @@ -269,43 +274,41 @@ flutter build linux --release # check $kiosk_home is available or not if [ ! -d "$kiosk_home" ]; then - echo "Creating directory $kiosk_home." + echo "Creating a kiosk directory in home " mkdir -p $kiosk_home echo else - echo "The $kiosk_home directory is already available." + echo "The kiosk directory is already available in home." echo fi - local kiosk_file="$kiosk_home/kiosk.sh" # check if kiosk.sh file is available or not if [ -f "$kiosk_file" ]; then - echo "remove current $kiosk_file file and create a new one." + echo "remove current kiosk.sh file and create a new one." sudo -E rm $kiosk_file echo fi - echo "Creating file $kiosk_file. from template" + echo "Creating file kiosk.sh file from template" sudo -E cp $snapp_home/kiosk.sh $kiosk_home/ echo - echo "Add Application path to $kiosk_file file" + echo "Add Application path to kiosk.sh file" sed -i "s/# placeholder/$(echo "$app_path" | sed 's/\//\\\//g') \&/g" "$kiosk_file" echo + print_seperator + if [ ! -d "$user_autostart_dir" ]; then - echo "Creating directory $user_autostart_dir." + echo "Creating directory $user_autostart_dir" sudo -E mkdir -p $user_autostart_dir echo - else - echo "The $user_autostart_dir directory is already available." - echo fi if [ -f "$user_autostart" ]; then - echo "remove current $user_autostart file." + echo "remove current user LXDE-pi/autostart file." sudo -E rm $user_autostart echo fi @@ -318,6 +321,14 @@ flutter build linux --release echo "@sleep 5" | sudo tee -a $user_autostart echo "@xdotool key alt+F11" | sudo tee -a $user_autostart + print_seperator + + echo + echo + echo "Kiosk mode has been enabled" + echo "Reboot your device to see the changes" + echo + echo echo } @@ -367,7 +378,7 @@ disable_autologin() { } check_autologin() { - return $(sudo -E raspi-config nonint get_autologin) + return "$(sudo -E raspi-config nonint get_autologin)" } print_banner() { @@ -401,6 +412,19 @@ print_banner() { echo "$border" } +print_seperator(){ + local width=40 # Adjust the width of the banner as needed + local border_char="*" + + echo + # prints $border_char $width times + for ((i = 0; i <= width; i++)); do + echo -n "*" + done + echo + echo +} + check_dep_packages() { all_installed=0 # Success (true) @@ -427,6 +451,30 @@ show_dep_packages_state(){ return $all_installed } +is_executable_file_valid(){ + local file_path="$1" + + # Check if the provided path exists + if [ ! -e "$file_path" ]; then + echo "File or directory does not exist: $file_path" + return 1 + fi + + # Check if the provided path is a regular file (not a directory) + if [ ! -f "$file_path" ]; then + echo "Not a regular file: $file_path" + return 1 + fi + + # Check if the file is executable + if [ ! -x "$file_path" ]; then + echo "File is not executable: $file_path" + return 1 + fi + + return 0 +} + check_dev_packages() { # List of packages to check From 94618d34fe89712b0327e1fc5300dece9fd02bf8 Mon Sep 17 00:00:00 2001 From: Payam Zahedi Date: Wed, 1 Nov 2023 16:04:13 +0330 Subject: [PATCH 2/4] add check for flutter project in kiosk command --- snapp_installer | 50 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/snapp_installer b/snapp_installer index ca04c1a..9178bc3 100644 --- a/snapp_installer +++ b/snapp_installer @@ -208,9 +208,51 @@ uninstall() { } kiosk(){ + + set -e + + echo + echo + + local possible_path=""; + if [ -z "$1" ]; then + echo "Excutable file path not provided". + echo + if [ -f "pubspec.yaml" ]; then + echo "It seems you are in the root of a flutter project." + echo "Try to find the executable file in the build folder." + echo + + # Check for the executable file with the same name as the current folder + current_folder_name=$(basename "$PWD") + + executable_path=$(find . -path "./build/linux/*/release/bundle/$current_folder_name" -type f -executable) + + + if [ -x "$executable_path" ]; then + echo "Found an executable file: $executable_path" + echo + # Prompt the user for confirmation + read -p "Do you want to use this executable file? (y/n): " choice + + if [ "$choice" = "y" ]; then + possible_path=$executable_path + else + echo "Operation canceled." + echo + fi + fi + fi + else + possible_path="$1" + fi + + + if [ -z "$possible_path" ]; then + echo " -No path parameter provided. +You should provide path to a excutable file or run this command in a flutter project. Usage: kiosk to run the app bundle in kiosk mode you need to provide the exact path to the flutter app bundle @@ -220,13 +262,11 @@ you can generate your file with the following command: flutter build linux --release " - echo + return 1 fi - set -e - - local app_path="$1" + local app_path=$possible_path if ! is_executable_file_valid "$app_path"; then return 1 From 9a83ceae79e96a27211d258dbec7f603cca474ce Mon Sep 17 00:00:00 2001 From: Payam Zahedi Date: Wed, 1 Nov 2023 16:08:37 +0330 Subject: [PATCH 3/4] add comment for install command --- snapp_installer | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/snapp_installer b/snapp_installer index 9178bc3..60ed963 100644 --- a/snapp_installer +++ b/snapp_installer @@ -201,6 +201,19 @@ install() { echo print_banner "Final Checks:" doctor + + print_seperator + + echo + echo + echo "Flutter installation has been completed" + echo + echo "To be able to use it, you should restart your terminal " + echo "Or you can enter the following command: " + echo + echo "source ~/.bashrc" + echo + echo } uninstall() { @@ -228,7 +241,7 @@ kiosk(){ current_folder_name=$(basename "$PWD") executable_path=$(find . -path "./build/linux/*/release/bundle/$current_folder_name" -type f -executable) - + if [ -x "$executable_path" ]; then echo "Found an executable file: $executable_path" From 78c13d1cc1b2ba9bf0af21bcca7719f33439fe41 Mon Sep 17 00:00:00 2001 From: Payam Zahedi Date: Thu, 2 Nov 2023 13:51:12 +0330 Subject: [PATCH 4/4] update README.md --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 581c58c..cf45a9b 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,10 @@ To use the "install" command, simply follow the Getting Started section in this ```bash snapp_installer install ``` + +**Note**: After running the "install" command, you need to restart your terminal or run `source ~/.bashrc` to apply the changes to your PATH environment variable. + + ## Kiosk Mode `snapp_installer` allows you to run your Flutter app in a kiosk mode on your Raspberry Pi, ensuring a seamless and focused user experience. To enable kiosk mode, follow these steps: @@ -81,7 +85,7 @@ snapp_installer install ```bash flutter build linux --release ``` -1. **Enable Kiosk Mode**:To run your Flutter app in kiosk mode, use the following command, replacing `` with the exact path to the Flutter app bundle you built in step 1: +1. **Enable Kiosk Mode**:To run your Flutter app in kiosk mode, use the following command, replacing `` with the path to the Flutter app bundle you built in step 1: ```bash snapp_installer kiosk @@ -94,6 +98,13 @@ snapp_installer kiosk /home/pi/app/build/linux/arm64/release/bundle/app ``` Ensure that the specified file path exists, points to an executable file, and is the path to your Flutter app bundle. + +Or you can run this command in a flutter project directory without specifying the path: + +```bash +snapp_installer kiosk +``` + **Auto Login**: Kiosk mode typically requires auto login on your Raspberry Pi. If auto login is not already enabled, snapp_installer will enable it for you.