-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_AppImage_JBs.sh
executable file
·143 lines (119 loc) · 5.41 KB
/
run_AppImage_JBs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
#
# Autor= João Batista Ribeiro
# Bugs, Agradecimentos, Críticas "construtivas"
# me envie um e-mail. Ficarei Grato!
# e-mail: joao42lbatista@gmail.com
#
# Este programa é um software livre; você pode redistribui-lo e/ou
# modifica-lo dentro dos termos da Licença Pública Geral GNU como
# publicada pela Fundação do Software Livre (FSF); na versão 2 da
# Licença, ou (na sua opinião) qualquer versão.
#
# Este programa é distribuído na esperança que possa ser útil,
# mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a
# qualquer MERCADO ou APLICAÇÃO EM PARTICULAR.
#
# Veja a Licença Pública Geral GNU para mais detalhes.
# Você deve ter recebido uma cópia da Licença Pública Geral GNU
# junto com este programa, se não, escreva para a Fundação do Software
#
# Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Script: Works with AppImage, can run, view, portable run and extract
#
# Tip: Add desktop launcher with the script
# Examples: https://github.com/ryuuzaki42/04_AppImage_shortcut_desktop/tree/main/AppImage_run
#
# Last update: 31/05/2024
#
set -x
AppImage_File=$1
if [ "$AppImage_File" == '' ]; then
echo -e "\n# Error: Need to pass parameters - the AppImage file and one option"
echo -e "For help message: $(basename "$0") -h\n"
exit 1
fi
if [ "$AppImage_File" == '-h' ] || [ "$AppImage_File" == '--help' ]; then
script_name=$(basename "$0")
echo -e "
Usage:
$script_name [AppImage] [OPTIONS]
OPTIONS:
-h, --help Print this message
-r, --run Run the AppImage with the arguments passed
Example: $script_name Maestral-*_JB.AppImage -r gui
> gui is a parameter to this AppImage to run with gui
-v, --view View the files inside the AppImage
Mount the AppImage and load the tmp folder with the file explorer
Example: $script_name Maestral-*_JB.AppImage -v
-x, --extract Extract the Prog*.AppImage to a folder Prog*.AppImage.ext/
Example: $script_name Maestral-*_JB.AppImage -x
-p, --portable Create a folder to home and other to configuration, then run the AppImage
Run an AppImage using local configuration (place of the AppImage file) and the arguments passed
Will create folders to save the configuration files: *.AppImage.config/ and *.AppImage.home/
Obs.: The application in the AppImage may save files in other folder, like user home folder
Example: $script_name Maestral-*_JB.AppImage -p gui\n"
exit 0
fi
if echo "$AppImage_File" | grep -iq "AppImage"; then # Check if is a AppImage file
option_run=$2
other_parameters=${*:3} # Parameters from $3 onwards
echo -e "\nAppImage_File: \"$AppImage_File\" option_run: \"$option_run\" other_parameters: \"$other_parameters\"\n"
else
echo "Error: \"$AppImage_File\" is no a AppImage file"
exit 1
fi
chmod +x "$AppImage_File" # Add permission to run, may not have it yet
first_char="${AppImage_File:0:1}" # Extract the first character
if [ "$first_char" != '/' ]; then # If $first_char == '/' is full path, if $first_char != '/' is relative path
AppImage_File="./$AppImage_File" # Add ./ to run the AppImage
fi
if [ "$option_run" == '' ]; then
echo "Pass one option valid to work with the AppImage"
echo "For help run: ./$(basename "$0") -h"
exit 1
elif [ "$option_run" == "-v" ] || [ "$option_run" == "--view" ]; then
TMP_File=$(mktemp) # Create a tmp file to save the mount point location
"$AppImage_File" --appimage-mount > "$TMP_File" & # Mount AppImage
sleep 1
mount_point=$(cat "$TMP_File")
rm -f "$TMP_File"
if [ -x /usr/bin/dolphin ]; then # Check witch file explorer available
file_explorer="dolphin"
elif [ -x /usr/bin/thunar ]; then
file_explorer="thunar"
else
echo "File explorer not defined"
fi
#echo "file_explorer: \"$file_explorer\""
"$file_explorer" "$mount_point"
echo " When has complete to check the files, respond y below to close and umount the AppImage in $mount_point"
echo -en "\n Close the \"$AppImage_File\"?\n (y)es or (n)o - Enter to yes: "
read -r do_close
if [ "$do_close" == 'y' ] || [ "$do_close" == '' ]; then
PID=$(ps aux | grep "appimage-mount" | grep "$AppImage_File" | awk '{print $2}' | head -n 1)
echo "PID: $PID"
kill "$PID"
#kill -9 $PID
fi
elif [ "$option_run" == "-x" ] || [ "$option_run" == "--extract" ]; then
"$AppImage_File" --appimage-extract # Extract the AppImage
mv squashfs-root/ "${AppImage_File}.ext/"
echo -e "\n AppImage: \"$AppImage_File\"\n Extracted to the folder: \"${AppImage_File}.ext/\""
elif [ "$option_run" == '-p' ] || [ "$option_run" == "--portable" ] \
|| [ "$option_run" == '-r' ] || [ "$option_run" == "--run" ]; then # If $option_run is --run or --portable
if [ "$option_run" == '-p' ] || [ "$option_run" == "--portable" ]; then # Only if $option_run is --portable
# Create a portable home folder to use as $HOME
"$AppImage_File" --appimage-portable-home
# Create a portable configuration folder to use as $XDG_CONFIG_HOME
"$AppImage_File" --appimage-portable-config
fi
if [ "$other_parameters" == '' ]; then # If no parameter were passed
"$AppImage_File"
else
"$AppImage_File" "$other_parameters"
fi
else
echo "Error: option \"$option_run\ not recognised"
fi