debian-packages/filebrowser-bin/filebrowser.sh

91 lines
1.9 KiB
Bash
Raw Normal View History

2022-11-01 07:08:44 +00:00
#!/usr/bin/env bash
version="${1:?You need to specific a version, eg: v1.22.2}"
version_num="${version##v}"
2022-11-01 07:28:08 +00:00
package_name=filebrowser-${version_num}.tar.gz
2022-11-01 07:08:44 +00:00
# must occur dirs
material_dir="./materials"
# optional dirs (created during build)
2022-11-01 07:28:08 +00:00
download_dir="./var/downloads"
extract_dir="./var/extracted"
rootfs="./var/rootfs"
2022-11-01 07:08:44 +00:00
2022-11-01 07:28:08 +00:00
package_dir="./packages"
2022-11-01 07:08:44 +00:00
function copy_file {
local src="$1"
local dst="$2"
# if ends with a splash
if [[ "$dst" == */ ]] ; then
mkdir -p $dst
cp --target-directory $dst $src
else
local dst_dir=$(dirname $dst)
mkdir -p $dst_dir
cp --no-target-directory $src $dst
fi
2022-11-01 07:28:08 +00:00
}
2022-11-01 07:08:44 +00:00
2022-11-01 07:28:08 +00:00
function download {
# don't re-download if already downloaded
if [ ! -f "${download_dir}/${package_name}" ] ; then
mkdir -p ${download_dir}
wget --output-document ${download_dir}/${package_name} https://github.com/filebrowser/filebrowser/releases/download/${version}/linux-amd64-filebrowser.tar.gz
fi
2022-11-01 07:08:44 +00:00
}
2022-11-01 07:28:08 +00:00
function extract {
rm -rf ${extract_dir}
mkdir -p ${extract_dir}
tar -xf ${download_dir}/${package_name} -C ${extract_dir}
}
2022-11-01 07:08:44 +00:00
2022-11-01 07:28:08 +00:00
function build_rootfs {
rm -rf ${rootfs}
2022-11-01 07:08:44 +00:00
2022-11-01 07:28:08 +00:00
copy_file ${extract_dir}/filebrowser ${rootfs}/usr/bin/filebrowser
2022-11-01 07:08:44 +00:00
2022-11-01 07:28:08 +00:00
copy_file ${extract_dir}/CHANGELOG.md ${rootfs}/usr/share/filebrowser/
copy_file ${extract_dir}/LICENSE ${rootfs}/usr/share/filebrowser/
copy_file ${extract_dir}/README.md ${rootfs}/usr/share/filebrowser/
copy_file ${material_dir}/filebrowser.service ${rootfs}/usr/lib/systemd/system/filebrowser.service
}
2022-11-01 07:08:44 +00:00
2022-11-01 07:28:08 +00:00
function package_meta {
# debian packages meta file
mkdir -p $rootfs/DEBIAN
sed "s/+++VERSION+++/${version_num}/" > $rootfs/DEBIAN/control << EOF
2022-11-01 07:08:44 +00:00
Package: filebrowser
Version: +++VERSION+++
Priority: optional
Architecture: all
Maintainer: leafee98 <me@leafee98.com>
Description: Web File Browser
EOF
2022-11-01 07:28:08 +00:00
}
function main {
download
extract
build_rootfs
package_meta
mkdir -p $package_dir
dpkg-deb --build --root-owner-group $rootfs $package_dir/filebrowser-${version}.deb
}
main "$@"