Skip to content

Commit

Permalink
clouddrive2: init at 0.7.21
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Trump committed Oct 17, 2024
1 parent a3c0b3b commit a1e1e05
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
63 changes: 63 additions & 0 deletions pkgs/by-name/cl/clouddrive2/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
lib,
stdenv,
fetchzip,
makeWrapper,
}:
let
os = if stdenv.hostPlatform.isDarwin then "macos" else "linux";
arch = if stdenv.hostPlatform.isAarch64 then "aarch64" else "x86_64";
in
stdenv.mkDerivation rec {
pname = "clouddrive2";
version = "0.7.21";

src = fetchzip {
url = "https://github.com/cloud-fs/cloud-fs.github.io/releases/download/v${version}/clouddrive-2-${os}-${arch}-${version}.tgz";
sha256 =
{
x86_64-linux = "sha256-t6Jbbm/G1GjHCRQPbBVymr5q2nLLEOROpn0T6SvzMS4=";
aarch64-linux = "sha256-VxG5jGX5KXuIpxfBmlhukuZzfAM8O9a9e5BaIjIRJ8I=";
x86_64-darwin = "sha256-W5mTrgVWXKdjc0wZRdVNuw5+Pp0PUrGLXjmu3UQQbGw=";
aarch64-darwin = "sha256-aNxKTM/2TDVqMnZCFojWLgpKkzyZSP42SFIODpZuGsY=";
}
.${stdenv.hostPlatform.system} or (throw "unsupported system ${stdenv.hostPlatform.system}");
};

nativeBuildInputs = [ makeWrapper ];

installPhase = ''
runHook preInstall
mkdir -p $out/bin
mkdir -p $out/opt/clouddrive2
cp -r wwwroot "$out/opt/clouddrive2/wwwroot"
cp -r clouddrive "$out/opt/clouddrive2/clouddrive"
makeWrapper $out/opt/clouddrive2/clouddrive $out/bin/clouddrive
runHook postInstall
'';

passthru.updateScript = ./update-bin.sh;

meta = {
homepage = "https://www.clouddrive2.com";
changelog = "https://github.com/cloud-fs/cloud-fs.github.io/releases/tag/v${version}";
description = "Multi-cloud drives management tool supporting mounting cloud drives locally";
longDescription = ''
CloudDrive is a powerful multi-cloud drive management tool that provides a multi-cloud
drive solution that includes local mounting of cloud drives. It supports lots of cloud
drives in China.
'';
mainProgram = "clouddrive";
license = lib.licenses.unfree;
platforms = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
maintainers = with lib.maintainers; [ ltrump ];
};
}
44 changes: 44 additions & 0 deletions pkgs/by-name/cl/clouddrive2/update-bin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl common-updater-scripts nix-prefetch jq

set -euo pipefail

ROOT="$(dirname "$(readlink -f "$0")")"
NIX_DRV="$ROOT/package.nix"
if [ ! -f "$NIX_DRV" ]; then
echo "ERROR: cannot find clouddrive2 in $ROOT"
exit 1
fi

fetch_arch() {
VER="$1"; ARCH="$2"
URL="https://github.com/cloud-fs/cloud-fs.github.io/releases/download/v${VER}/clouddrive-2-${ARCH}-${VER}.tgz";
nix-prefetch "{ stdenv, fetchzip }:
stdenv.mkDerivation rec {
pname = \"clouddrive2\"; version = \"${VER}\";
src = fetchzip { url = \"$URL\"; };
}
"
}

replace_sha() {
sed -i "s#$1 = \"sha256-.\{44\}\"#$1 = \"$2\"#" "$NIX_DRV"
}

LAT_RELEASE=$(curl -sSfL \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/cloud-fs/cloud-fs.github.io/releases/latest")
LAT_VER=$(jq .tag_name -r <<< "$LAT_RELEASE" | cut -c2-)

LAT_LINUX_AARCH64_SHA256=$(fetch_arch "$LAT_VER" "linux-aarch64")
LAT_LINUX_X64_SHA256=$(fetch_arch "$LAT_VER" "linux-x86_64")
LAT_DARWIN_AARCH64_SHA256=$(fetch_arch "$LAT_VER" "macos-aarch64")
LAT_DARWIN_X64_SHA256=$(fetch_arch "$LAT_VER" "macos-x86_64")

sed -i "s/version = \".*\"/version = \"$LAT_VER\"/" "$NIX_DRV"

replace_sha "aarch64-linux" "$LAT_LINUX_AARCH64_SHA256"
replace_sha "x86_64-linux" "$LAT_LINUX_X64_SHA256"
replace_sha "aarch64-darwin" "$LAT_DARWIN_AARCH64_SHA256"
replace_sha "x86_64-darwin" "$LAT_DARWIN_X64_SHA256"

0 comments on commit a1e1e05

Please sign in to comment.