Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: suggestions and errors pointed out by shellcheck #12

Merged
merged 4 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions alist/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@ ARG TARGETARCH

ENV DUMB_INIT_VERSION "1.2.5"

ADD https://raw.githubusercontent.com/monlor/docker-xiaoya/main/bin/dumb-init_${DUMB_INIT_VERSION}_${TARGETARCH} /dumb-init
ADD --chmod=755 https://raw.githubusercontent.com/monlor/docker-xiaoya/main/bin/dumb-init_${DUMB_INIT_VERSION}_${TARGETARCH} /dumb-init

RUN chmod +x /dumb-init

COPY ./start.sh /start.sh
COPY ./clear.sh /clear.sh
COPY ./update_media_addr.sh /update_media_addr.sh
COPY ./fix_media.sh /fix_media.sh
COPY ./data.sh /data.sh

RUN chmod +x /start.sh /clear.sh /update_media_addr.sh /fix_media.sh /data.sh
COPY --chmod=755 ./*.sh /

RUN DATA_DIR=/tmp/data /data.sh download

ENTRYPOINT [ "/dumb-init", "--", "/start.sh" ]

CMD []
CMD []
7 changes: 3 additions & 4 deletions alist/data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ download_files() {
}

restart_service() {
kill -15 $(ps ax | grep 'nginx|httpd|alist' | grep -v grep | awk '{print$1}')
kill -15 $(pgrep -f 'nginx|httpd|alist')
sleep 10
/entrypoint.sh /opt/alist/alist server --no-prefix &
}

update() {
download_files
if [ $? -ne 0 ]; then
if ! download_files; then
echo "Failed to download files or no need to update"
return 1
fi
Expand All @@ -89,4 +88,4 @@ case "$1" in
echo "Usage: $0 {update|download}"
exit 1
;;
esac
esac
8 changes: 4 additions & 4 deletions alist/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ fi
if [ -n "${PIKPAK_LIST:-}" ]; then
echo "设置PIKPAK用户密码..."
rm -rf /data/pikpak_list.txt
echo ${PIKPAK_LIST} | tr ',' '\n' | while read line; do
user=$(echo $line | cut -d':' -f1)
pass=$(echo $line | cut -d':' -f2-)
echo "${PIKPAK_LIST}" | tr ',' '\n' | while read -r line; do
user=$(echo "$line" | cut -d':' -f1)
pass=$(echo "$line" | cut -d':' -f2-)
echo "\"${user}\" \"${pass}\"" >> /data/pikpak_list.txt
done
fi
Expand Down Expand Up @@ -106,4 +106,4 @@ fi

/entrypoint.sh /opt/alist/alist server --no-prefix &

exec crond -f
exec crond -f
1 change: 1 addition & 0 deletions emby/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create_embyserver.sh
15 changes: 5 additions & 10 deletions emby/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@ LABEL MAINTAINER [email protected]

ARG TARGETARCH

ENV SHELL2HTTP_VERSION "1.17.0"

ENV DUMB_INIT_VERSION "1.2.5"
ENV SHELL2HTTP_VERSION="1.17.0" \
DUMB_INIT_VERSION="1.2.5"

ENV PUID=0 PGID=0

ADD https://github.com/msoap/shell2http/releases/download/v${SHELL2HTTP_VERSION}/shell2http_${SHELL2HTTP_VERSION}_linux_${TARGETARCH}.tar.gz .

ADD https://raw.githubusercontent.com/monlor/docker-xiaoya/main/bin/dumb-init_${DUMB_INIT_VERSION}_${TARGETARCH} /dumb-init
ADD --chmod=755 https://raw.githubusercontent.com/monlor/docker-xiaoya/main/bin/dumb-init_${DUMB_INIT_VERSION}_${TARGETARCH} /dumb-init

RUN tar -zxvf shell2http_${SHELL2HTTP_VERSION}_linux_${TARGETARCH}.tar.gz -C /usr/bin/ shell2http && \
rm -rf shell2http_${SHELL2HTTP_VERSION}_linux_${TARGETARCH}.tar.gz && \
chmod +x /dumb-init

COPY ./entrypoint.sh /entrypoint.sh
COPY ./update_alist_addr.sh /update_alist_addr.sh
rm -rf shell2http_${SHELL2HTTP_VERSION}_linux_${TARGETARCH}.tar.gz

RUN chmod +x /entrypoint.sh /update_alist_addr.sh
COPY --chmod=755 ./*.sh /

ENTRYPOINT [ "/dumb-init", "/entrypoint.sh" ]
7 changes: 3 additions & 4 deletions emby/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

echo "等待alist启动完成..."
while ! wget -q -T 1 -O /dev/null "${ALIST_ADDR:=http://alist:5678}" &> /dev/null; do
while ! wget -q -T 1 -O /dev/null "${ALIST_ADDR:=http://alist:5678}" > /dev/null 2>&1; do
sleep 2
done

Expand All @@ -16,13 +16,12 @@ networks: files
EOF

echo "开始自动更新alist地址..."
/update_alist_addr.sh &> /dev/null &
/update_alist_addr.sh > /dev/null 2>&1 &

/start_emby.sh &> /dev/null &
/start_emby.sh > /dev/null 2>&1 &

start_command="/system/EmbyServer -programdata /config -ffdetect /bin/ffdetect -ffmpeg /bin/ffmpeg -ffprobe /bin/ffprobe -restartexitcode 3"

$start_command &

exec shell2http -port 8080 /stop "killall -15 EmbyServer" /start "LD_LIBRARY_PATH=/lib:/system ${start_command} &"

2 changes: 1 addition & 1 deletion emby/update_alist_addr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ALIST_DOMAIN=$(echo "${ALIST_ADDR}" | sed -e 's#http://##' -e 's#https://##' -e
add_hosts() {
# 容器里不能使用sed -i,所以使用临时文件
sed -e "/xiaoya.host/d" /etc/hosts > /tmp/hosts
echo -e "$1\txiaoya.host" >> /tmp/hosts
printf "%s\txiaoya.host\n" "$1" >> /tmp/hosts
cat /tmp/hosts > /etc/hosts
}

Expand Down
36 changes: 18 additions & 18 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if ! command -v docker &> /dev/null; then
echo "Docker 未安装,请安装docker后再运行脚本,推荐OrbStack:https://orbstack.dev/"
exit 1
fi
read -p "Docker 未安装,是否安装?(y/n): " install
read -rp "Docker 未安装,是否安装?(y/n): " install
if [ "$install" = "y" ]; then
echo "安装docker..."
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
Expand All @@ -45,7 +45,7 @@ DOCKER_COMPOSE="docker compose"

# 检查是否安装了compose插件,docker compose 命令
if ! docker compose &> /dev/null && ! which docker-compose &> /dev/null; then
read -p "Docker Compose 未安装,是否安装?(y/n): " install
read -rp "Docker Compose 未安装,是否安装?(y/n): " install
if [ "$install" = "y" ]; then
echo "安装docker compose..."
# 判断系统是x86还是arm,arm有很多种类,都要判断
Expand All @@ -70,14 +70,14 @@ if ! docker compose &> /dev/null; then
fi

# 让用户输入服务部署目录,默认/opt/xiaoya
read -p "请输入服务部署目录(默认/opt/xiaoya): " install_path
read -rp "请输入服务部署目录(默认/opt/xiaoya): " install_path
install_path=${install_path:=/opt/xiaoya}

# 检查服务是否已经运行
echo "检查服务是否已经存在..."
if [ -f "$install_path/docker-compose.yml" ]; then
# 询问用户是否要更新服务
read -p "检查到服务已存在,是否更新服务?(y/n): " update
read -rp "检查到服务已存在,是否更新服务?(y/n): " update
if [ "${update}" != "y" ]; then
echo "退出安装"
exit 1
Expand All @@ -86,15 +86,15 @@ fi

# 如果是更新服务,则从原有的compose配置中获取token等信息
if [ "${update}" = "y" ]; then
token=$(cat $install_path/env 2> /dev/null | grep ALIYUN_TOKEN | awk -F '=' '{print $2}')
open_token=$(cat $install_path/env 2> /dev/null | grep ALIYUN_OPEN_TOKEN | awk -F '=' '{print $2}')
folder_id=$(cat $install_path/env 2> /dev/null | grep ALIYUN_FOLDER_ID | awk -F '=' '{print $2}')
token=$(grep ALIYUN_TOKEN "$install_path/env" 2> /dev/null | awk -F '=' '{print $2}')
open_token=$(grep ALIYUN_OPEN_TOKEN "$install_path/env" 2> /dev/null | awk -F '=' '{print $2}')
folder_id=$(grep ALIYUN_FOLDER_ID "$install_path/env" 2> /dev/null | awk -F '=' '{print $2}')
fi

# 让用户输入阿里云盘TOKEN,token获取方式教程:https://alist.nn.ci/zh/guide/drivers/aliyundrive.html
echo
echo "阿里云盘token获取方式教程:https://alist.nn.ci/zh/guide/drivers/aliyundrive.html"
read -p "请输入阿里云盘TOKEN(默认为$token): " res
read -rp "请输入阿里云盘TOKEN(默认为$token): " res
token=${res:=$token}
if [ ${#token} -ne 32 ]; then
echo "长度不对,阿里云盘 Token是32位"
Expand All @@ -104,7 +104,7 @@ fi
# 让用户输入阿里云盘OpenTOKEN,token获取方式教程:https://alist.nn.ci/zh/guide/drivers/aliyundrive_open.html
echo
echo "阿里云盘Open token获取方式教程:https://alist.nn.ci/zh/guide/drivers/aliyundrive_open.html"
read -p "请输入阿里云盘Open TOKEN(默认为$open_token): " res
read -rp "请输入阿里云盘Open TOKEN(默认为$open_token): " res
open_token=${res:=$open_token}
if [ ${#open_token} -le 334 ]; then
echo "长度不对,阿里云盘 Open Token是335位"
Expand All @@ -114,7 +114,7 @@ fi
# 让用户输入阿里云盘转存目录folder_id,folder_id获取方式教程:https://www.aliyundrive.com/s/rP9gP3h9asE
echo
echo "转存以下文件到你的网盘,进入文件夹,获取地址栏末尾的文件夹ID:https://www.aliyundrive.com/s/rP9gP3h9asE"
read -p "请输入阿里云盘转存目录folder_id(默认为$folder_id): " res
read -rp "请输入阿里云盘转存目录folder_id(默认为$folder_id): " res
folder_id=${res:=$folder_id}
if [ ${#folder_id} -ne 40 ]; then
echo "长度不对,阿里云盘 folder id是40位"
Expand All @@ -128,7 +128,7 @@ echo "1. alist + emby (默认)"
echo "2. alist"
echo "3. alist + jellyfin"
echo "4. alist + emby + jellyfin"
read -p "请选择部署服务类型: " service_type
read -rp "请选择部署服务类型: " service_type
case $service_type in
1)
service_type=""
Expand All @@ -150,15 +150,15 @@ esac

# 检查目录是否存在,不存在则创建
if [ ! -d "$install_path" ]; then
mkdir -p $install_path
mkdir -p "$install_path"
fi

cd $install_path
cd "$install_path"

echo "开始生成配置文件docker-compose${service_type}.yml..."
curl -#Lo $install_path/docker-compose.yml "${GH_PROXY}https://raw.githubusercontent.com/monlor/docker-xiaoya/main/docker-compose${service_type}.yml"
if [ ! -f $install_path/env ]; then
curl -#Lo $install_path/env "${GH_PROXY}https://raw.githubusercontent.com/monlor/docker-xiaoya/main/env"
curl -#Lo "$install_path/docker-compose.yml" "${GH_PROXY}https://raw.githubusercontent.com/monlor/docker-xiaoya/main/docker-compose${service_type}.yml"
if [ ! -f "$install_path/env" ]; then
curl -#Lo "$install_path/env" "${GH_PROXY}https://raw.githubusercontent.com/monlor/docker-xiaoya/main/env"
fi
sedsh "s#ALIYUN_TOKEN=.*#ALIYUN_TOKEN=$token#g" env
sedsh "s#ALIYUN_OPEN_TOKEN=.*#ALIYUN_OPEN_TOKEN=$open_token#g" env
Expand Down Expand Up @@ -196,7 +196,7 @@ echo "emby地址: http://$local_ip:6908, http://$ip:6908, 默认用户密码: xi
echo "jellyfin地址: http://$local_ip:8096, http://$ip:8096"

# 添加管理脚本,启动,停止,查看日志
cat > $install_path/manage.sh <<-EOF
cat > "$install_path/manage.sh" <<-EOF
#!/bin/bash

set -e
Expand Down Expand Up @@ -230,4 +230,4 @@ case \$1 in
esac
EOF

chmod +x $install_path/manage.sh
chmod +x "$install_path/manage.sh"
1 change: 1 addition & 0 deletions jellyfin/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create_jellyfn.sh
5 changes: 1 addition & 4 deletions jellyfin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ FROM monlor/jellyfin

LABEL MAINTAINER [email protected]

COPY ./entrypoint.sh /entrypoint.sh
COPY ./update_alist_addr.sh /update_alist_addr.sh

RUN chmod +x /entrypoint.sh /update_alist_addr.sh
COPY --chmod=755 ./*.sh /

ENTRYPOINT [ "/entrypoint.sh" ]
4 changes: 2 additions & 2 deletions jellyfin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

echo "等待alist启动完成..."
while ! curl -s -f -m 1 "${ALIST_ADDR:=http://alist:5678}" &> /dev/null; do
while ! curl -s -f -m 1 "${ALIST_ADDR:=http://alist:5678}" > /dev/null 2>&1; do
sleep 2
done

Expand All @@ -16,6 +16,6 @@ networks: files
EOF

echo "开始自动更新alist地址..."
/update_alist_addr.sh &> /dev/null &
/update_alist_addr.sh > /dev/null 2>&1 &
monlor marked this conversation as resolved.
Show resolved Hide resolved

/jellyfin/jellyfin --datadir /config --cachedir /cache --ffmpeg /usr/lib/jellyfin-ffmpeg/ffmpeg
2 changes: 1 addition & 1 deletion jellyfin/update_alist_addr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ALIST_DOMAIN=$(echo "${ALIST_ADDR}" | sed -e 's#http://##' -e 's#https://##' -e
add_hosts() {
# 容器里不能使用sed -i,所以使用临时文件
sed -e "/xiaoya.host/d" /etc/hosts > /tmp/hosts
echo -e "$1\txiaoya.host" >> /tmp/hosts
printf "%s\txiaoya.host\n" "$1" >> /tmp/hosts
cat /tmp/hosts > /etc/hosts
}

Expand Down
7 changes: 2 additions & 5 deletions metadata/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ RUN curl -#LO https://github.com/Rik-F5/xiaoya_db/archive/refs/heads/main.zip &&
mv xiaoya_db-main/solid.py / && \
rm -rf main.zip xiaoya_db-main

COPY ./entrypoint.sh /entrypoint.sh
COPY ./emby.sh /emby.sh
COPY --chmod=755 ./*.sh /

RUN chmod +x /entrypoint.sh /emby.sh

ENTRYPOINT [ "/entrypoint.sh" ]
ENTRYPOINT [ "/entrypoint.sh" ]
5 changes: 3 additions & 2 deletions metadata/emby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ wait_for_emby() {
echo "Waiting for Emby service to start at $EMBY_URL..."

while true; do
local http_code=$(curl -s -o /dev/null -w "%{http_code}" "${EMBY_URL}/Users")
local http_code
http_code=$(curl -s -o /dev/null -w "%{http_code}" "${EMBY_URL}/Users")
if [ "$http_code" -eq 401 ]; then
echo "Emby service is up and running."
return 0
Expand Down Expand Up @@ -196,4 +197,4 @@ case $1 in
echo "Usage: $0 {update|reset|download}"
exit 1
;;
esac
esac
2 changes: 1 addition & 1 deletion metadata/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ echo "Complete."

touch ${MEDIA_DIR}/config/meta_finished

cron -f
cron -f
4 changes: 2 additions & 2 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

read -p "请输入服务部署目录(默认/opt/xiaoya):" install_path
read -rp "请输入服务部署目录(默认/opt/xiaoya):" install_path
install_path=${install_path:=/opt/xiaoya}

if [ ! -d "$install_path" ]; then
Expand All @@ -17,7 +17,7 @@ if ! docker compose &> /dev/null; then
fi

params=""
read -p "是否删除数据卷?(y/n)" delete_volume
read -rp "是否删除数据卷?(y/n)" delete_volume
if [ "$delete_volume" = "y" ]; then
params="--volumes"
fi
Expand Down
Loading