-
Notifications
You must be signed in to change notification settings - Fork 11
Add restic.net devcontainer feature #85
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c70d94e
Initial plan
Copilot 340d092
Add restic.net devcontainer feature
Copilot ae07bb2
Merge main branch changes (rclone.org, feature updates) while keeping…
Copilot dd034eb
Fix test.yaml: add restic.net to test-scenarios and resolve merge con…
Copilot 302df1b
Merge branch 'main' into copilot/add-feature-restic-net
sebst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "name": "restic.net", | ||
| "id": "restic.net", | ||
| "version": "1.0.0", | ||
| "description": "Install \"restic\" binary", | ||
| "documentationURL": "https://github.com/devcontainer-community/devcontainer-features/tree/main/src/restic.net", | ||
| "options": { | ||
| "version": { | ||
| "type": "string", | ||
| "default": "latest", | ||
| "proposals": [ | ||
| "latest" | ||
| ], | ||
| "description": "Version of \"restic\" to install." | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| #!/bin/bash | ||
| set -o errexit | ||
| set -o pipefail | ||
| set -o noclobber | ||
| set -o nounset | ||
| set -o allexport | ||
| readonly githubRepository='restic/restic' | ||
| readonly binaryName='restic' | ||
| readonly versionArgument='version' | ||
| readonly binaryTargetFolder='/usr/local/bin' | ||
| apt_get_update() { | ||
| if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then | ||
| echo "Running apt-get update..." | ||
| apt-get update -y | ||
| fi | ||
| } | ||
| apt_get_checkinstall() { | ||
| if ! dpkg -s "$@" >/dev/null 2>&1; then | ||
| apt_get_update | ||
| DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends --no-install-suggests --option 'Debug::pkgProblemResolver=true' --option 'Debug::pkgAcquire::Worker=1' "$@" | ||
| fi | ||
| } | ||
| apt_get_cleanup() { | ||
| apt-get clean | ||
| rm -rf /var/lib/apt/lists/* | ||
| } | ||
| check_curl_bzip2_installed() { | ||
| declare -a requiredAptPackagesMissing=() | ||
| if ! [ -r '/etc/ssl/certs/ca-certificates.crt' ]; then | ||
| requiredAptPackagesMissing+=('ca-certificates') | ||
| fi | ||
| if ! command -v curl >/dev/null 2>&1; then | ||
| requiredAptPackagesMissing+=('curl') | ||
| fi | ||
| if ! command -v bunzip2 >/dev/null 2>&1; then | ||
| requiredAptPackagesMissing+=('bzip2') | ||
| fi | ||
| declare -i requiredAptPackagesMissingCount=${#requiredAptPackagesMissing[@]} | ||
| if [ $requiredAptPackagesMissingCount -gt 0 ]; then | ||
| apt_get_update | ||
| apt_get_checkinstall "${requiredAptPackagesMissing[@]}" | ||
| apt_get_cleanup | ||
| fi | ||
| } | ||
| curl_check_url() { | ||
| local url=$1 | ||
| local status_code | ||
| status_code=$(curl -s -o /dev/null -w '%{http_code}' "$url") | ||
| if [ "$status_code" -ne 200 ] && [ "$status_code" -ne 302 ]; then | ||
| echo "Failed to download '$url'. Status code: $status_code." | ||
| return 1 | ||
| fi | ||
| } | ||
| curl_download_stdout() { | ||
| local url=$1 | ||
| curl \ | ||
| --silent \ | ||
| --location \ | ||
| --output '-' \ | ||
| --connect-timeout 5 \ | ||
| "$url" | ||
| } | ||
| debian_get_arch() { | ||
| dpkg --print-architecture | ||
| } | ||
| debian_get_target_arch() { | ||
| case $(debian_get_arch) in | ||
| amd64) echo 'amd64' ;; | ||
| arm64) echo 'arm64' ;; | ||
| armhf) echo 'arm' ;; | ||
| i386) echo '386' ;; | ||
| *) echo 'unknown' ;; | ||
| esac | ||
| } | ||
| echo_banner() { | ||
| local text="$1" | ||
| echo -e "\e[1m\e[97m\e[41m$text\e[0m" | ||
| } | ||
| github_list_releases() { | ||
| if [ -z "$1" ]; then | ||
| echo "Usage: list_github_releases <owner/repo>" | ||
| return 1 | ||
| fi | ||
| local repo="$1" | ||
| local url="https://api.github.com/repos/$repo/releases" | ||
| curl -s "$url" | grep -Po '"tag_name": "\K.*?(?=")' | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' | ||
| } | ||
| github_get_latest_release() { | ||
| if [ -z "$1" ]; then | ||
| echo "Usage: get_latest_github_release <owner/repo>" | ||
| return 1 | ||
| fi | ||
| github_list_releases "$1" | head -n 1 | ||
| } | ||
| github_get_tag_for_version() { | ||
| if [ -z "$1" ] || [ -z "$2" ]; then | ||
| echo "Usage: github_get_tag_for_version <owner/repo> <version>" | ||
| return 1 | ||
| fi | ||
| local repo="$1" | ||
| local version="$2" | ||
| local url="https://api.github.com/repos/$repo/releases" | ||
| local escaped_version | ||
| escaped_version="$(printf '%s' "$version" | sed 's/\./\\./g')" | ||
| curl -s "$url" | grep -Po '"tag_name": "\K.*?(?=")' | grep -E "^v?${escaped_version}$" | head -n 1 | ||
| } | ||
| utils_check_version() { | ||
| local version=$1 | ||
| if ! [[ "${version:-}" =~ ^(latest|[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then | ||
| printf >&2 '=== [ERROR] Option "version" (value: "%s") is not "latest" or valid semantic version format "X.Y.Z" !\n' \ | ||
| "$version" | ||
| exit 1 | ||
| fi | ||
| } | ||
| install() { | ||
| utils_check_version "$VERSION" | ||
| check_curl_bzip2_installed | ||
| readonly architecture="$(debian_get_target_arch)" | ||
| if [ "$VERSION" == 'latest' ] || [ -z "$VERSION" ]; then | ||
| VERSION=$(github_get_latest_release "$githubRepository") | ||
| fi | ||
| readonly version="${VERSION:?}" | ||
| readonly releaseTag="$(github_get_tag_for_version "$githubRepository" "$version")" | ||
| if [ -z "$releaseTag" ]; then | ||
| printf >&2 '=== [ERROR] Could not find release tag for version "%s" in "%s"!\n' "$version" "$githubRepository" | ||
| exit 1 | ||
| fi | ||
| readonly downloadUrl="https://github.com/${githubRepository}/releases/download/${releaseTag}/${binaryName}_${version}_linux_${architecture}.bz2" | ||
| curl_check_url "$downloadUrl" | ||
| readonly binaryTargetPath="${binaryTargetFolder}/${binaryName}" | ||
| curl_download_stdout "$downloadUrl" | bunzip2 > "$binaryTargetPath" | ||
| chmod 755 "$binaryTargetPath" | ||
| apt_get_cleanup | ||
| } | ||
| echo_banner "devcontainer.community" | ||
| echo "Installing $binaryName..." | ||
| install "$@" | ||
| echo "(*) Done!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/bin/bash | ||
|
|
||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library bundled with the devcontainer CLI | ||
| # See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib | ||
| # Provides the 'check' and 'reportResults' commands. | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Feature-specific tests | ||
| # The 'check' command comes from the dev-container-features-test-lib. Syntax is... | ||
| # check <LABEL> <cmd> [args...] | ||
| check "verify restic version" bash -c "restic version | grep 'restic'" | ||
|
|
||
| # Report results | ||
| # If any of the checks above exited with a non-zero exit code, the test will fail. | ||
| reportResults |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.