setup-termux.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* eslint-disable */
  2. const {existsSync, writeFileSync} = require('fs');
  3. const {spawnSync} = require('child_process');
  4. const {HOME, PATH} = process.env;
  5. const CONFIG_FILE = 'd-fi.config.json';
  6. if (HOME && PATH.includes('com.termux') && !existsSync(CONFIG_FILE)) {
  7. console.log('Setting config file for termux users in ' + CONFIG_FILE);
  8. const STORAGE_LOCATION = `${HOME}/storage`;
  9. const DOWNLOAD_LOCATION = `${STORAGE_LOCATION}/downloads`;
  10. if (!existsSync(STORAGE_LOCATION)) {
  11. console.log(
  12. `It is necessary to grant storage permission for Termux on Android 6 and higher. Use 'Settings>Apps>Termux>Permissions>Storage' and set to true.`,
  13. );
  14. spawnSync('termux-setup-storage');
  15. }
  16. if (existsSync(DOWNLOAD_LOCATION)) {
  17. writeFileSync(
  18. CONFIG_FILE,
  19. JSON.stringify(
  20. {
  21. saveLayout: {
  22. track: `${DOWNLOAD_LOCATION}/Music/{ALB_TITLE}/{SNG_TITLE}`,
  23. album: `${DOWNLOAD_LOCATION}/Music/{ALB_TITLE}/{SNG_TITLE}`,
  24. artist: `${DOWNLOAD_LOCATION}/Music/{ALB_TITLE}/{SNG_TITLE}`,
  25. playlist: `${DOWNLOAD_LOCATION}/Playlist/{TITLE}/{SNG_TITLE}`,
  26. },
  27. },
  28. null,
  29. 2,
  30. ),
  31. 'utf-8',
  32. );
  33. console.log('Done. Config created.');
  34. } else {
  35. console.error('Something went wrong. Cannot find downloads location: ' + DOWNLOAD_LOCATION);
  36. }
  37. }