diff options
Diffstat (limited to 'various')
-rwxr-xr-x | various/allup | 33 | ||||
-rwxr-xr-x | various/dirup | 9 | ||||
-rw-r--r-- | various/neoup/config.h | 3 | ||||
-rw-r--r-- | various/neoup/makefile | 15 | ||||
-rw-r--r-- | various/neoup/neoup.c | 120 | ||||
-rw-r--r-- | various/neoup/readme | 29 | ||||
-rwxr-xr-x | various/readme | 11 | ||||
-rwxr-xr-x | various/up | 5 |
8 files changed, 225 insertions, 0 deletions
diff --git a/various/allup b/various/allup new file mode 100755 index 0000000..03b656f --- /dev/null +++ b/various/allup @@ -0,0 +1,33 @@ +#!/bin/sh + +# $1 is the remote directory to upload into. +# $2 is the local directory to upload from. +# $2's name should be ignored, however the +# directories within should retain their names. +uname="" +psswd="" +rdir="${1:-/}" +dir=${2:-$PWD} +url="https://$uname:$psswd@neocities.org/api/upload" + +# $1 is the directory to upload to. +# $2 is everything in the directory to upload from. +# $3 is the original name of the directory to upload from, +# as that directory name needs to be removed from the start +# of each file name. +up() +{ + for i in $2 + do + if [ -d $i ] + then + up $1 "$i/*" $3 + else + j=${i#$3/} + echo $1/$j + curl -F "$1/$j=@$i" "$url" + fi + done +} + +up $rdir "$dir/*" $dir diff --git a/various/dirup b/various/dirup new file mode 100755 index 0000000..20938d7 --- /dev/null +++ b/various/dirup @@ -0,0 +1,9 @@ +#!/bin/sh + +uname="" +psswd="" +rdir="${1:-/}" +fn="${2:-$PWD}" + +echo $rdir/$fn +curl -F "$rdir/$2=@$2" "https://$uname:$psswd@neocities.org/api/upload" diff --git a/various/neoup/config.h b/various/neoup/config.h new file mode 100644 index 0000000..522807e --- /dev/null +++ b/various/neoup/config.h @@ -0,0 +1,3 @@ +char *username = "username"; +char *password = "password"; +char *url = "\"https://neocities.org/api/upload\""; diff --git a/various/neoup/makefile b/various/neoup/makefile new file mode 100644 index 0000000..84d5ea7 --- /dev/null +++ b/various/neoup/makefile @@ -0,0 +1,15 @@ +CC = gcc +CFLAGS = -std=c89 -g -Wall -fdiagnostics-color=never +#CC = tcc +#CFLAGS = -Wall -g +LDFLAGS = +all: neoup + +.c: + $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< $(DLL) $(ICON) +clean: + rm -f neoup +install: all + cp neoup $(HOME)/bin +uninstall: + rm $(HOME)/bin/neoup diff --git a/various/neoup/neoup.c b/various/neoup/neoup.c new file mode 100644 index 0000000..0415954 --- /dev/null +++ b/various/neoup/neoup.c @@ -0,0 +1,120 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <dirent.h> +#include <unistd.h> +#include "config.h" + +#define MAXPATH 1024 +#define MAXCMD 4096 + +int +upfile(char *name, char *rdir) +{ + char *cmd = calloc(MAXCMD, sizeof(char)); + snprintf(cmd, MAXCMD, "curl -u %s:%s -F \"%s/%s=@%s\" %s", + username, password, rdir, name, name, url); + + printf("%s%s\n", rdir, name); + /*printf("\t%s\n", cmd);*/ + system(cmd); + + free(cmd); + return 0; +} + +int +updir(DIR *dirp, char *rdir, char *dir) +{ + DIR *nestdirp; + struct dirent *dp; + char *name = calloc(MAXPATH, sizeof(char)); + while ((dp = readdir(dirp)) != NULL) { + if (strcmp(".", dp->d_name) == 0 + || strcmp("..", dp->d_name) == 0) + continue; + if (strcmp(".", dir) != 0) { + strcpy(name, dir); + if (name[strlen(name) - 1] != '/') + strcat(name, "/"); + strcat(name, dp->d_name); + } + else + strcpy(name, dp->d_name); + nestdirp = opendir(name); + if (nestdirp == NULL) + upfile(name, rdir); + else if (nestdirp != NULL) { + updir(nestdirp, rdir, name); + } + } + + free(name); + closedir(dirp); + return 0; +} + +/* Upload to a neocities directory a local file or directory. */ +int +main(int argc, char **argv) +{ + char *rdir; + rdir = calloc(MAXPATH, sizeof(char)); + char *local; + local = calloc(MAXPATH, sizeof(char)); + /* In case getcwd is more appropriate than simply '.'. + char *dir = calloc(MAXPATH, sizeof(char)); + getcwd(dir, MAXPATH * sizeof(char));*/ + local[0] = '.'; + int i; + for (i = 1; i < argc; ++i) { + if (strcmp(argv[i], "-r") == 0) { + if (i < argc - 1) { + ++i; + rdir = argv[i]; + } + else { + puts("Supply a directory" + " name after -r"); + return 1; + } + } else if (strcmp(argv[i], "-f") == 0) { + if (i < argc - 1) { + ++i; + local = argv[i]; + } + else { + puts("Supply a file or directory" + " name after -f"); + return 2; + } + } + else { + puts(argv[i]); + printf("%s [-r neocities directory]" + " [-f local file or directory]\n", + argv[0]); + return -1; + } + } + int tmp = strlen(rdir) - 1; + if (rdir[tmp] == '/' && tmp > 0) + rdir[tmp] = '\0'; + /*if (rdir[0] == '\0') + printf("%s ", "/"); + else + printf("%s ", rdir); + printf("%s\n", local);*/ + + DIR *dirp = opendir(local); + if (dirp != NULL) { + updir(dirp, rdir, local); + } else if (access(local, R_OK) == 0) { + upfile(local, rdir); + } else { + printf("I can't open this!\n"); + return 3; + } + + return 0; +} diff --git a/various/neoup/readme b/various/neoup/readme new file mode 100644 index 0000000..992928b --- /dev/null +++ b/various/neoup/readme @@ -0,0 +1,29 @@ +The files provided here allow for generating a program that, when specified +with valid credentials at compilation time, may be used to upload to a file +or directory to a neocities site. The provided makefile's defaults are suitable +for a usual mingw installation, and the commented-out alternatives are suitable +for a usual Unix C89 compiler. In order to make this program work, fill in +valid neocities log-in information in "config.h", compile by means of "make", +and then run the program, that which has the following input syntax: + + neoup [-r neocities directory] [-d local file or directory] + +Should a local file be supplied, it will be uploaded. +Should a local directory be supplied, it and its contents will be uploaded. +If none is specified, the current local directory's contents are uploaded. +Should a neocities directory be specified, all uploads will be placed in that +directory on the neocities site, relative to the starting directory. +If none is specified, all uploads are placed in the starting directory. + +On Windows, mingw is the only build dependency that doesn't commonly come with +the operating system. +On Unix, there are no unusual build dependencies. +On Windows, all of the run-time dependencies are already installed. +On Unix, "curl" may need to be installed, depending on who distributes your +operating system. + +Should there be an issue, message me. + + kaa@disroot.org + +This author places their work distributed here in the Public Domain. diff --git a/various/readme b/various/readme new file mode 100755 index 0000000..d487173 --- /dev/null +++ b/various/readme @@ -0,0 +1,11 @@ +'up' simply uploads a file. +'./up [file]' + +'dirup' uploads a file to a given remote directory. +'./dirup [remote directory] [file]' + +'allup' uploads all files in a given directory to a +given remote directory, intentionally preserving the +names of the directories within the local directory, +and uploading their contents recursively. +'./allup [remote directory] [local directory]' diff --git a/various/up b/various/up new file mode 100755 index 0000000..3aeb8af --- /dev/null +++ b/various/up @@ -0,0 +1,5 @@ +#!/bin/sh + +uname="" +psswd="" +curl -F "$1=@$1" "https://$uname:$psswd@neocities.org/api/upload" |