From 2928cbc9e6996bbe88c68d9c8f0f36fb9544bbd9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Mon, 22 Apr 2024 15:38:35 +0900 Subject: [PATCH] =?utf8?q?=E6=9C=80=E5=88=9D=E3=82=B3=E3=83=9F=E3=83=83?= =?utf8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ CHANGELOG.md | 2 ++ LICENSE.txt | 14 +++++++++ Makefile | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 37 +++++++++++++++++++++++ main.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE.txt create mode 100644 Makefile create mode 100644 README.md create mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50538ff --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +odl +release diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..00911c4 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +# 0.1.0 +* 最初リリース diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..c4d9131 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,14 @@ +Copyright © 2004-2011 by Internet Systems Consortium, Inc. ("ISC") +Copyright © 2018-2024 by 076.moe + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD +TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9de03f8 --- /dev/null +++ b/Makefile @@ -0,0 +1,83 @@ +UNAME_S!=uname -s + +NAME!=cat main.c | grep "const char\* sofname" | awk '{print $$5}' | \ + sed "s/\"//g" | sed "s/;//" +VERSION!=cat main.c | grep "const char\* version" | awk '{print $$5}' | \ + sed "s/\"//g" | sed "s/;//" +PREFIX=/usr/local +MANPREFIX=${PREFIX}/man +CFLAGS=-Wall -Wextra -g -I/usr/include -I/usr/local/include +LDFLAGS=-L/usr/lib -L/usr/local/lib + +.if ${UNAME_S} == "FreeBSD" +MANPREFIX=${PREFIX}/share/man +.elif ${UNAME_S} == "OpenBSD" +.elif ${UNAME_S} == "Linux" +PREFIX=/usr +MANPREFIX=${PREFIX}/share/man +.elif ${UNAME_S} == "NetBSD" +PREFIX=/usr/pkg +CFLAGS+= -I/usr/pkg/include +LDFLAGS+= -L/usr/pkg/lib +MANPREFIX=${PREFIX}/share/man +.endif + +CC=cc +FILES=main.c +LIBS=-lcurl + +all: + ${CC} ${CFLAGS} -o ${NAME} ${FILES} ${LDFLAGS} ${LIBS} + strip ${NAME} + +clean: + rm -f ${NAME} + +release-openbsd: + mkdir -p release/bin + ${CC} ${CFLAGS} -o release/bin/${NAME}-${VERSION}-openbsd-amd64 ${FILES} ${LDFLAGS} \ + -static -lcurl -lc -lnghttp3 -lngtcp2_crypto_quictls -lngtcp2 -lssl \ + -lcrypto -lnghttp2 -lz -lpthread + strip release/bin/${NAME}-${VERSION}-openbsd-amd64 + +release-netbsd: + mkdir -p release/bin + ${CC} ${CFLAGS} -o release/bin/${NAME}-${VERSION}-netbsd-amd64 ${FILES} ${LDFLAGS} \ + -static -lcurl -lnghttp2 -lc -lidn2 -lunistring -lgssapi -lkrb5 -lhx509 -lintl \ + -lssl -lcrypto -lcrypt -lasn1 -lcom_err -lroken -lutil -lwind -lheimbase \ + -lheimntlm -lz -lpthread + strip release/bin/${NAME}-${VERSION}-netbsd-amd64 + +release-freebsd: + mkdir -p release/bin + ${CC} ${CFLAGS} -o release/bin/${NAME}-${VERSION}-freebsd-amd64 ${FILES} ${LDFLAGS} \ + -static -lcurl -lnghttp2 -lssh2 -lpsl -lssl -lheimntlm \ + -lhx509 -lcom_err -lcrypto -lasn1 -lwind -lheimbase \ + -lroken -lcrypt -lz -lkrb5 -lgssapi -lgssapi_krb5 -lthr \ + -lidn2 -lunistring -lprivateheimipcc + strip release/bin/${NAME}-${VERSION}-freebsd-amd64 + +release-linux: + mkdir -p release/bin + ${CC} ${CFLAGS} -o release/bin/${NAME}-${VERSION}-linux-amd64 ${FILES} ${LDFLAGS} \ + -static -lcurl -lc -lnghttp2 -lidn2 -lssh2 -lpsl -lssl -lcrypto -lzstd -lz \ + -lunistring + strip release/bin/${NAME}-${VERSION}-linux-amd64 + +dist: + mkdir -p ${NAME}-${VERSION} release/src + cp -R LICENSE.txt Makefile README.md CHANGELOG.md \ + *.c ${NAME}-${VERSION} + tar zcfv ${NAME}-${VERSION}.tar.gz ${NAME}-${VERSION} + mv ${NAME}-${VERSION}.tar.gz release/src + rm -rf ${NAME}-${VERSION} + +install: + mkdir -p ${DESTDIR}${PREFIX}/bin + cp -f ${NAME} ${DESTDIR}${PREFIX}/bin + chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME} + +uninstall: + rm -f ${DESTDIR}${PREFIX}/bin/${NAME} + +.PHONY: all clean install uninstall diff --git a/README.md b/README.md new file mode 100644 index 0000000..47ce343 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# odl - オンライン・ダウンロード + +## インストールする方法 +### OpenBSD +```sh +doas pkg_add curl +make +doas make install +``` + +### Void Linux +```sh +doas xbps-install curl bmake +bmake +doas bmake install +``` + +### FreeBSD +```sh +doas pkg install curl +make +doas make install +``` + +### NetBSD +```sh +doas pkgin install curl +make +doas make install +``` + +### CRUX Linux +```sh +doas prt-get depinst curl bmake +bmake +doas bmake install +``` diff --git a/main.c b/main.c new file mode 100644 index 0000000..af195ff --- /dev/null +++ b/main.c @@ -0,0 +1,81 @@ +#include +#include +#include + +#include + +const char* sofname = "odl"; +const char* version = "0.1.0"; +char* filename; + +int progress_callback(void *cp, double dt, double dn, double ut, double un) { + (void)cp; + (void)ut; + (void)un; + + double progress = (dn / dt) * 100.0; + char* status = "ダウンロード中"; + if (progress == 100.0) status = "ダウンロード済み"; + + printf("\r["); + int barw = 50; + int pos = (int)(progress * barw / 100.0); + + for (int i = 0; i < barw; ++i) { + if (i < pos) printf("="); + else if (i == pos) printf(">"); + else printf(" "); + } + + printf("] %.2f%% %s, %s", progress, filename, status); + fflush(stdout); + + return 0; +} + +int main(int argc, char* argv[]) { + if (argc < 2) { + printf("usage: %s [url ...]\n", sofname); + return 1; + } + + CURL* curl = curl_easy_init(); + if (!curl) { + perror("curlを初期設置に失敗。"); + return -1; + } + + for (int i = 1; i < argc; i++) { + const char* url = argv[i]; + filename = basename((char*)url); + + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); + + FILE* file = fopen(filename, "wb"); + if (!file) { + curl_easy_cleanup(curl); + perror("ファイルを開けません。"); + return -1; + } + + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, file); + CURLcode res = curl_easy_perform(curl); + fclose(file); + + if (res != CURLE_OK) { + curl_easy_cleanup(curl); + fprintf(stderr, "ダウンロードに失敗: %s\n", curl_easy_strerror(res)); + return -1; + } + + printf("\n"); + } + + curl_easy_cleanup(curl); + + printf("\nダウンロードに完了しました。\n"); + + return 0; +} -- 2.43.0