template.am 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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 $HeaderAuthWithGITPAT https://api.github.com/repos"
  167. }
  168. function _template_if_codeberg() {
  169. SITE="https://codeberg.org"
  170. RESPONSE=$(echo "$RESPONSE" | sed 's#https://codeberg.org/##g' | cut -f1,2 -d'/')
  171. COMMENT=$(curl https://codeberg.org/"$RESPONSE" 2>/dev/null | grep "description.*content" | tail -1 | sed 's/content="/\n/; s/">//g' | tail -1)
  172. CURL_COMMAND_REF="curl -Ls https://codeberg.org"
  173. }
  174. function _template_if_git_repo() {
  175. # Determine the git repo and complete the markdown
  176. if echo "$RESPONSE" | grep -q "https://github.com"; then
  177. _template_if_github
  178. elif echo "$RESPONSE" | grep -q "https://codeberg.org"; then
  179. _template_if_codeberg
  180. fi
  181. # Create the markdown file
  182. echo "# $(echo "$arg" | tr '[:lower:]' '[:upper:]')" >> ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md
  183. 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
  184. # Determine the function to download the program based on the type (appimage or other)
  185. q="'"
  186. if [ "$templatetype" = 0 ]; then
  187. 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'
  188. elif [ "$templatetype" = 2 ]; then
  189. FUNCTION=''"$CURL_COMMAND_REF"'/'"$RESPONSE"'/releases | sed '"$q"'s/[()",{} ]/\\n/g'"$q"' | grep -oi "https.*" | grep -vi "i386\\|i686\\|aarch64\\|arm64\\|armv7l" | head -1'
  190. fi
  191. # Add the above function and reference repository in the installation script
  192. sed -i "s#REPLACETHIS#$RESPONSE#g" ./am-scripts/"$ARCH"/"$arg"
  193. sed -i "s#FUNCTION)#$FUNCTION)#g" ./am-scripts/"$ARCH"/"$arg"
  194. _template_create_new_line_for_application_list
  195. echo "$DIVIDING_LINE"
  196. }
  197. function _template_test_github_url_if_torsocks_exists() {
  198. echo ""
  199. GHURLPREVIEW=$(eval "$GHURLPREVIEW_COMMAND")
  200. if [ -z "$GHURLPREVIEW" ]; then
  201. if command -v torsocks 1>/dev/null; then
  202. GHURLPREVIEW="torsocks $GHURLPREVIEW_COMMAND"
  203. eval "$GHURLPREVIEW"
  204. fi
  205. else
  206. echo "$GHURLPREVIEW"
  207. fi
  208. }
  209. function _template_then_git_repo() {
  210. _template_if_git_repo
  211. # Set the release as "latest" or keep it generic
  212. read -r -p ' Latest release (y) or a generic one (N or leave blank)?' yn
  213. if echo "$yn" | grep -qi "^y"; then
  214. setlatest="/latest"
  215. sed -i 's#/releases #/releases/latest #g' ./am-scripts/"$ARCH"/"$arg"
  216. else
  217. setlatest=""
  218. fi
  219. echo "$DIVIDING_LINE"
  220. # Check if the URL is correct
  221. read -r -p ' Do you wish to check the link (Y,n)?' yn
  222. if ! echo "$yn" | grep -qi "^n"; then
  223. if [ "$templatetype" = 0 ]; then
  224. GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*mage$\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | head -1"
  225. _template_test_github_url_if_torsocks_exists
  226. elif [ "$templatetype" = 2 ]; then
  227. GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | head -1"
  228. _template_test_github_url_if_torsocks_exists
  229. fi
  230. echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
  231. fi
  232. echo "$DIVIDING_LINE"
  233. # Add/remove keywords or leave blank to skip
  234. read -r -p ' If correct, press "ENTER", 1 to add keywords and 2 to remove keywords: ' response
  235. case "$response" in
  236. 1)
  237. read -r -ep ' URL must contain ("x64", "x86_64"... or leave blank): ' response
  238. if [ -n "$response" ]; then
  239. sed -i "s# head -1# grep -i \"$response\" | head -1#g" ./am-scripts/"$ARCH"/"$arg"
  240. read -r -p ' Do you wish to check the link for the last time (Y,n)?' yn
  241. if ! echo "$yn" | grep -qi "^n"; then
  242. if [ "$templatetype" = 0 ]; then
  243. GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*mage$\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | grep -i \"$response\" | head -1"
  244. _template_test_github_url_if_torsocks_exists
  245. elif [ "$templatetype" = 2 ]; then
  246. GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | grep -i \"$response\" | head -1"
  247. _template_test_github_url_if_torsocks_exists
  248. fi
  249. echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
  250. fi
  251. fi
  252. ;;
  253. 2)
  254. read -r -ep ' URL must NOT contain ("txt", "ARM"... or leave blank): ' response
  255. if [ -n "$response" ]; then
  256. sed -i "s# head -1# grep -v \"$response\" | head -1#g" ./am-scripts/"$ARCH"/"$arg"
  257. read -r -p ' Do you wish to check the link for the last time (Y,n)?' yn
  258. if ! echo "$yn" | grep -qi "^n"; then
  259. if [ "$templatetype" = 0 ]; then
  260. GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*mage$\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | grep -v \"$response\" | head -1"
  261. _template_test_github_url_if_torsocks_exists
  262. elif [ "$templatetype" = 2 ]; then
  263. GHURLPREVIEW_COMMAND="$CURL_COMMAND_REF/$RESPONSE/releases$setlatest | sed 's/[()\",{} ]/\n/g' | grep -oi \"https.*\" | grep -vi \"i386\|i686\|aarch64\|arm64\|armv7l\" | grep -v \"$response\" | head -1"
  264. _template_test_github_url_if_torsocks_exists
  265. fi
  266. echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
  267. fi
  268. fi
  269. ;;
  270. esac
  271. }
  272. # ------------------------------------------------------------------------
  273. # FUNCTIONS SPECIFIC PER WEBSITE
  274. # ------------------------------------------------------------------------
  275. function _template_if_sourceforge() {
  276. sed -i "s#REPLACETHIS#$RESPONSE#g" ./am-scripts/"$ARCH"/"$arg"
  277. # ADD PROJECTNAME
  278. read -r -ep " ◆ ADD THE NAME OF THE PROJECT OR LEAVE BLANK IF ITS THE SAME $(echo -e '\n : ')" projectname
  279. case "$projectname" in
  280. '') SOURCEFORGE="https://sourceforge.net/p/$arg/activity/feed";;
  281. *) SOURCEFORGE="https://sourceforge.net/p/$projectname/activity/feed";;
  282. esac
  283. echo "$DIVIDING_LINE"
  284. # FILE TYPE
  285. if [ "$templatetype" = 0 ]; then
  286. filetype="appimage"
  287. elif [ "$templatetype" = 2 ]; then
  288. read -r -ep " ◆ ADD an univoque keyword for the file (for example \"tar.gz\", \"linux\"):" filekeyword
  289. case "$filekeyword" in
  290. *) filetype="$filekeyword";;
  291. esac
  292. fi
  293. # ADD A DESCRIPTION FOR THIS APPLICATION
  294. read -r -ep " ◆ ADD A BRIEF DESCRIPTION FOR THIS APPLICATION $(echo -e '\n : ')" COMMENT
  295. case "$COMMENT" in
  296. *)
  297. _template_create_markdown_webpage_for_the_catalog
  298. _template_create_new_line_for_application_list
  299. ;;
  300. esac
  301. echo "$DIVIDING_LINE"
  302. sourceforge_url_test=$(curl -Ls "$SOURCEFORGE" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep -i "$filetype" | grep -v '%' | head -1)
  303. if curl --head --silent --fail "$sourceforge_url_test" 1> /dev/null; then
  304. _edit_script_head
  305. echo "version=\$(curl -Ls $SOURCEFORGE | grep -Eo \"(http|https)://[a-zA-Z0-9./?=_%:-]*\" | grep -i \"$filetype\" | grep -v '%' | head -1)" >> ./am-scripts/"$ARCH"/"$arg"
  306. _edit_script_middle
  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_ending
  309. curl -Ls "$SOURCEFORGE" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep -i "$filetype" | grep -v '%' | head -1
  310. echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
  311. else
  312. _template_custom_download_url_as_version_variable
  313. fi
  314. sed -i 's/*mage/*/g' ./am-scripts/"$ARCH"/"$arg"
  315. }
  316. #####################################
  317. # LET CREATE OUR INSTALLATION SCRIPTS
  318. #####################################
  319. case $2 in
  320. '')
  321. echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit
  322. ;;
  323. esac
  324. ARGS="$(echo "$@" | cut -f2- -d ' ')"
  325. for arg in $ARGS; do
  326. arg=$(echo "$arg" | tr '[:upper:]' '[:lower:]')
  327. case $arg in
  328. *)
  329. cd "$SCRIPTDIR" || return
  330. echo "##############################################################"
  331. echo ""
  332. echo " Create a template for \"$arg\"" | tr '[:lower:]' '[:upper:]'
  333. echo ""
  334. echo "$DIVIDING_LINE"
  335. echo ""
  336. echo " EACH MODEL IS BASED ON A DIFFERENT METHOD OF BUILDING/UPDATING THE PROGRAM."
  337. echo ""
  338. echo " PLEASE, SELECT A TEMPLATE FOR \"$(echo "$arg" | tr '[:lower:]' '[:upper:]')\":"
  339. echo ""
  340. echo " 0) APPIMAGE, FROM ANY WEBSITE (BETTER IF FROM GITHUB.COM)"
  341. echo " 1) APPIMAGE ON-THE-FLY, USING A DEDICATED SCRIPT"
  342. echo " 2) ANY ARCHIVE/BINARY/SCRIPT FROM ANY WEBSITE"
  343. echo " 3) WEBAPP BASED ON A FIREFOX PROFILE (REQUIRES \"FIREFOX\" IN \$PATH)"
  344. echo ""
  345. read -r -p " WHAT KIND OF PROGRAM DO YOU WANT TO WRITE A SCRIPT FOR? : " templatetype
  346. case "$templatetype" in
  347. 0) # APPIMAGE (ANY)
  348. _template_create_dirs_and_ask_for_source
  349. # ADD THE NAME OF THE SOURCE
  350. 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
  351. case "$RESPONSE" in
  352. *)
  353. if echo "$RESPONSE" | grep -qi "^https.*github.com\|codeberg.org"; then
  354. _template_then_git_repo
  355. elif echo "$RESPONSE" | grep -q "sourceforge"; then
  356. _template_if_sourceforge
  357. else
  358. _template_description_if_hosted_elsewhere
  359. _template_help_by_repology
  360. fi
  361. esac
  362. # END OF THIS FUNCTION
  363. echo "$DIVIDING_LINE"
  364. echo -e "\n All files are saved in $SCRIPTDIR/am-scripts\n"
  365. ;;
  366. 1) # CREATE AN APPIMAGE ON-THE-FLY
  367. _template_create_dirs_and_ask_for_source
  368. _template_description_if_hosted_elsewhere
  369. _template_help_by_repology
  370. # ADD A LINEAR DOWNLOAD URL
  371. read -r -ep " ◆ ADD A LINEAR DOWNLOAD URL FOR THE SCRIPT OR LEAVE BLANK $(echo -e '\n : ')" dlurl
  372. case "$dlurl" in
  373. '')
  374. 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"
  375. ;;
  376. *)
  377. sed -i 's#wget "$version"#wget "'"$dlurl"'" -O '"$arg"'.sh && chmod '"$arg"'.sh && ./'"$arg"'.sh#g' ./am-scripts/"$ARCH"/"$arg"
  378. ;;
  379. esac
  380. # END OF THIS FUNCTION
  381. echo "$DIVIDING_LINE"
  382. echo -e "\n All files are saved in $SCRIPTDIR/am-scripts\n"
  383. ;;
  384. 2) # DOWNLOAD ANY ARCHIVE
  385. _template_create_dirs_and_ask_for_source
  386. # ADD THE NAME OF THE SOURCE
  387. 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
  388. case "$RESPONSE" in
  389. *)
  390. if echo "$RESPONSE" | grep -q "https://github.com"; then
  391. _template_then_git_repo
  392. elif echo "$RESPONSE" | grep -q "https://codeberg.org"; then
  393. _template_then_git_repo
  394. elif echo "$RESPONSE" | grep -q "sourceforge"; then
  395. _template_if_sourceforge
  396. else
  397. _template_description_if_hosted_elsewhere
  398. _template_help_by_repology
  399. fi
  400. esac
  401. # LAUNCHER AND ICON (OPTIONAL)
  402. read -r -p " ◆ Do you wish to add a launcher and a icon (y,N)? " yn
  403. if echo "$yn" | grep -qi "^y"; then
  404. # ADD LAUNCHER AND ICON REFERENCES TO THE INSTALLATION SCRIPT
  405. _template_generate_desktop_file
  406. # ENTER THE URL OF THE ICON THAT WILL APPEAR IN THE MENU
  407. read -r -ep " ◆ COPY/PASTE THE URL OF THE ICON HERE $(echo -e '\n URL: ')" ICONURL
  408. case "$ICONURL" in
  409. '') sed -i "s#ICONURL#https://portable-linux-apps.github.io/icons/$arg.png#g" ./am-scripts/"$ARCH"/"$arg"
  410. ;;
  411. *) sed -i "s#ICONURL#$ICONURL#g" ./am-scripts/"$ARCH"/"$arg"
  412. wget -q -P ./am-scripts/portable-linux-apps.github.io/icons/ "$ICONURL"
  413. ;;
  414. esac
  415. echo "$DIVIDING_LINE"
  416. # APPNAME
  417. read -r -ep ' ◆ NAME OF THE APP (for the "Name" entry of the .desktop file): ' APPNAME
  418. case "$APPNAME" in
  419. *)
  420. sed -i "s#APPNAME#$APPNAME#g" ./am-scripts/"$ARCH"/"$arg"
  421. ;;
  422. esac
  423. echo "$DIVIDING_LINE"
  424. # PUT THE APP INTO A CATEGORY, THIS IS NEEDED FOR OUR CUSTOM DESKTOP FILE
  425. _template_desktop_file_select_category
  426. else
  427. echo "$DIVIDING_LINE"
  428. fi
  429. # END OF THIS FUNCTION
  430. echo -e "\n All files are saved in $SCRIPTDIR/am-scripts\n"
  431. ;;
  432. 3) # CREATE A CUSTOM FIREFOX PROFILE ("firefox" MUST BE IN "$PATH" TO MADE IT WORK)
  433. _template_create_dirs_and_ask_for_source
  434. # USE THE SUFFIX FROM NOW ON
  435. mv ./am-scripts/"$ARCH"/"$arg" ./am-scripts/"$ARCH"/"ffwa-$arg"
  436. arg="ffwa-$arg"
  437. echo "$DIVIDING_LINE"
  438. read -r -ep " ◆ NAME OF THE APP: " RESPONSE
  439. case "$RESPONSE" in
  440. *)
  441. sed -i "s#GIVEMEANAME#$RESPONSE#g" ./am-scripts/"$ARCH"/"$arg"
  442. # CREATE A WEBPAGE FOR https://portable-linux-apps.github.io CONTAINING ALL THE INFO ABOUT THIS APP
  443. echo "# $(echo "$arg" | tr '[:lower:]' '[:upper:]')" >> ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md
  444. 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
  445. # CREATE A NEW LINE FOR THE APPLICATION'S LIST
  446. echo "◆ $arg : WebApp & Firefox Profile for $RESPONSE." >> ./am-scripts/list
  447. esac
  448. # PUT THE APP INTO A CATEGORY, THIS IS NEEDED FOR OUR CUSTOM DESKTOP FILE
  449. _template_desktop_file_select_category
  450. # ENTER THE URL OF THE SITE YOU WANT TO CREATE A CUSTOM FIREFOX PROFILE FOR
  451. read -r -ep " ◆ URL OF THE WEBAPP: " RESPONSE
  452. case "$RESPONSE" in
  453. *)
  454. 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
  455. ;;
  456. esac
  457. echo "$DIVIDING_LINE"
  458. # ENTER THE URL OF THE ICON THAT WILL APPEAR IN THE MENU
  459. read -r -ep " ◆ COPY/PASTE THE URL OF THE ICON HERE $(echo -e '\n URL: ')" RESPONSE
  460. case "$RESPONSE" in
  461. *)
  462. sed -i "s#YOURICONURL#$RESPONSE#g" ./am-scripts/"$ARCH"/"$arg"
  463. ;;
  464. esac
  465. echo "$DIVIDING_LINE"
  466. # END OF THIS FUNCTION
  467. echo -e "\n All files are saved in $SCRIPTDIR/am-scripts\n"
  468. ;;
  469. # NOTHING SELECTED
  470. *)
  471. echo -e "\n No valid argument was chosen: process aborted! \n" | tr '[:lower:]' '[:upper:]'; break
  472. ;;
  473. esac
  474. esac
  475. done