From 71d1b96e697da545490778256046a1138ed8ff37 Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Sun, 3 Dec 2023 21:14:02 +0800 Subject: [PATCH] Opt: update install script and dockerfile --- Dockerfile | 20 +++++++++----------- script/install.sh | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0be7bb2..bd6ea59 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,28 +6,26 @@ WORKDIR /synctv COPY ./ ./ -RUN apk add --no-cache bash curl gcc git go musl-dev - -RUN bash script/build.sh -P -v ${VERSION} +RUN apk add --no-cache bash curl gcc git go musl-dev && \ + bash script/build.sh -P -v ${VERSION} From alpine:latest +ENV PUID=0 PGID=0 UMASK=022 + COPY --from=builder /synctv/build/synctv /usr/local/bin/synctv COPY script/entrypoint.sh /entrypoint.sh -RUN apk add --no-cache bash ca-certificates su-exec tzdata - -RUN chmod +x /entrypoint.sh - -ENV PUID=0 PGID=0 UMASK=022 - -RUN mkdir -p ~/.synctv +RUN apk add --no-cache bash ca-certificates su-exec tzdata && \ + rm -rf /var/cache/apk/* && \ + chmod +x /entrypoint.sh && \ + mkdir -p ~/.synctv WORKDIR ~/.synctv EXPOSE 8080/tcp 8080/udp -VOLUME [ ~/.synctv ] +VOLUME [ "~/.synctv" ] CMD [ "/entrypoint.sh" ] diff --git a/script/install.sh b/script/install.sh index 7821030..3f92af6 100755 --- a/script/install.sh +++ b/script/install.sh @@ -12,6 +12,11 @@ function Help() { } function Init() { + # Check if the user is root or sudo + if [ "$EUID" -ne 0 ]; then + echo "Please run as root" + exit + fi VERSION="latest" InitOS InitArch @@ -112,7 +117,7 @@ function InitDownloadTools() { function Download() { case "$download_tool" in curl) - curl -L "$1" -o "$2" + curl -L "$1" -o "$2" --progress-bar if [ $? -ne 0 ]; then echo "download $1 failed" exit 1 @@ -178,6 +183,10 @@ function InstallWithVersion() { } function InitLinuxSystemctlService() { + if [ -z "$(command -v systemctl)" ]; then + echo "systemctl command not found" + exit 1 + fi mkdir -p "/opt/synctv" if [ ! -d "/etc/systemd/system" ]; then echo "/etc/systemd/system not found" @@ -214,14 +223,6 @@ function InitSystemctlService() { linux) InitLinuxSystemctlService ;; - darwin) - echo "darwin not support" - exit 1 - ;; - *) - echo "OS not supported" - exit 1 - ;; esac }