/ modules / template.am
template.am
  1  #!/usr/bin/env bash
  2  
  3  ##########################################################################
  4  # THIS MODULE IS USED TO CREATE INSTALLATION SCRIPS TO ADD TO THE DATABASE
  5  ##########################################################################
  6  
  7  # ------------------------------------------------------------------------
  8  # COMMON FUNCTIONS FOR OPTIONS 0 (APPIMAGES) AND 2 (ARCHIVES/FILES)
  9  # ------------------------------------------------------------------------
 10  
 11  _template_create_dirs_and_ask_for_source() {
 12  	# Create base directories
 13  	mkdir -p ./am-scripts ./am-scripts/"$ARCH" ./am-scripts/portable-linux-apps.github.io/apps ./am-scripts/portable-linux-apps.github.io/icons
 14  	# Download the template and convert the argument into a command
 15  	if [ "$templatetype" = 0 ] || [ "$templatetype" = 1 ]; then
 16  		wget -q "$AMREPO"/templates/AM-SAMPLE-AppImage -O ./am-scripts/"$ARCH"/"$arg"
 17  	elif [ "$templatetype" = 2 ]; then
 18  		wget -q "$AMREPO"/templates/AM-SAMPLE-Archive -O ./am-scripts/"$ARCH"/"$arg"
 19  	elif [ "$templatetype" = 3 ]; then
 20  		wget -q "$AMREPO"/templates/AM-SAMPLE-Firefox-webapp -O ./am-scripts/"$ARCH"/"$arg"
 21  	fi
 22  	sed -i "s/SAMPLE/$arg/g" ./am-scripts/"$ARCH"/"$arg"
 23  	echo "$DIVIDING_LINE"
 24  }
 25  
 26  _template_create_markdown_webpage_for_the_catalog() {
 27  	echo "# $(echo "$arg" | tr '[:lower:]' '[:upper:]')" >> ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md
 28  	echo -e "\n $COMMENT\n\n SITE: $RESPONSE\n\n | [Applications](https://portable-linux-apps.github.io/apps.html) | [Home](https://portable-linux-apps.github.io)\n | --- | --- |" >> ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md
 29  }
 30  
 31  _template_create_new_line_for_application_list() {
 32  	echo "◆ $arg : $COMMENT" >> ./am-scripts/list
 33  }
 34  
 35  _template_description_if_hosted_elsewhere() {
 36  	sed -i "s#REPLACETHIS#$RESPONSE#g" ./am-scripts/"$ARCH"/"$arg"
 37  	# ADD A DESCRIPTION FOR THIS APPLICATION
 38  	read -r -ep " ◆ ADD A BRIEF DESCRIPTION FOR THIS APPLICATION $(echo -e '\n : ')" COMMENT
 39  	case "$COMMENT" in
 40  	*)
 41  		_template_create_markdown_webpage_for_the_catalog
 42  		_template_create_new_line_for_application_list
 43  		;;
 44  	esac
 45  	echo "$DIVIDING_LINE"
 46  }
 47  
 48  _edit_script_head() {
 49  	mv ./am-scripts/"$ARCH"/"$arg" ./am-scripts/"$ARCH"/"$arg".old
 50  	sed -n '1,14p' ./am-scripts/"$ARCH"/"$arg".old >> ./am-scripts/"$ARCH"/"$arg"
 51  }
 52  
 53  _edit_script_middle() {
 54  	sed -n '16,35p' ./am-scripts/"$ARCH"/"$arg".old >> ./am-scripts/"$ARCH"/"$arg"
 55  }
 56  
 57  _edit_script_ending() {
 58  	sed -n '37,132p' ./am-scripts/"$ARCH"/"$arg".old >> ./am-scripts/"$ARCH"/"$arg"
 59  	rm -f ./am-scripts/"$ARCH"/"$arg".old
 60  }
 61  
 62  # ------------------------------------------------------------------------
 63  # FUNCTIONS TO HANDLE DOWNLOADS AND VERSIONS FROM ALTERNATIVE SOURCES
 64  # ------------------------------------------------------------------------
 65  
 66  _template_custom_download_url_as_version_variable() {
 67  	# IF YOU CAN, USE A ONE-LINE COMMAND TO DOWNLOAD THE PROGRAM
 68  	read -r -ep " USE A ONE-LINE COMMAND TO CHECK THE URL TO THE PROGRAM OR THE VERSION $(echo -e '\n\n if the URL is fixed, simply add the "echo" command at the beginning\n\n :') " DOWNLOADURL
 69  	case "$DOWNLOADURL" in
 70  	*)
 71  		_edit_script_head
 72  		echo "version=\$($DOWNLOADURL)" >> ./am-scripts/"$ARCH"/"$arg"
 73  		_edit_script_middle
 74  		echo "version=\$($DOWNLOADURL)" >> ./am-scripts/"$ARCH"/"$arg"
 75  		_edit_script_ending
 76  		echo "$DIVIDING_LINE"
 77  		;;
 78  	esac
 79  }
 80  
 81  _template_use_wget_to_download_a_linear_url_or_a_command() {
 82  	# FOR "WGET", ADD A LINEAR DOWNLOAD URL OR CHECK THE URL USING THE "$( ... )" SYNTAX
 83  	read -r -ep " ◆ FOR \"WGET\", ADD A COMMAND AS \"\$( ... )\" OR A LINEAR DOWNLOAD URL $(echo -e '\n : ')" DOWNLOADURL
 84  	case "$DOWNLOADURL" in
 85  	*)
 86  		mv ./am-scripts/"$ARCH"/"$arg" ./am-scripts/"$ARCH"/"$arg".old
 87  		sed -n '1,15p' ./am-scripts/"$ARCH"/"$arg".old >> ./am-scripts/"$ARCH"/"$arg"
 88  		echo "wget \"$DOWNLOADURL\" || exit 1" >> ./am-scripts/"$ARCH"/"$arg"
 89  		sed -n '17,40p' ./am-scripts/"$ARCH"/"$arg".old >> ./am-scripts/"$ARCH"/"$arg"
 90  		if grep -q "appimage" ./am-scripts/"$ARCH"/"$arg".old; then
 91  			echo "	[ -e ../*.zsync ] && wget \"\$version.zsync\" 2>/dev/null || { wget \"$DOWNLOADURL\" || exit 1; }" >> ./am-scripts/"$ARCH"/"$arg"
 92  		else
 93  			echo "	wget \"$DOWNLOADURL\" || exit 1" >> ./am-scripts/"$ARCH"/"$arg"
 94  		fi
 95  		sed -n '42,150p' ./am-scripts/"$ARCH"/"$arg".old >> ./am-scripts/"$ARCH"/"$arg"
 96  		rm -f ./am-scripts/"$ARCH"/"$arg".old
 97  		echo "$DIVIDING_LINE"
 98  		;;
 99  	esac
100  }
101  
102  _template_use_repology() {
103  	echo ""; echo " $repology"; echo ""
104  	_edit_script_head
105  	echo "version=\$($repology_command)" >> ./am-scripts/"$ARCH"/"$arg"
106  	_edit_script_middle
107  	echo "version=\$($repology_command)" >> ./am-scripts/"$ARCH"/"$arg"
108  	_edit_script_ending
109  }
110  
111  _template_help_by_repology() {
112  	# IF A DOWNLOAD URL IS LINEAR, USE https://repology.org
113  	read -r -ep " Do you want to use repology.org to identify version (y,N)? " yn
114  	if echo "$yn" | grep -qi "^y"; then
115  		repology=$(wget -q https://repology.org/project/"$arg"/versions -O - | grep -i "new.*version" | head -1 | tr '><' '\n' | grep "^[0-9]")
116  		repology_command="wget -q https://repology.org/project/$arg/versions -O - | grep -i \"new.*version\" | head -1 | tr '><' '\\n' | grep \"^[0-9]\""
117  		if [ -z "$repology" ]; then
118  			repology=$(wget -q https://repology.org/project/"$arg"/versions -O - | grep -i "uniq.*version" | head -1 | tr '><' '\n' | grep "^[0-9]")
119  			repology_command="wget -q https://repology.org/project/$arg/versions -O - | grep -i \"uniq.*version\" | head -1 | tr '><' '\\n' | grep \"^[0-9]\""
120  			_template_use_repology
121  		else
122  			_template_use_repology
123  		fi
124  		if [ "$templatetype" != 1 ]; then
125  			_template_use_wget_to_download_a_linear_url_or_a_command
126  		fi
127  	else
128  		echo "$DIVIDING_LINE"
129  		_template_custom_download_url_as_version_variable
130  	fi
131  }
132  
133  # ------------------------------------------------------------------------
134  # CUSTOM LAUNCHERS GENERATOR
135  # ------------------------------------------------------------------------
136  
137  # Function to add a generic .desktop file and an icon to the installation script (option 2)
138  _template_generate_desktop_file() {
139  	sed -i "s/#printf/printf/g" ./am-scripts/"$ARCH"/"$arg"
140  	cat <<-'HEREDOC' >> ./am-scripts/"$ARCH"/"$arg"
141  
142  	# ICON
143  	mkdir -p icons
144  	wget ICONURL -O ./icons/"$APP" 2> /dev/null
145  
146  	# LAUNCHER
147  	echo "[Desktop Entry]
148  	Name=APPNAME
149  	Exec=$APP
150  	Icon=/opt/$APP/icons/$APP
151  	Type=Application
152  	Terminal=false
153  	Categories=YOURCATEGORY;" > /usr/local/share/applications/"$APP"-AM.desktop
154  	HEREDOC
155  }
156  
157  # Function to add a category to our custom .desktop file (options 2 and 3)
158  _template_desktop_file_select_category() {
159  	echo -e " LIST OF CATEGORIES:\n 0) AudioVideo\n 1) Audio\n 2) Video\n 3) Development\n 4) Education\n 5) Game\n 6) Graphics\n 7) Network\n 8) Office\n 9) Science\n 10) Settings\n 11) System\n 12) Utility (default)\n "
160  	read -r -p " CHOOSE A CATEGORY : " response
161  	case "$response" in
162  		0)	sed -i "s/YOURCATEGORY/AudioVideo/g" ./am-scripts/"$ARCH"/"$arg";;
163  		1)	sed -i "s/YOURCATEGORY/Audio/g" ./am-scripts/"$ARCH"/"$arg";;
164  		2)	sed -i "s/YOURCATEGORY/Video/g" ./am-scripts/"$ARCH"/"$arg";;
165  		3)	sed -i "s/YOURCATEGORY/Development/g" ./am-scripts/"$ARCH"/"$arg";;
166  		4)	sed -i "s/YOURCATEGORY/Education/g" ./am-scripts/"$ARCH"/"$arg";;
167  		5)	sed -i "s/YOURCATEGORY/Game/g" ./am-scripts/"$ARCH"/"$arg";;
168  		6)	sed -i "s/YOURCATEGORY/Graphics/g" ./am-scripts/"$ARCH"/"$arg";;
169  		7)	sed -i "s/YOURCATEGORY/Network/g" ./am-scripts/"$ARCH"/"$arg";;
170  		8)	sed -i "s/YOURCATEGORY/Office/g" ./am-scripts/"$ARCH"/"$arg";;
171  		9)	sed -i "s/YOURCATEGORY/Science/g" ./am-scripts/"$ARCH"/"$arg";;
172  		10)	sed -i "s/YOURCATEGORY/Settings/g" ./am-scripts/"$ARCH"/"$arg";;
173  		11)	sed -i "s/YOURCATEGORY/System/g" ./am-scripts/"$ARCH"/"$arg";;
174  		12|*)	sed -i "s/YOURCATEGORY/Utility/g" ./am-scripts/"$ARCH"/"$arg";;
175  	esac
176  	echo "$DIVIDING_LINE"
177  }
178  
179  # ------------------------------------------------------------------------
180  # COMMON FUNCTIONS TO DOWNLOAD APPS FROM GIT REPOSITORIES
181  # ------------------------------------------------------------------------
182  
183  _template_if_github() {
184  	SITE="https://github.com"
185  	RESPONSE=$(echo "$RESPONSE" | sed 's#https://github.com/##g' | cut -f1,2 -d'/')
186  	COMMENT=$(curl $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE" 2>/dev/null | grep description | sed 's/"description": "//' | sed 's/",//' | cut -c 3-)
187  	CURL_COMMAND_REF="curl -Ls https://api.github.com/repos"
188  	CURL_COMMAND_REF_PREVIEW="curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos"
189  }
190  
191  _template_if_codeberg() {
192  	SITE="https://codeberg.org"
193  	RESPONSE=$(echo "$RESPONSE" | sed 's#https://codeberg.org/##g' | cut -f1,2 -d'/')
194  	COMMENT=$(curl https://codeberg.org/"$RESPONSE" 2>/dev/null | grep "description.*content" | tail -1 | sed 's/content="/\n/; s/">//g' | tail -1)
195  	CURL_COMMAND_REF="curl -Ls https://codeberg.org"
196  	CURL_COMMAND_REF_PREVIEW="$CURL_COMMAND_REF"
197  }
198  
199  _template_if_git_repo() {
200  	# Determine the git repo and complete the markdown
201  	if echo "$RESPONSE" | grep -q "https://github.com"; then
202  		_template_if_github
203  	elif echo "$RESPONSE" | grep -q "https://codeberg.org"; then
204  		_template_if_codeberg
205  	fi
206  	# Create the markdown file
207  	echo "# $(echo "$arg" | tr '[:lower:]' '[:upper:]')" >> ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md
208  	echo -e "\n $COMMENT\n\n SITE: $SITE/$RESPONSE\n\n | [Applications](https://portable-linux-apps.github.io/apps.html) | [Home](https://portable-linux-apps.github.io)\n | --- | --- |" >> ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md
209  	# Determine the function to download the program based on the type (appimage or other)
210  	q="'"
211  	if [ "$templatetype" = 0 ]; then
212  		FUNCTION=''"$CURL_COMMAND_REF"'/'"$RESPONSE"'/releases | sed '"$q"'s/[()",{} ]/\\n/g'"$q"' | grep -oi "https.*mage$" | grep -vi "i386\\|i686\\|aarch64\\|arm64\\|armv7l" | head -1'
213  	elif [ "$templatetype" = 2 ]; then
214  		FUNCTION=''"$CURL_COMMAND_REF"'/'"$RESPONSE"'/releases | sed '"$q"'s/[()",{} ]/\\n/g'"$q"' | grep -oi "https.*" | grep -vi "i386\\|i686\\|aarch64\\|arm64\\|armv7l" | head -1'
215  	fi
216  	# Add the above function and reference repository in the installation script
217  	sed -i "s#REPLACETHIS#$RESPONSE#g" ./am-scripts/"$ARCH"/"$arg"
218  	sed -i "s#FUNCTION)#$FUNCTION)#g" ./am-scripts/"$ARCH"/"$arg"
219  	_template_create_new_line_for_application_list
220  	echo "$DIVIDING_LINE"
221  }
222  
223  _template_test_github_url_if_torsocks_exists() {
224  	echo ""
225  	GHURLPREVIEW=$(eval "$GHURLPREVIEW_COMMAND")
226  	if [ -z "$GHURLPREVIEW" ]; then
227  		if command -v torsocks 1>/dev/null; then
228  			GHURLPREVIEW="torsocks $GHURLPREVIEW_COMMAND"
229  			eval "$GHURLPREVIEW"
230  		fi
231  	else
232  		echo "$GHURLPREVIEW"
233  	fi
234  }
235  
236  _template_then_git_repo() {
237  	_template_if_git_repo
238  	# Set the release as "latest" or keep it generic
239  	read -r -p ' Latest release (y) or a generic one (N or leave blank)?' yn
240  	if echo "$yn" | grep -qi "^y"; then
241  		setlatest="/latest"
242  		sed -i 's#/releases #/releases/latest #g' ./am-scripts/"$ARCH"/"$arg"
243  	else
244  		setlatest=""
245  	fi
246  	echo "$DIVIDING_LINE"
247  	# Check if the URL is correct
248  	read -r -p ' Do you wish to check the link (Y,n)?' yn
249  	if ! echo "$yn" | grep -qi "^n"; then
250  		if [ "$templatetype" = 0 ]; then
251  			GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF_PREVIEW/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*mage$\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | head -1"
252  			_template_test_github_url_if_torsocks_exists
253  		elif [ "$templatetype" = 2 ]; then
254  			GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF_PREVIEW/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | head -1"
255  			_template_test_github_url_if_torsocks_exists
256  		fi
257  		echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
258  	fi
259  	echo "$DIVIDING_LINE"
260  	# Add/remove keywords or leave blank to skip
261  	read -r -p ' If correct, press "ENTER", 1 to add keywords and 2 to remove keywords: ' response
262  	case "$response" in
263  	1)
264  		read -r -ep ' URL must contain ("x64", "x86_64"... or leave blank): ' response
265  		if [ -n "$response" ]; then
266  			sed -i "s# head -1# grep -i \"$response\" | head -1#g" ./am-scripts/"$ARCH"/"$arg"
267  			read -r -p ' Do you wish to check the link for the last time (Y,n)?' yn
268  			if ! echo "$yn" | grep -qi "^n"; then
269  				if [ "$templatetype" = 0 ]; then
270  					GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF_PREVIEW/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*mage$\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | grep -i \"$response\" | head -1"
271  					_template_test_github_url_if_torsocks_exists
272  				elif [ "$templatetype" = 2 ]; then
273  					GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF_PREVIEW/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | grep -i \"$response\" | head -1"
274  					_template_test_github_url_if_torsocks_exists
275  				fi
276  				echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
277  			fi
278  		fi
279  		;;
280  	2)
281  		read -r -ep ' URL must NOT contain ("txt", "ARM"... or leave blank): ' response
282  		if [ -n "$response" ]; then
283  			sed -i "s# head -1# grep -v \"$response\" | head -1#g" ./am-scripts/"$ARCH"/"$arg"
284  			read -r -p ' Do you wish to check the link for the last time (Y,n)?' yn
285  			if ! echo "$yn" | grep -qi "^n"; then
286  				if [ "$templatetype" = 0 ]; then
287  					GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF_PREVIEW/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*mage$\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | grep -v \"$response\" | head -1"
288  					_template_test_github_url_if_torsocks_exists
289  				elif [ "$templatetype" = 2 ]; then
290  					GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF_PREVIEW/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | grep -v \"$response\" | head -1"
291  					_template_test_github_url_if_torsocks_exists
292  				fi
293  				echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
294  			fi
295  		fi
296  		;;
297  	esac
298  }
299  
300  # ------------------------------------------------------------------------
301  # FUNCTIONS SPECIFIC PER WEBSITE
302  # ------------------------------------------------------------------------
303  
304  _template_if_sourceforge() {
305  	sed -i "s#REPLACETHIS#$RESPONSE#g" ./am-scripts/"$ARCH"/"$arg"
306  	# ADD PROJECTNAME
307  	read -r -ep " ◆ ADD THE NAME OF THE PROJECT OR LEAVE BLANK IF ITS THE SAME $(echo -e '\n : ')" projectname
308  	case "$projectname" in
309  	'')	SOURCEFORGE="https://sourceforge.net/p/$arg/activity/feed";;
310  	*)	SOURCEFORGE="https://sourceforge.net/p/$projectname/activity/feed";;
311  	esac
312  	echo "$DIVIDING_LINE"
313  	# FILE TYPE
314  	if [ "$templatetype" = 0 ]; then
315  		filetype="appimage"
316  	elif [ "$templatetype" = 2 ]; then
317  		read -r -ep " ◆ ADD an univoque keyword for the file (for example \"tar.gz\", \"linux\"):" filekeyword
318  		case "$filekeyword" in
319  		*) filetype="$filekeyword";;
320  		esac
321  	fi
322  	# ADD A DESCRIPTION FOR THIS APPLICATION
323  	read -r -ep " ◆ ADD A BRIEF DESCRIPTION FOR THIS APPLICATION $(echo -e '\n : ')" COMMENT
324  	case "$COMMENT" in
325  	*)
326  		_template_create_markdown_webpage_for_the_catalog
327  		_template_create_new_line_for_application_list
328  		;;
329  	esac
330  	echo "$DIVIDING_LINE"
331  	sourceforge_url_test=$(curl -Ls "$SOURCEFORGE" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep -i "$filetype" | grep -v '%' | head -1)
332  	if curl --head --silent --fail "$sourceforge_url_test" 1> /dev/null; then
333  		_edit_script_head
334  		echo "version=\$(curl -Ls $SOURCEFORGE | grep -Eo \"(http|https)://[a-zA-Z0-9./?=_%:-]*\" | grep -i \"$filetype\" | grep -v '%' | head -1)" >> ./am-scripts/"$ARCH"/"$arg"
335  		_edit_script_middle
336  		echo "version=\$(curl -Ls $SOURCEFORGE | grep -Eo \"(http|https)://[a-zA-Z0-9./?=_%:-]*\" | grep -i \"$filetype\" | grep -v '%' | head -1)" >> ./am-scripts/"$ARCH"/"$arg"
337  		_edit_script_ending
338  		curl -Ls "$SOURCEFORGE" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep -i "$filetype" | grep -v '%' | head -1
339  		echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
340  	else
341  		_template_custom_download_url_as_version_variable
342  	fi
343  	sed -i 's/*mage/*/g' ./am-scripts/"$ARCH"/"$arg"
344  }
345  
346  #####################################
347  # LET CREATE OUR INSTALLATION SCRIPTS
348  #####################################
349  
350  case $2 in
351  '')
352  	echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit
353  	;;
354  esac
355  
356  ARGS="$(echo "$@" | cut -f2- -d ' ')"
357  for arg in $ARGS; do
358  	arg=$(echo "$arg" | tr '[:upper:]' '[:lower:]')
359  	case $arg in
360  	*)
361  		cd "$SCRIPTDIR" || return
362  		echo "##############################################################"
363  		echo ""
364  		echo " Create a template for \"$arg\"" | tr '[:lower:]' '[:upper:]'
365  		echo ""
366  		echo "$DIVIDING_LINE"
367  		echo ""
368  		echo " EACH MODEL IS BASED ON A DIFFERENT METHOD OF BUILDING/UPDATING THE PROGRAM."
369  		echo ""
370  		echo " PLEASE, SELECT A TEMPLATE FOR \"$(echo "$arg" | tr '[:lower:]' '[:upper:]')\":"
371  		echo ""
372  		echo "  0) APPIMAGE, FROM ANY WEBSITE (BETTER IF FROM GITHUB.COM)"
373  		echo "  1) APPIMAGE ON-THE-FLY, USING A DEDICATED SCRIPT"
374  		echo "  2) ANY ARCHIVE/BINARY/SCRIPT FROM ANY WEBSITE"
375  		echo "  3) WEBAPP BASED ON A FIREFOX PROFILE (REQUIRES \"FIREFOX\" IN \$PATH)"
376  		echo ""
377  		read -r -p " WHAT KIND OF PROGRAM DO YOU WANT TO WRITE A SCRIPT FOR? : " templatetype
378  		case "$templatetype" in
379  
380  		0) # APPIMAGE (ANY)
381  
382  			_template_create_dirs_and_ask_for_source
383  
384  			# ADD THE NAME OF THE SOURCE
385  			read -r -ep " ◆ ADD THE URL OF THE SITE (BETTER IF IT COME FROM GITHUB), FOR EXAMPLE: $(echo -e '\n\n - if from github.com, use "https://github.com/USER/PROJECT"\n\n - if from other sources, use "https://www.SITENAME.com" or something\n\n URL: ')" RESPONSE
386  			case "$RESPONSE" in
387  			*)
388  				if echo "$RESPONSE" | grep -qi "^https.*github.com\|codeberg.org"; then
389  					_template_then_git_repo
390  				elif echo "$RESPONSE" | grep -q "sourceforge"; then
391  					_template_if_sourceforge
392  				else
393  					_template_description_if_hosted_elsewhere
394  					_template_help_by_repology
395  				fi
396  			esac
397  			# END OF THIS FUNCTION
398  			echo "$DIVIDING_LINE"
399  			echo -e "\n All files are saved in $SCRIPTDIR/am-scripts\n"
400  			;;
401  
402  		1) # CREATE AN APPIMAGE ON-THE-FLY
403  
404  			_template_create_dirs_and_ask_for_source
405  			_template_description_if_hosted_elsewhere
406  			_template_help_by_repology
407  
408  			# ADD A LINEAR DOWNLOAD URL
409  			read -r -ep " ◆ ADD A LINEAR DOWNLOAD URL FOR THE SCRIPT OR LEAVE BLANK $(echo -e '\n : ')" dlurl
410  			case "$dlurl" in
411  			'')
412  				sed -i 's#wget "$version"#wget "'"$AMREPO"'/appimage-bulder-scripts/'"$ARCH"'/$APP.sh" \&\& chmod a+x "$APP".sh \&\& ./"$APP".sh#g' ./am-scripts/"$ARCH"/"$arg"
413  			;;
414  			*)
415  				sed -i 's#wget "$version"#wget "'"$dlurl"'" -O '"$arg"'.sh && chmod '"$arg"'.sh && ./'"$arg"'.sh#g' ./am-scripts/"$ARCH"/"$arg"
416  			;;
417  			esac
418  			# END OF THIS FUNCTION
419  			echo "$DIVIDING_LINE"
420  			echo -e "\n All files are saved in $SCRIPTDIR/am-scripts\n"
421  			;;
422  
423  		2) # DOWNLOAD ANY ARCHIVE
424  
425  			_template_create_dirs_and_ask_for_source
426  
427  			# ADD THE NAME OF THE SOURCE
428  			read -r -ep " ◆ ADD THE URL OF THE SITE (BETTER IF IT COME FROM GITHUB), FOR EXAMPLE: $(echo -e '\n\n - if from github.com, use "https://github.com/USER/PROJECT"\n\n - if from other sources, use "https://www.SITENAME.com" or something\n\n URL: ')" RESPONSE
429  			case "$RESPONSE" in
430  			*)
431  				if echo "$RESPONSE" | grep -q "https://github.com"; then
432  					_template_then_git_repo
433  				elif echo "$RESPONSE" | grep -q "https://codeberg.org"; then
434  					_template_then_git_repo
435  				elif echo "$RESPONSE" | grep -q "sourceforge"; then
436  					_template_if_sourceforge
437  				else
438  					_template_description_if_hosted_elsewhere
439  					_template_help_by_repology
440  				fi
441  			esac
442  			# LAUNCHER AND ICON (OPTIONAL)
443  			read -r -p " ◆ Do you wish to add a launcher and a icon (y,N)? " yn
444  			if echo "$yn" | grep -qi "^y"; then
445  				# ADD LAUNCHER AND ICON REFERENCES TO THE INSTALLATION SCRIPT
446  				_template_generate_desktop_file
447  
448  				# ENTER THE URL OF THE ICON THAT WILL APPEAR IN THE MENU
449  				read -r -ep " ◆ COPY/PASTE THE URL OF THE ICON HERE $(echo -e '\n URL: ')" ICONURL
450  				case "$ICONURL" in
451  				'')	sed -i "s#ICONURL#https://portable-linux-apps.github.io/icons/$arg.png#g" ./am-scripts/"$ARCH"/"$arg"
452  					;;
453  				*)	sed -i "s#ICONURL#$ICONURL#g" ./am-scripts/"$ARCH"/"$arg"
454  					wget -q -P ./am-scripts/portable-linux-apps.github.io/icons/ "$ICONURL"
455  					;;
456  				esac
457  				echo "$DIVIDING_LINE"
458  				# APPNAME
459  				read -r -ep ' ◆ NAME OF THE APP (for the "Name" entry of the .desktop file): ' APPNAME
460  				case "$APPNAME" in
461  				*)
462  					sed -i "s#APPNAME#$APPNAME#g" ./am-scripts/"$ARCH"/"$arg"
463  					;;
464  				esac
465  				echo "$DIVIDING_LINE"
466  				# PUT THE APP INTO A CATEGORY, THIS IS NEEDED FOR OUR CUSTOM DESKTOP FILE
467  				_template_desktop_file_select_category
468  			else
469  				echo "$DIVIDING_LINE"
470  			fi
471  			# END OF THIS FUNCTION
472  			echo -e "\n All files are saved in $SCRIPTDIR/am-scripts\n"
473  			;;
474  
475  		3) # CREATE A CUSTOM FIREFOX PROFILE ("firefox" MUST BE IN "$PATH" TO MADE IT WORK)
476  
477  			_template_create_dirs_and_ask_for_source
478  
479  			# USE THE SUFFIX FROM NOW ON
480  			mv ./am-scripts/"$ARCH"/"$arg" ./am-scripts/"$ARCH"/"ffwa-$arg"
481  			arg="ffwa-$arg"
482  			echo "$DIVIDING_LINE"
483  			read -r -ep " ◆ NAME OF THE APP: " RESPONSE
484  			case "$RESPONSE" in
485  			*)
486  				sed -i "s#GIVEMEANAME#$RESPONSE#g" ./am-scripts/"$ARCH"/"$arg"
487  				# CREATE A WEBPAGE FOR https://portable-linux-apps.github.io CONTAINING ALL THE INFO ABOUT THIS APP
488  				echo "# $(echo "$arg" | tr '[:lower:]' '[:upper:]')" >> ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md
489  				echo -e "\n WebApp & Firefox Profile for $RESPONSE.\n\n SITE: MYWEBSITE\n\n | [Applications](https://portable-linux-apps.github.io/apps.html) | [Home](https://portable-linux-apps.github.io)\n | --- | --- |" >> ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md
490  				# CREATE A NEW LINE FOR THE APPLICATION'S LIST
491  				echo "◆ $arg : WebApp & Firefox Profile for $RESPONSE." >> ./am-scripts/list
492  			esac
493  			# PUT THE APP INTO A CATEGORY, THIS IS NEEDED FOR OUR CUSTOM DESKTOP FILE
494  			_template_desktop_file_select_category
495  			# ENTER THE URL OF THE SITE YOU WANT TO CREATE A CUSTOM FIREFOX PROFILE FOR
496  			read -r -ep " ◆ URL OF THE WEBAPP: " RESPONSE
497  			case "$RESPONSE" in
498  			*)
499  				sed -i "s#MYWEBSITE#$RESPONSE#g" ./am-scripts/"$ARCH"/"$arg"; sed -i "s#MYWEBSITE#$RESPONSE#g" ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md
500  				;;
501  			esac
502  			echo "$DIVIDING_LINE"
503  			# ENTER THE URL OF THE ICON THAT WILL APPEAR IN THE MENU
504  			read -r -ep " ◆ COPY/PASTE THE URL OF THE ICON HERE $(echo -e '\n URL: ')" RESPONSE
505  			case "$RESPONSE" in
506  			*)
507  				sed -i "s#YOURICONURL#$RESPONSE#g" ./am-scripts/"$ARCH"/"$arg"
508  				;;
509  			esac
510  			echo "$DIVIDING_LINE"
511  			# END OF THIS FUNCTION
512  			echo -e "\n All files are saved in $SCRIPTDIR/am-scripts\n"
513  			;;
514  
515  		# NOTHING SELECTED
516  		*)
517  			echo -e "\n No valid argument was chosen: process aborted! \n" | tr '[:lower:]' '[:upper:]'; break
518  			;;
519  		esac
520  	esac
521  done