template.am 23 KB

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