spacepaste

  1.  
  2. ### for raw view on ios where the
  3. ### 1st or 2nd lines are cut off
  4. ### by the screen
  5. printf "NOTICE: this does NOT package special files like pts/tty devices, anything in /dev, and so on however it CAN package fifo's, named pipes, and sockets, into the archive... continuing in 4 seconds\nnote: sed '5s//<new>/g' replaces line 5 with whatever u want\n"
  6. # sleep 4
  7. fatal() { echo error: cannot embed "'$path'" into executable: "'$path'" does not exist; exit; }
  8. fatal2() { echo error: cannot embed "'$path'" into executable: "'$path'" does not contain any valid files; exit; }
  9. fatal3() { echo error: cannot embed "'$path'" into executable: "'$path'" is a "'$type'" file; exit; }
  10. fatal4() { echo error: cannot embed "'$1'" into executable: "'$1'" is of type "'$2'"; exit; }
  11. strippath()
  12. {
  13. realpath1=$(readlink -f "$1")
  14. pathdir1=$(dirname "$realpath1")
  15. pathdir1="$pathdir1/"
  16. echo "$pathdir1"
  17. }
  18. preinitmulti() { mkdir -v Converted ; mkdir -v Converted/"$pathbaseprefix" ; cd Converted/"$pathbaseprefix"
  19. printf '%b' '/* */
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <unistd.h>
  23. #include <limits.h>
  24. #include <assert.h>
  25. #include <string.h>
  26. #include <errno.h>
  27. #include <libgen.h>
  28. #include <sys/stat.h>
  29. #include <sys/types.h>
  30. // "look deep into yourself, Clarice" -- Hanibal Lector
  31. char findyourself_save_pwd[PATH_MAX];
  32. char findyourself_save_argv0[PATH_MAX];
  33. char findyourself_save_path[PATH_MAX];
  34. char findyourself_path_separator='"'/'"';
  35. char findyourself_path_separator_as_string[2]="/";
  36. char findyourself_path_list_separator[8]=":"; // could be ":; "
  37. char findyourself_debug=0;
  38. int findyourself_initialized=0;
  39. void findyourself_init(char *argv0)
  40. {
  41. getcwd(findyourself_save_pwd, sizeof(findyourself_save_pwd));
  42. strncpy(findyourself_save_argv0, argv0, sizeof(findyourself_save_argv0));
  43. findyourself_save_argv0[sizeof(findyourself_save_argv0)-1]=0;
  44. strncpy(findyourself_save_path, getenv("PATH"), sizeof(findyourself_save_path));
  45. findyourself_save_path[sizeof(findyourself_save_path)-1]=0;
  46. findyourself_initialized=1;
  47. }
  48. int find_yourself(char *result, size_t size_of_result)
  49. {
  50. char newpath[PATH_MAX+256];
  51. char newpath2[PATH_MAX+256];
  52. assert(findyourself_initialized);
  53. result[0]=0;
  54. if(findyourself_save_argv0[0]==findyourself_path_separator) {
  55. if(findyourself_debug) printf(" absolute path\\n");
  56. realpath(findyourself_save_argv0, newpath);
  57. if(findyourself_debug) printf(" newpath=\"%s\"\\n", newpath);
  58. if(!access(newpath, F_OK)) {
  59. strncpy(result, newpath, size_of_result);
  60. result[size_of_result-1]=0;
  61. return(0);
  62. } else {
  63. perror("access failed 1");
  64. }
  65. } else if( strchr(findyourself_save_argv0, findyourself_path_separator )) {
  66. if(findyourself_debug) printf(" relative path to pwd\\n");
  67. strncpy(newpath2, findyourself_save_pwd, sizeof(newpath2));
  68. newpath2[sizeof(newpath2)-1]=0;
  69. strncat(newpath2, findyourself_path_separator_as_string, sizeof(newpath2));
  70. newpath2[sizeof(newpath2)-1]=0;
  71. strncat(newpath2, findyourself_save_argv0, sizeof(newpath2));
  72. newpath2[sizeof(newpath2)-1]=0;
  73. realpath(newpath2, newpath);
  74. if(findyourself_debug) printf(" newpath=\"%s\"\\n", newpath);
  75. if(!access(newpath, F_OK)) {
  76. strncpy(result, newpath, size_of_result);
  77. result[size_of_result-1]=0;
  78. return(0);
  79. } else {
  80. perror("access failed 2");
  81. }
  82. } else {
  83. if(findyourself_debug) printf(" searching $PATH\\n");
  84. char *saveptr;
  85. char *pathitem;
  86. for(pathitem=strtok_r(findyourself_save_path, findyourself_path_list_separator, &saveptr); pathitem; pathitem=strtok_r(NULL, findyourself_path_list_separator, &saveptr) ) {
  87. if(findyourself_debug>=2) printf("pathitem=\"%s\"\\n", pathitem);
  88. strncpy(newpath2, pathitem, sizeof(newpath2));
  89. newpath2[sizeof(newpath2)-1]=0;
  90. strncat(newpath2, findyourself_path_separator_as_string, sizeof(newpath2));
  91. newpath2[sizeof(newpath2)-1]=0;
  92. strncat(newpath2, findyourself_save_argv0, sizeof(newpath2));
  93. newpath2[sizeof(newpath2)-1]=0;
  94. realpath(newpath2, newpath);
  95. if(findyourself_debug) printf(" newpath=\"%s\"\\n", newpath);
  96. if(!access(newpath, F_OK)) {
  97. strncpy(result, newpath, size_of_result);
  98. result[size_of_result-1]=0;
  99. return(0);
  100. }
  101. } // end for
  102. perror("access failed 3");
  103. } // end else
  104. // if we get here, we have tried all three methods on argv[0] and still haven'"'"'t succeeded. Include fallback methods here.
  105. return(1);
  106. }
  107. #include <stddef.h>
  108. #include <stdio.h>
  109. #include <errno.h>
  110. #include <stdlib.h>
  111. #include <string.h>
  112. #include <sys/socket.h>
  113. #include <sys/un.h>
  114. int
  115. make_named_socket (const char *filename)
  116. {
  117. struct sockaddr_un name;
  118. int sock;
  119. size_t size;
  120. /* Create the socket. */
  121. sock = socket (PF_LOCAL, SOCK_DGRAM, 0);
  122. if (sock < 0)
  123. {
  124. perror ("socket");
  125. exit (EXIT_FAILURE);
  126. }
  127. /* Bind a name to the socket. */
  128. name.sun_family = AF_LOCAL;
  129. strncpy (name.sun_path, filename, sizeof (name.sun_path));
  130. name.sun_path[sizeof (name.sun_path) - 1] = '"'\\\0'"';
  131. /* The size of the address is
  132. the offset of the start of the filename,
  133. plus its length (not including the terminating null byte).
  134. Alternatively you can just do:
  135. size = SUN_LEN (&name);
  136. */
  137. size = (offsetof (struct sockaddr_un, sun_path)
  138. + strlen (name.sun_path));
  139. if (bind (sock, (struct sockaddr *) &name, size) < 0)
  140. {
  141. perror ("bind");
  142. exit (EXIT_FAILURE);
  143. }
  144. return sock;
  145. }
  146. int main(int argc, char **argv)
  147. {
  148. findyourself_init(argv[0]);
  149. char newpath[PATH_MAX];
  150. find_yourself(newpath, sizeof(newpath));
  151. if(1 || strcmp(argv[0],newpath)) { }
  152. char *dummy = strdup( newpath );
  153. char *dname = dirname( dummy );
  154. printf("Extracting...\\n");
  155. ' > main.c; }
  156. objectconvert() {
  157. path="$1" && objectfile=$(echo "$path" | sed 's/.*\///') && symbol=$(echo "$path" | tr '\000-\057\072-\100\133-\140\173-\255' '_') && mkdir Converted ; mkdir Converted/"$objectfile" ; cd Converted/"$objectfile" && object=$(objcopy --input binary --output elf64-x86-64 --binary-architecture i386 "$path" "$objectfile".o -v | sed 's/.*to `//' | sed s/\'.*//) && start=$(nm "$object" | sed 's/.* _/_/' | grep "$symbol"start) && size=$(nm "$object" | sed 's/.* _/_/' | grep "$symbol"size) && end=$(nm "$object" | sed 's/.* _/_/' | grep "$symbol"end) && printf '%b' '/* */
  158. #include <stdlib.h>
  159. #include <stdio.h>
  160. #include <unistd.h>
  161. #include <limits.h>
  162. #include <assert.h>
  163. #include <string.h>
  164. #include <errno.h>
  165. #include <libgen.h>
  166. // "look deep into yourself, Clarice" -- Hanibal Lector
  167. char findyourself_save_pwd[PATH_MAX];
  168. char findyourself_save_argv0[PATH_MAX];
  169. char findyourself_save_path[PATH_MAX];
  170. char findyourself_path_separator='"'/'"';
  171. char findyourself_path_separator_as_string[2]="/";
  172. char findyourself_path_list_separator[8]=":"; // could be ":; "
  173. char findyourself_debug=0;
  174. int findyourself_initialized=0;
  175. void findyourself_init(char *argv0)
  176. {
  177. getcwd(findyourself_save_pwd, sizeof(findyourself_save_pwd));
  178. strncpy(findyourself_save_argv0, argv0, sizeof(findyourself_save_argv0));
  179. findyourself_save_argv0[sizeof(findyourself_save_argv0)-1]=0;
  180. strncpy(findyourself_save_path, getenv("PATH"), sizeof(findyourself_save_path));
  181. findyourself_save_path[sizeof(findyourself_save_path)-1]=0;
  182. findyourself_initialized=1;
  183. }
  184. int find_yourself(char *result, size_t size_of_result)
  185. {
  186. char newpath[PATH_MAX+256];
  187. char newpath2[PATH_MAX+256];
  188. assert(findyourself_initialized);
  189. result[0]=0;
  190. if(findyourself_save_argv0[0]==findyourself_path_separator) {
  191. if(findyourself_debug) printf(" absolute path\\n");
  192. realpath(findyourself_save_argv0, newpath);
  193. if(findyourself_debug) printf(" newpath=\"%s\"\\n", newpath);
  194. if(!access(newpath, F_OK)) {
  195. strncpy(result, newpath, size_of_result);
  196. result[size_of_result-1]=0;
  197. return(0);
  198. } else {
  199. perror("access failed 1");
  200. }
  201. } else if( strchr(findyourself_save_argv0, findyourself_path_separator )) {
  202. if(findyourself_debug) printf(" relative path to pwd\\n");
  203. strncpy(newpath2, findyourself_save_pwd, sizeof(newpath2));
  204. newpath2[sizeof(newpath2)-1]=0;
  205. strncat(newpath2, findyourself_path_separator_as_string, sizeof(newpath2));
  206. newpath2[sizeof(newpath2)-1]=0;
  207. strncat(newpath2, findyourself_save_argv0, sizeof(newpath2));
  208. newpath2[sizeof(newpath2)-1]=0;
  209. realpath(newpath2, newpath);
  210. if(findyourself_debug) printf(" newpath=\"%s\"\\n", newpath);
  211. if(!access(newpath, F_OK)) {
  212. strncpy(result, newpath, size_of_result);
  213. result[size_of_result-1]=0;
  214. return(0);
  215. } else {
  216. perror("access failed 2");
  217. }
  218. } else {
  219. if(findyourself_debug) printf(" searching $PATH\\n");
  220. char *saveptr;
  221. char *pathitem;
  222. for(pathitem=strtok_r(findyourself_save_path, findyourself_path_list_separator, &saveptr); pathitem; pathitem=strtok_r(NULL, findyourself_path_list_separator, &saveptr) ) {
  223. if(findyourself_debug>=2) printf("pathitem=\"%s\"\\n", pathitem);
  224. strncpy(newpath2, pathitem, sizeof(newpath2));
  225. newpath2[sizeof(newpath2)-1]=0;
  226. strncat(newpath2, findyourself_path_separator_as_string, sizeof(newpath2));
  227. newpath2[sizeof(newpath2)-1]=0;
  228. strncat(newpath2, findyourself_save_argv0, sizeof(newpath2));
  229. newpath2[sizeof(newpath2)-1]=0;
  230. realpath(newpath2, newpath);
  231. if(findyourself_debug) printf(" newpath=\"%s\"\\n", newpath);
  232. if(!access(newpath, F_OK)) {
  233. strncpy(result, newpath, size_of_result);
  234. result[size_of_result-1]=0;
  235. return(0);
  236. }
  237. } // end for
  238. perror("access failed 3");
  239. } // end else
  240. // if we get here, we have tried all three methods on argv[0] and still haven'"'"'t succeeded. Include fallback methods here.
  241. return(1);
  242. }
  243. #include <stddef.h>
  244. #include <stdio.h>
  245. #include <errno.h>
  246. #include <stdlib.h>
  247. #include <string.h>
  248. #include <sys/socket.h>
  249. #include <sys/un.h>
  250. int
  251. make_named_socket (const char *filename)
  252. {
  253. struct sockaddr_un name;
  254. int sock;
  255. size_t size;
  256. /* Create the socket. */
  257. sock = socket (PF_LOCAL, SOCK_DGRAM, 0);
  258. if (sock < 0)
  259. {
  260. perror ("socket");
  261. exit (EXIT_FAILURE);
  262. }
  263. /* Bind a name to the socket. */
  264. name.sun_family = AF_LOCAL;
  265. strncpy (name.sun_path, filename, sizeof (name.sun_path));
  266. name.sun_path[sizeof (name.sun_path) - 1] = '"'\\\0'"';
  267. /* The size of the address is
  268. the offset of the start of the filename,
  269. plus its length (not including the terminating null byte).
  270. Alternatively you can just do:
  271. size = SUN_LEN (&name);
  272. */
  273. size = (offsetof (struct sockaddr_un, sun_path)
  274. + strlen (name.sun_path));
  275. if (bind (sock, (struct sockaddr *) &name, size) < 0)
  276. {
  277. perror ("bind");
  278. exit (EXIT_FAILURE);
  279. }
  280. return sock;
  281. }
  282. int main(int argc, char **argv)
  283. {
  284. findyourself_init(argv[0]);
  285. char newpath[PATH_MAX];
  286. find_yourself(newpath, sizeof(newpath));
  287. if(1 || strcmp(argv[0],newpath)) { }
  288. char *dummy = strdup( newpath );
  289. char *dname = dirname( dummy );
  290. printf("Extracting...\\n");
  291. ' > main.c && printf '
  292. // OBJECT START
  293. extern char '"$start"';
  294. extern char '"$size"'; // we keep this just in case we ever need it
  295. extern char '"$end"';
  296. char * p = &'"$start"';
  297. FILE *fp;
  298. chdir(dname);
  299. fp = fopen("'"$objectfile"'", ("'"w+"'"));
  300. while ( p != &'"$end"' ) fputc(*p++, fp); // credit for fputc(*p++, fp): flawless_snowflake from kik messenger
  301. // char y[3];
  302. // strcpy(y, x);
  303. fclose(fp);
  304. // OBJECT END
  305. ' >> main.c ; }
  306. objectconvertMulti() {
  307. path="$1" && objectfile=$(echo "$path" | tr '\000-\057\072-\100\133-\140\173-\255' '_') && symbol=$(echo "$path" | tr '\000-\057\072-\100\133-\140\173-\255' '_') && object=$(objcopy --input binary --output elf64-x86-64 --binary-architecture i386 "$path" "$2".o -v | sed 's/.*to `//' | sed s/\'.*// | sed 's/ /_/g') && objectlist+="$object " && start=$(nm "$object" | sed 's/.* _/_/' | grep "$symbol"start) && size=$(nm "$object" | sed 's/.* _/_/' | grep "$symbol"size) && end=$(nm "$object" | sed 's/.* _/_/' | grep "$symbol"end) && printf '
  308. // OBJECT START
  309. extern char '"$start"';
  310. extern char '"$size"'; // we keep this just in case we ever need it
  311. extern char '"$end"';
  312. char * '"a$2"'p = &'"$start"';
  313. FILE *'"a$2"'fp;
  314. chdir(dname);
  315. ' >> main.c
  316. patha5rray=($(echo "$3" | sed s/"\/"/\ /g))
  317. for b in ${patha5rray[@]}
  318. do
  319. printf '%b' 'mkdir("'"$b"'", 0777); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  320. chdir("'"$b"'"); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  321. ' >> main.c
  322. done
  323. printf '
  324. '"a$2"'fp = fopen("'"./$4"'", ("'"w+"'"));
  325. while ( '"a$2"'p != &'"$end"' ) fputc(*'"a$2"'p++, '"a$2"'fp); // credit for fputc(*p++, fp): flawless_snowflake from kik messenger
  326. fclose('"a$2"'fp);
  327. chmod("'"./$4"'", '"$5"');
  328. chdir(dname);
  329. // OBJECT END
  330. ' >> main.c ; }
  331. mksymlink() {
  332. printf '
  333. // SYMLINK START
  334. chdir(dname);
  335. ' >> "$orgp2/main.c"
  336. patha5rray=($(echo "$1" | sed s/"\/"/\ /g))
  337. for b in ${patha5rray[@]}
  338. do
  339. printf '%b' 'mkdir("'"$b"'", 0777); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  340. chdir("'"$b"'"); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  341. ' >> "$orgp2/main.c"
  342. done
  343. printf '
  344. symlink("'"$3"'", "'"$2"'");
  345. chmod("'"./$2"'", '"$4"');
  346. chdir(dname);
  347. // SYMLINK END
  348. ' >> "$orgp2/main.c" ; }
  349. mkfifoC() {
  350. printf '
  351. // FIFO START
  352. chdir(dname);
  353. ' >> main.c
  354. patha5rray=($(echo "$1" | sed s/"\/"/\ /g))
  355. for b in ${patha5rray[@]}
  356. do
  357. printf '%b' 'mkdir("'"$b"'", 0777); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  358. chdir("'"$b"'"); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  359. ' >> main.c
  360. done
  361. printf '
  362. mkfifo("'"$2"'", '"$3"');
  363. chdir(dname);
  364. // FIFO END
  365. ' >> main.c ; }
  366. mkdirs() {
  367. printf '
  368. // MKDIRS START
  369. chdir(dname);
  370. ' >> main.c
  371. patha5rray=($(echo "$1" | sed s/"\/"/\ /g))
  372. for b in ${patha5rray[@]}
  373. do
  374. printf '%b' 'mkdir("'"$b"'", 0777);
  375. // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  376. chdir("'"$b"'"); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  377. ' >> main.c
  378. done
  379. printf '
  380. chdir(dname);
  381. // MKDIRS END
  382. ' >> main.c ; }
  383. chmoddir() {
  384. printf '
  385. // CHMODDIR START
  386. chdir(dname);
  387. chmod("'"$1"'", '"$2"');
  388. chdir(dname);
  389. // CHMODDIR END
  390. ' >> main.c ; }
  391. mksocket() {
  392. printf '
  393. // SOCKET START
  394. chdir(dname);
  395. ' >> main.c
  396. patha5rray=($(echo "$1" | sed s/"\/"/\ /g))
  397. for b in ${patha5rray[@]}
  398. do
  399. printf '%b' 'mkdir("'"$b"'", 0777); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  400. chdir("'"$b"'"); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  401. ' >> main.c
  402. done
  403. printf '
  404. make_named_socket("'"$2"'");
  405. chmod("'"./$2"'", '"$3"');
  406. chdir(dname);
  407. // SOCKET END
  408. ' >> main.c ; }
  409. mkemptyfile() {
  410. printf '
  411. // EMPTY FILE START
  412. chdir(dname);
  413. ' >> "$orgp2/main.c"
  414. patha5rray=($(echo "$1" | sed s/"\/"/\ /g))
  415. for b in ${patha5rray[@]}
  416. do
  417. printf '%b' 'mkdir("'"$b"'", 0777); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  418. chdir("'"$b"'"); // Simulates the mkdir -p ( mkdir --help: -p, --parents ) argument of the mkdir binary found in /bin/mkdir or /usr/bin/mkdir
  419. ' >> "$orgp2/main.c"
  420. done
  421. printf '
  422. FILE *'"e$4"'fp;
  423. '"e$4"'fp = fopen("'"./$2"'", ("'"w+"'"));
  424. fclose('"e$4"'fp);
  425. chmod("'"./$2"'", '"$3"');
  426. chdir(dname);
  427. // EMPTY FILE END
  428. ' >> "$orgp2/main.c" ; }
  429. compile() { gcc -g main.c "$object" -static && wait
  430. }
  431. compilemulti() { gcc -g main.c $objectlist -static && wait
  432. }
  433. compiledebug() { cat ./main.c && gcc -g main.c "$object" -static && wait && echo size of "$path" is $( wc -c < "$path" ) && declare -p path objectfile object start end
  434. }
  435. compilemultidebug() { cat ./main.c && gcc -g main.c $objectlist -static && wait
  436. }
  437. fin() { printf '
  438. free( dummy );
  439. printf("Extracted\\n");
  440. return 0;
  441. }
  442. ' >> main.c
  443. }
  444. finmulti() { printf '
  445. free( dummy );
  446. printf("Extracted\\n");
  447. return 0;
  448. }
  449. ' >> main.c
  450. }
  451. finish() { if [[ -f "$path" || -f "$replacement" ]] ; then
  452. cd "$origin"
  453. printf "\
  454. package created \n\
  455. "
  456. fi
  457. }
  458. finishdebug() { if [[ -f "$path" || -f "$replacement" ]] ; then
  459. pwd
  460. printf "\
  461. path= $(ls -Ls ""$path"" )\n\
  462. object= $(ls -Ls ""$object"")\n\
  463. replacement= $(ls -Ls ""$replacement"")\n\
  464. output= $(ls -Ls ./""$object""'bject')\n\
  465. package created \n\
  466. "
  467. cd "$origin"
  468. fi
  469. }
  470. finishmulti() { if [[ -f "$path" || -f "$replacement" ]] ; then
  471. cd "$origin"
  472. printf "\
  473. \n\
  474. package created with $(echo "${objectlist[@]}" | tr ' ' '\n' | wc -l) embeddable files ($(find "$origin"/Converted/Multi | grep "\.o$" | wc -l) recorded files, $(find "$pathreal" -type f | wc -l) physical files, $(find "$pathreal" -type d | wc -l) physical directories, $(echo "${objectlist[@]}" | tr ' ' '\n' | grep -v ^$ | wc -l) non-empty files worth $(echo "${objectlist[@]}" | wc -c) characters, $(echo "${objectlist[@]}" | tr ' ' '\n' | grep ^$ | wc -l) empty, $(echo "${objectlist[@]}" | tr ' ' '\n' | uniq -D | wc -l) duplicates, $(echo "${symlinksreal[@]}" | tr ' ' '\n' | wc -l) symlinks, $(echo "${fifosreal[@]}" | tr ' ' '\n' | wc -l) fifo's (named pipes), and $(echo "${socketsreal[@]}" | tr ' ' '\n' | wc -l) sockets) \n\
  475. "
  476. fi
  477. }
  478. finishmultidebug() { if [[ -f "$path" || -f "$replacement" ]] ; then
  479. pwd
  480. printf "\
  481. objects= $(ls -L $objectlist | tr "\n" " ")\n\
  482. output= $(ls -Ls ./a.out) \n\
  483. package created \n\
  484. "
  485. cd "$origin"
  486. fi
  487. }
  488. replacement="$(whereis "$1" | cut -d ' ' -f2)"
  489. origin=$(pwd)
  490. # im just going to assume that $0 will NEVER ever contain any of a script's arguments in any cercimstance
  491. path="$1"
  492. if [[ -d "$path" ]]; then
  493. echo "$path" is a directory
  494. # stat -c %a ./test/2 # permisions in chmod format
  495. # stat -c %F ./test/2 # type
  496. stripped="$(strippath "$path" )"
  497. pathreal="$(readlink -f "$path" )"
  498. pathdir="$(dirname "${pathreal[i]}")"
  499. pathdir="$pathdir/"
  500. pathbaseprefix=("${pathreal[i]#$pathdir}")
  501. mapfile -d '' -t blocksreal < <(find "${pathreal[0]}" '(' -not -type d ')' -not -empty -type b -print0)
  502. mapfile -d '' -t characterall < <(find "${pathreal[0]}" '(' -not -type d ')' -not -empty -type c -print0)
  503. mapfile -d '' -t dirsreal < <(find "${pathreal[0]}" -type d -print0)
  504. mapfile -d '' -t fifosreal < <(find "${pathreal[0]}" '(' -not -type d ')' -not -empty -type p -print0)
  505. mapfile -d '' -t filesreal < <(find "${pathreal[0]}" '(' -not -type d ')' -not -empty -type f -print0)
  506. mapfile -d '' -t emptyreal < <(find "${pathreal[0]}" '(' -not -type d ')' -empty -type f -print0)
  507. mapfile -d '' -t symlinksreal < <(find "${pathreal[0]}" '(' -not -type d ')' -not -empty -type l -print0)
  508. mapfile -d '' -t socketsreal < <(find "${pathreal[0]}" '(' -not -type d ')' -not -empty -type s -print0)
  509. if [[ -z ${dirsreal[@]} && -z ${fifosreal[@]} && -z ${filesreal[@]} && -z ${emptyreal[@]} && -z ${symlinksreal[@]} ]] ; then
  510. fatal2
  511. fi
  512. orgp="$(pwd)"
  513. preinitmulti
  514. orgp2="$(pwd)"
  515. for i in ${!filesreal[@]}
  516. do
  517. pathdir="$(dirname "${filesreal[i]}")"
  518. pathdir="$pathdir/"
  519. pathbase=("${filesreal[i]#$pathdir}")
  520. pathstripped=("${pathdir#$stripped}")
  521. objectconvertMulti "${filesreal[i]}" "$i" "$pathstripped" "${pathbase[0]}" "$(stat -c '%05a' "${filesreal[i]}")"
  522. echo "${filesreal[i]}" processed
  523. done
  524. cd "$orgp"
  525. for i in ${!emptyreal[@]}
  526. do
  527. pathdir="$(dirname "${emptyreal[i]}")"
  528. pathdir="$pathdir/"
  529. pathbase=("${emptyreal[i]#$pathdir}")
  530. pathstripped=("${pathdir#$stripped}")
  531. mkemptyfile "$pathstripped" "${pathbase[0]}" "$(stat -c '%05a' "${emptyreal[i]}")" "emp$i"
  532. echo "${emptyreal[i]}" processed
  533. done
  534. for i in "${!symlinksreal[@]}"
  535. do
  536. echo "${symlinksreal[i]}" is a symlink, following...
  537. pathdir="$(dirname "${symlinksreal[i]}")"
  538. pathdir="$pathdir/"
  539. cd "$pathdir"
  540. pathbase=("${symlinksreal[i]#$pathdir}")
  541. pathstripped=("${pathdir#$stripped}")
  542. symlinkorigin+=("${symlinksreal[i]}")
  543. symlinkvalue+=("$(readlink "${symlinksreal[i]}")")
  544. symlinktypevalue+=("$(stat -c %F "${symlinkvalue[i]}")")
  545. # echo "symlinkorigin = ${symlinkorigin[i]}"
  546. # echo "symlinkvalue = ${symlinkvalue[i]}"
  547. # echo "symlinktypevalue = ${symlinktypevalue[i]}"
  548. if [[ ${symlinktypevalue[i]} != "symbolic link" ]]
  549. then
  550. symlinkfullpath+=("$(readlink -f $(readlink "${symlinksreal[i]}"))")
  551. symlinktypepath+=("$(stat -c %F "${symlinkfullpath[i]}")")
  552. # echo "symlinkfullpath = ${symlinkfullpath[i]}"
  553. # echo "symlinktypepath = ${symlinktypepath[i]}"
  554. if [[ ! -e ${symlinkfullpath[i]} ]] ; then
  555. fatal4 "${symlinkfullpath[i]}" "${symlinktypepath[i]}"
  556. elif [[ -S ${symlinkfullpath[i]} ]] ; then
  557. type='socket'
  558. fatal4 "${symlinkfullpath[i]}" "${symlinktypepath[i]}"
  559. elif [[ -p ${symlinkfullpath[i]} ]] ; then
  560. type='named pipe (fifo)'
  561. fatal4 "${symlinkfullpath[i]}" "${symlinktypepath[i]}"
  562. elif [[ -c ${symlinkfullpath[i]} ]] ; then
  563. type='character'
  564. fatal4 "${symlinkfullpath[i]}" "${symlinktypepath[i]}"
  565. elif [[ -b ${symlinkfullpath[i]} ]] ; then
  566. type='block'
  567. fatal4 "${symlinkfullpath[i]}" "${symlinktypepath[i]}"
  568. elif [[ ! -s ${symlinkfullpath[i]} ]] ; then
  569. type='empty'
  570. pathdir="$(dirname "${symlinkfullpath[i]}")"
  571. pathdir="$pathdir/"
  572. pathbase=("${symlinkfullpath[i]#$pathdir}")
  573. pathstripped=("${pathdir#$stripped}")
  574. mkemptyfile "$pathstripped" "${pathbase[0]}" "$(stat -c '%05a' "${symlinkfullpath[i]}")" "sym$i"
  575. echo "${symlinkfullpath[i]}" processed
  576. # fatal4 "${symlinkfullpath[i]}" "${symlinktypepath[i]}"
  577. # elif [[ -f $path ]] ; then
  578. # type='regular'
  579. # fatal4
  580. fi
  581. else
  582. symlinkfullpath+=("null")
  583. fi
  584. cd "$orgp"
  585. done
  586. for i in ${!symlinkvalue[@]}
  587. do
  588. cd "$orgp"
  589. echo "${symlinkorigin[i]} is a symlink to ${symlinkvalue[i]} (${symlinkfullpath[i]}) with type ${symlinktypevalue[i]}"
  590. pathdir="$(dirname "${symlinkorigin[i]}")"
  591. pathdir="$pathdir/"
  592. cd "$pathdir"
  593. pathbase=("${symlinkorigin[i]#$pathdir}")
  594. pathstripped=("${pathdir#$stripped}")
  595. mksymlink "$pathstripped" "${pathbase[0]}" "${symlinkvalue[i]}" "$(stat -c '%05a' "${symlinkorigin[i]}")"
  596. echo "${symlinkorigin[i]}" processed
  597. cd "$orgp"
  598. done
  599. cd "$orgp2"
  600. for i in ${!fifosreal[@]}
  601. do
  602. pathdir="$(dirname "${fifosreal[i]}")"
  603. pathdir="$pathdir/"
  604. pathbase=("${fifosreal[i]#$pathdir}")
  605. pathstripped=("${pathdir#$stripped}")
  606. mkfifoC "$pathstripped" "${pathbase[0]}" "$(stat -c '%05a' "${fifosreal[i]}")"
  607. echo "${fifosreal[i]}" processed
  608. done
  609. for i in ${!socketsreal[@]}
  610. do
  611. pathdir="$(dirname "${socketsreal[i]}")"
  612. pathdir="$pathdir/"
  613. pathbase=("${socketsreal[i]#$pathdir}")
  614. pathstripped=("${pathdir#$stripped}")
  615. mksocket "$pathstripped" "${pathbase[0]}" "$(stat -c '%05a' "${socketsreal[i]}")"
  616. echo "${socketsreal[i]}" processed
  617. done
  618. for i in ${!dirsreal[@]}
  619. do
  620. pathdir="$(dirname "${dirsreal[i]}")"
  621. if [[ $pathdir = "/" ]]
  622. then
  623. pathdir=
  624. fi
  625. pathdir="$pathdir/"
  626. pathbase=("${dirsreal[i]#$pathdir}")
  627. pathstripped=("${pathdir#$stripped}")
  628. if [[ $pathstripped = "/" ]]
  629. then
  630. pathstripped=
  631. fi
  632. mkdirs "$pathstripped$pathbase"
  633. echo "${dirsreal[i]}" processed
  634. done
  635. for i in ${!dirsreal[@]}
  636. do
  637. pathdir="$(dirname "${dirsreal[i]}")"
  638. if [[ $pathdir = "/" ]]
  639. then
  640. pathdir=
  641. fi
  642. pathdir="$pathdir/"
  643. pathbase=("${dirsreal[i]#$pathdir}")
  644. pathstripped=("${pathdir#$stripped}")
  645. if [[ $pathstripped = "/" ]]
  646. then
  647. pathstripped=
  648. fi
  649. chmoddir "$pathstripped$pathbase" "$(stat -c '%05a' "${dirsreal[i]}")"
  650. echo "$pathstripped$pathbase" processed
  651. done
  652. finmulti
  653. compilemulti
  654. finishmulti
  655. exit
  656. elif [ "$(printf '%s\n' "$path" | grep -e ^"/")" ]; then
  657. if [[ -L $path ]] ; then
  658. echo $path is a symlink, following...
  659. path="$(readlink $path)"
  660. if [[ ! -e $path ]] ; then
  661. fatal
  662. elif [[ -S $path ]] ; then
  663. type='socket'
  664. fatal3
  665. elif [[ -p $path ]] ; then
  666. type='named pipe (fifo)'
  667. fatal3
  668. elif [[ -c $path ]] ; then
  669. type='character'
  670. fatal3
  671. elif [[ -b $path ]] ; then
  672. type='block'
  673. fatal3
  674. elif [[ ! -s $path ]] ; then
  675. type='empty'
  676. fatal3
  677. # elif [[ -f $path ]] ; then
  678. # type='regular'
  679. # fatal3
  680. fi
  681. elif [[ ! -e $path ]] ; then
  682. fatal
  683. elif [[ -S $path ]] ; then
  684. type='socket'
  685. fatal3
  686. elif [[ -p $path ]] ; then
  687. type='named pipe (fifo)'
  688. fatal3
  689. elif [[ -c $path ]] ; then
  690. type='character'
  691. fatal3
  692. elif [[ -b $path ]] ; then
  693. type='block'
  694. fatal3
  695. elif [[ ! -s $path ]] ; then
  696. type='empty'
  697. fatal3
  698. # elif [[ -f $path ]] ; then
  699. # type='regular'
  700. # fatal3
  701. fi
  702. path="$path"
  703. elif [ "$(printf '%s\n' "$path" | grep -e ^"./" -e ^"../")" ]; then
  704. if [[ -L $path ]] ; then
  705. echo $path is a symlink, following...
  706. symlinkvalue="$(readlink $path)"
  707. symlinkfullpath="$(readlink -f "$(readlink $path)")"
  708. stat -c %F "$symlinkfullpath"
  709. declare -p symlinkfullpath symlinkvalue
  710. path=$symlinkfullpath
  711. if [[ ! -e $path ]] ; then
  712. fatal
  713. elif [[ -S $path ]] ; then
  714. type='socket'
  715. fatal3
  716. elif [[ -p $path ]] ; then
  717. type='named pipe (fifo)'
  718. fatal3
  719. elif [[ -c $path ]] ; then
  720. type='character'
  721. fatal3
  722. elif [[ -b $path ]] ; then
  723. type='block'
  724. fatal3
  725. elif [[ ! -s $path ]] ; then
  726. type='empty'
  727. fatal3
  728. # elif [[ -f $path ]] ; then
  729. # type='regular'
  730. # fatal3
  731. fi
  732. elif [[ ! -e $path ]] ; then
  733. fatal
  734. elif [[ -S $path ]] ; then
  735. type='socket'
  736. fatal3
  737. elif [[ -p $path ]] ; then
  738. type='named pipe (fifo)'
  739. fatal3
  740. elif [[ -c $path ]] ; then
  741. type='character'
  742. fatal3
  743. elif [[ -b $path ]] ; then
  744. type='block'
  745. fatal3
  746. elif [[ ! -s $path ]] ; then
  747. type='empty'
  748. fatal3
  749. # elif [[ -f $path ]] ; then
  750. # type='regular'
  751. # fatal3
  752. fi
  753. echo converting "$path" to absolute path
  754. pathfile=("$(find "$path" -type f)")
  755. pathfilefull+=("$(readlink -f "${pathfile[i]}")")
  756. echo converted to absolute path
  757. path="$pathfilefull"
  758. elif [[ -f "$replacement" ]]; then
  759. : > /dev/null
  760. else
  761. fatal
  762. fi
  763. if [[ -f "$path" ]] ; then
  764. objectconvert "$path"
  765. fin
  766. compile
  767. finish
  768. exit
  769. elif [[ -f "$replacement" ]] ; then
  770. echo Warning: "$path" does not exist however "$replacement" does, using "$replacement"
  771. objectconvert "$replacement"
  772. fin
  773. compile
  774. finish
  775. exit
  776. else
  777. fatal
  778. fi
  779.