diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index aa8ca60..bcd981c 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -26,7 +26,7 @@ jobs: - name: build run: go tool task build # needed to download the embedded resources env: - GH_TOKEN: ${{ secrets.ARDUINOBOT_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: dprint/check@v2.2 with: diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 246bc46..e1d9b17 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -21,4 +21,4 @@ jobs: - name: Run tests run: go tool task test env: - GH_TOKEN: ${{ secrets.ARDUINOBOT_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 087f957..a95e952 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,7 +65,7 @@ jobs: env: GOARCH: ${{ matrix.arch }} GOOS: ${{ matrix.os }} - GH_TOKEN: ${{ secrets.ARDUINOBOT_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Prepare Build Artifacts (!windows) working-directory: ./${{ env.DIST_DIR }} diff --git a/.licenses/arduino-flasher-cli/go/github.com/fatih/color.dep.yml b/.licenses/arduino-flasher-cli/go/github.com/fatih/color.dep.yml new file mode 100644 index 0000000..3c49fef --- /dev/null +++ b/.licenses/arduino-flasher-cli/go/github.com/fatih/color.dep.yml @@ -0,0 +1,35 @@ +--- +name: github.com/fatih/color +version: v1.18.0 +type: go +summary: Package color is an ANSI color package to output colorized or SGR defined + output to the standard output. +homepage: https://pkg.go.dev/github.com/fatih/color +license: mit +licenses: +- sources: LICENSE.md + text: | + The MIT License (MIT) + + Copyright (c) 2013 Fatih Arslan + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +- sources: README.md + text: The MIT License (MIT) - see [`LICENSE.md`](https://github.com/fatih/color/blob/master/LICENSE.md) + for more details +notices: [] diff --git a/.licenses/arduino-flasher-cli/go/github.com/sirupsen/logrus.dep.yml b/.licenses/arduino-flasher-cli/go/github.com/mattn/go-colorable.dep.yml similarity index 74% rename from .licenses/arduino-flasher-cli/go/github.com/sirupsen/logrus.dep.yml rename to .licenses/arduino-flasher-cli/go/github.com/mattn/go-colorable.dep.yml index 07801f9..2bc368b 100644 --- a/.licenses/arduino-flasher-cli/go/github.com/sirupsen/logrus.dep.yml +++ b/.licenses/arduino-flasher-cli/go/github.com/mattn/go-colorable.dep.yml @@ -1,17 +1,16 @@ --- -name: github.com/sirupsen/logrus -version: v1.9.3 +name: github.com/mattn/go-colorable +version: v0.1.13 type: go -summary: Package logrus is a structured logger for Go, completely API compatible with - the standard library logger. -homepage: https://pkg.go.dev/github.com/sirupsen/logrus +summary: +homepage: https://pkg.go.dev/github.com/mattn/go-colorable license: mit licenses: - sources: LICENSE text: | The MIT License (MIT) - Copyright (c) 2014 Simon Eskildsen + Copyright (c) 2016 Yasuhiro Matsumoto Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,14 +19,16 @@ licenses: copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +- sources: README.md + text: MIT notices: [] diff --git a/.licenses/arduino-flasher-cli/go/github.com/mattn/go-isatty.dep.yml b/.licenses/arduino-flasher-cli/go/github.com/mattn/go-isatty.dep.yml new file mode 100644 index 0000000..fcf3912 --- /dev/null +++ b/.licenses/arduino-flasher-cli/go/github.com/mattn/go-isatty.dep.yml @@ -0,0 +1,22 @@ +--- +name: github.com/mattn/go-isatty +version: v0.0.20 +type: go +summary: Package isatty implements interface to isatty +homepage: https://pkg.go.dev/github.com/mattn/go-isatty +license: mit +licenses: +- sources: LICENSE + text: | + Copyright (c) Yasuhiro MATSUMOTO + + MIT License (Expat) + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +- sources: README.md + text: MIT +notices: [] diff --git a/.licenses/arduino-flasher-cli/go/github.com/shirou/gopsutil/v4/common.dep.yml b/.licenses/arduino-flasher-cli/go/github.com/shirou/gopsutil/v4/common.dep.yml new file mode 100644 index 0000000..6185644 --- /dev/null +++ b/.licenses/arduino-flasher-cli/go/github.com/shirou/gopsutil/v4/common.dep.yml @@ -0,0 +1,74 @@ +--- +name: github.com/shirou/gopsutil/v4/common +version: v4.25.10 +type: go +summary: 'SPDX-License-Identifier: BSD-3-Clause' +homepage: https://pkg.go.dev/github.com/shirou/gopsutil/v4/common +license: bsd-3-clause +licenses: +- sources: v4@v4.25.10/LICENSE + text: |- + gopsutil is distributed under BSD license reproduced below. + + Copyright (c) 2014, WAKAYAMA Shirou + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the gopsutil authors nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + ------- + internal/common/binary.go in the gopsutil is copied and modified from golang/encoding/binary.go. + + + + Copyright (c) 2009 The Go Authors. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +- sources: v4@v4.25.10/README.md + text: New BSD License (same as psutil) +notices: [] diff --git a/.licenses/arduino-flasher-cli/go/github.com/shirou/gopsutil/v4/disk.dep.yml b/.licenses/arduino-flasher-cli/go/github.com/shirou/gopsutil/v4/disk.dep.yml new file mode 100644 index 0000000..52a5db9 --- /dev/null +++ b/.licenses/arduino-flasher-cli/go/github.com/shirou/gopsutil/v4/disk.dep.yml @@ -0,0 +1,74 @@ +--- +name: github.com/shirou/gopsutil/v4/disk +version: v4.25.10 +type: go +summary: 'SPDX-License-Identifier: BSD-3-Clause' +homepage: https://pkg.go.dev/github.com/shirou/gopsutil/v4/disk +license: bsd-3-clause +licenses: +- sources: v4@v4.25.10/LICENSE + text: |- + gopsutil is distributed under BSD license reproduced below. + + Copyright (c) 2014, WAKAYAMA Shirou + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the gopsutil authors nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + ------- + internal/common/binary.go in the gopsutil is copied and modified from golang/encoding/binary.go. + + + + Copyright (c) 2009 The Go Authors. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +- sources: v4@v4.25.10/README.md + text: New BSD License (same as psutil) +notices: [] diff --git a/.licenses/arduino-flasher-cli/go/github.com/shirou/gopsutil/v4/internal/common.dep.yml b/.licenses/arduino-flasher-cli/go/github.com/shirou/gopsutil/v4/internal/common.dep.yml new file mode 100644 index 0000000..7f29c14 --- /dev/null +++ b/.licenses/arduino-flasher-cli/go/github.com/shirou/gopsutil/v4/internal/common.dep.yml @@ -0,0 +1,74 @@ +--- +name: github.com/shirou/gopsutil/v4/internal/common +version: v4.25.10 +type: go +summary: 'SPDX-License-Identifier: BSD-3-Clause' +homepage: https://pkg.go.dev/github.com/shirou/gopsutil/v4/internal/common +license: bsd-3-clause +licenses: +- sources: v4@v4.25.10/LICENSE + text: |- + gopsutil is distributed under BSD license reproduced below. + + Copyright (c) 2014, WAKAYAMA Shirou + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the gopsutil authors nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + ------- + internal/common/binary.go in the gopsutil is copied and modified from golang/encoding/binary.go. + + + + Copyright (c) 2009 The Go Authors. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +- sources: v4@v4.25.10/README.md + text: New BSD License (same as psutil) +notices: [] diff --git a/.licenses/arduino-flasher-cli/go/go.bug.st/relaxed-semver.dep.yml b/.licenses/arduino-flasher-cli/go/go.bug.st/relaxed-semver.dep.yml new file mode 100644 index 0000000..36bfdcf --- /dev/null +++ b/.licenses/arduino-flasher-cli/go/go.bug.st/relaxed-semver.dep.yml @@ -0,0 +1,45 @@ +--- +name: go.bug.st/relaxed-semver +version: v0.15.0 +type: go +summary: +homepage: https://pkg.go.dev/go.bug.st/relaxed-semver +license: bsd-3-clause +licenses: +- sources: LICENSE + text: |2+ + + Copyright (c) 2018-2025, Cristian Maglie. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +notices: [] +... diff --git a/.licenses/arduino-flasher-cli/go/golang.org/x/sys/unix.dep.yml b/.licenses/arduino-flasher-cli/go/golang.org/x/sys/unix.dep.yml index 6dacbe6..d9d7ef1 100644 --- a/.licenses/arduino-flasher-cli/go/golang.org/x/sys/unix.dep.yml +++ b/.licenses/arduino-flasher-cli/go/golang.org/x/sys/unix.dep.yml @@ -1,12 +1,12 @@ --- name: golang.org/x/sys/unix -version: v0.36.0 +version: v0.37.0 type: go summary: Package unix contains an interface to the low-level operating system primitives. homepage: https://pkg.go.dev/golang.org/x/sys/unix -license: bsd-3-clause +license: bsd-3-clause licenses: -- sources: sys@v0.36.0/LICENSE +- sources: sys@v0.37.0/LICENSE text: | Copyright 2009 The Go Authors. @@ -35,7 +35,7 @@ licenses: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- sources: sys@v0.36.0/PATENTS +- sources: sys@v0.37.0/PATENTS text: | Additional IP Rights Grant (Patents) diff --git a/.licenses/arduino-flasher-cli/go/gopkg.in/yaml.v3.dep.yml b/.licenses/arduino-flasher-cli/go/gopkg.in/yaml.v3.dep.yml new file mode 100644 index 0000000..9d2ff02 --- /dev/null +++ b/.licenses/arduino-flasher-cli/go/gopkg.in/yaml.v3.dep.yml @@ -0,0 +1,80 @@ +--- +name: gopkg.in/yaml.v3 +version: v3.0.1 +type: go +summary: Package yaml implements YAML support for the Go language. +homepage: https://pkg.go.dev/gopkg.in/yaml.v3 +license: apache-2.0 +licenses: +- sources: LICENSE + text: |2 + + This project is covered by two different licenses: MIT and Apache. + + #### MIT License #### + + The following files were ported to Go from C files of libyaml, and thus + are still covered by their original MIT license, with the additional + copyright staring in 2011 when the project was ported over: + + apic.go emitterc.go parserc.go readerc.go scannerc.go + writerc.go yamlh.go yamlprivateh.go + + Copyright (c) 2006-2010 Kirill Simonov + Copyright (c) 2006-2011 Kirill Simonov + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + ### Apache License ### + + All the remaining project files are covered by the Apache license: + + Copyright (c) 2011-2019 Canonical Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +- sources: README.md + text: |- + The yaml package is licensed under the MIT and Apache License 2.0 licenses. + Please see the LICENSE file for details. +notices: +- sources: NOTICE + text: |- + Copyright 2011-2016 Canonical Ltd. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7247529 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Arduino Flasher CLI + +A tool to download and flash Debian images on the board. + +## Docs + +For a full guide on how to use it, see the [User documentation](https://docs.arduino.cc/tutorials/uno-q/update-image/). + +## Build and test it locally + +Build it with `task build` and run: + +```sh +# Flash the latest release of the Debian image +./build/arduino-flasher-cli flash latest + +# Flash a local image. It works with either an archived or extracted image +./build/arduino-flasher-cli flash path/to/downloaded/image +``` diff --git a/check_for_updates.go b/check_for_updates.go new file mode 100644 index 0000000..7802f83 --- /dev/null +++ b/check_for_updates.go @@ -0,0 +1,65 @@ +// This file is part of arduino-flasher-cli. +// +// Copyright 2025 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-flasher-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package main + +import ( + "encoding/json" + "fmt" + "net/http" + "strings" + "time" + + semver "go.bug.st/relaxed-semver" +) + +const maxTime time.Duration = 1 * time.Second + +func checkForUpdates() (string, error) { + currentVersion, err := semver.Parse(Version) + if err != nil { + return "", err + } + + client := http.Client{Timeout: maxTime} + resp, err := client.Get("https://api.github.com/repos/arduino/arduino-flasher-cli/releases/latest") + if err != nil { + return "", err + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return "", fmt.Errorf("failed to fetch latest release: status code %d", resp.StatusCode) + } + var release struct { + TagName string `json:"tag_name"` + } + err = json.NewDecoder(resp.Body).Decode(&release) + if err != nil { + return "", err + } + + release.TagName = strings.TrimPrefix(release.TagName, "v") + latestVersion, err := semver.Parse(release.TagName) + if err != nil { + return "", err + } + + // Do nothing if the Arduino Flasher CLI is up to date + if currentVersion.GreaterThanOrEqual(latestVersion) { + return "", nil + } + + return latestVersion.String(), nil +} diff --git a/download.go b/download.go new file mode 100644 index 0000000..911bd69 --- /dev/null +++ b/download.go @@ -0,0 +1,59 @@ +// This file is part of arduino-flasher-cli. +// +// Copyright 2025 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-flasher-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package main + +import ( + "context" + "os" + + "github.com/arduino/go-paths-helper" + "github.com/spf13/cobra" + + "github.com/arduino/arduino-flasher-cli/feedback" + "github.com/arduino/arduino-flasher-cli/i18n" + "github.com/arduino/arduino-flasher-cli/updater" +) + +func newDownloadCmd() *cobra.Command { + var destDir string + cmd := &cobra.Command{ + Use: "download", + Short: "Download a Linux image to the specified path", + Args: cobra.ExactArgs(1), + Example: " " + os.Args[0] + " download latest\n" + + " " + os.Args[0] + " download latest --dest-dir /tmp\n", + Run: func(cmd *cobra.Command, args []string) { + runDownloadCommand(cmd.Context(), args, destDir) + }, + } + cmd.Flags().StringVar(&destDir, "dest-dir", ".", "Path to the directory in which the image will be downloaded") + + return cmd +} + +func runDownloadCommand(ctx context.Context, args []string, destDir string) { + targetVersion := args[0] + downloadPath := paths.New(destDir) + if !downloadPath.IsDir() { + feedback.Fatal(i18n.Tr("error: %s is not a directory. Please, select an existing directory.", destDir), feedback.ErrBadArgument) + } + + client := updater.NewClient() + _, _, err := updater.DownloadImage(ctx, client, targetVersion, nil, true, downloadPath) + if err != nil { + feedback.Fatal(i18n.Tr("error downloading the image: %v", err), feedback.ErrBadArgument) + } +} diff --git a/feedback/feedback.go b/feedback/feedback.go index 5fa9d0d..96cb6aa 100644 --- a/feedback/feedback.go +++ b/feedback/feedback.go @@ -22,8 +22,6 @@ import ( "io" "os" - "github.com/sirupsen/logrus" - "github.com/arduino/arduino-flasher-cli/i18n" ) @@ -161,7 +159,6 @@ func Warning(msg string) { } else { bufferWarnings = append(bufferWarnings, msg) } - logrus.Warning(msg) } // FatalError outputs the error and exits with status exitCode. diff --git a/flash.go b/flash.go index a439185..77c6b03 100644 --- a/flash.go +++ b/flash.go @@ -31,6 +31,7 @@ import ( func newFlashCmd() *cobra.Command { var forceYes bool + var tempDir string appCmd := &cobra.Command{ Use: "flash", Short: "Flash a Debian image on the board", @@ -61,15 +62,17 @@ NOTE: On Windows, required drivers are automatically installed with elevated pri " " + os.Args[0] + " flash ./my-image.tar.zst\n" + " " + os.Args[0] + " flash /path/to/debian-image.tar.zst\n" + " " + os.Args[0] + " flash /path/to/debian-image.tar.xz \n" + - " " + os.Args[0] + " flash /path/to/arduino-unoq-debian-image-20250915-173 \n", + " " + os.Args[0] + " flash /path/to/arduino-unoq-debian-image-20250915-173 \n" + + " " + os.Args[0] + " flash latest --temp-dir /path/to/custom/tempDir \n", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { checkDriversInstalled() - runFlashCommand(cmd.Context(), args, forceYes) + runFlashCommand(cmd.Context(), args, forceYes, tempDir) }, } appCmd.Flags().BoolVarP(&forceYes, "yes", "y", false, "Automatically confirm all prompts") + appCmd.Flags().StringVar(&tempDir, "temp-dir", "", "Path to the directory in which the image will be downloaded and extracted") // TODO: add --clean-install flag or something similar to distinguish between keeping and purging the /home directory return appCmd @@ -86,13 +89,13 @@ func checkDriversInstalled() { } } -func runFlashCommand(ctx context.Context, args []string, forceYes bool) { +func runFlashCommand(ctx context.Context, args []string, forceYes bool, tempDir string) { imagePath, err := paths.New(args[0]).Abs() if err != nil { feedback.Fatal(i18n.Tr("could not find image absolute path: %v", err), feedback.ErrBadArgument) } - err = updater.Flash(ctx, imagePath, args[0], forceYes) + err = updater.Flash(ctx, imagePath, args[0], forceYes, tempDir) if err != nil { feedback.Fatal(i18n.Tr("error flashing the board: %v", err), feedback.ErrBadArgument) } diff --git a/go.mod b/go.mod index 1f966aa..cc0dada 100644 --- a/go.mod +++ b/go.mod @@ -6,14 +6,16 @@ require ( github.com/arduino/go-paths-helper v1.14.0 github.com/arduino/go-windows-runas v1.0.1 github.com/codeclysm/extract/v4 v4.0.0 + github.com/fatih/color v1.18.0 github.com/jedib0t/go-pretty/v6 v6.6.8 github.com/leonelquinteros/gotext v1.7.2 github.com/schollz/progressbar/v3 v3.18.0 - github.com/sirupsen/logrus v1.9.3 + github.com/shirou/gopsutil/v4 v4.25.10 github.com/spf13/cobra v1.9.1 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 go.bug.st/cleanup v1.0.0 go.bug.st/f v0.4.0 + go.bug.st/relaxed-semver v0.15.0 ) require ( @@ -29,13 +31,14 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.11.5 // indirect github.com/dominikbraun/graph v0.23.0 // indirect + github.com/ebitengine/purego v0.9.0 // indirect github.com/elliotchance/orderedmap/v3 v3.1.0 // indirect github.com/emirpasic/gods v1.18.1 // indirect - github.com/fatih/color v1.18.0 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.6.2 // indirect github.com/go-git/go-git/v5 v5.16.2 // indirect + github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/go-task/task/v3 v3.44.1 // indirect github.com/go-task/template v0.2.0 // indirect @@ -56,6 +59,7 @@ require ( github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect github.com/pjbgf/sha1cd v0.3.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/sajari/fuzzy v1.0.0 // indirect @@ -65,11 +69,12 @@ require ( github.com/stretchr/objx v0.5.2 // indirect github.com/ulikunitz/xz v0.5.12 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect + github.com/yusufpapurcu/wmi v1.2.4 // indirect github.com/zeebo/xxh3 v1.0.2 // indirect golang.org/x/crypto v0.37.0 // indirect golang.org/x/net v0.39.0 // indirect golang.org/x/sync v0.16.0 // indirect - golang.org/x/sys v0.36.0 // indirect + golang.org/x/sys v0.37.0 // indirect golang.org/x/term v0.35.0 // indirect golang.org/x/text v0.24.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect diff --git a/go.sum b/go.sum index 386a8c9..50ec8ea 100644 --- a/go.sum +++ b/go.sum @@ -43,6 +43,8 @@ github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZ github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dominikbraun/graph v0.23.0 h1:TdZB4pPqCLFxYhdyMFb1TBdFxp8XLcJfTTBQucVPgCo= github.com/dominikbraun/graph v0.23.0/go.mod h1:yOjYyogZLY1LSG9E33JWZJiq5k83Qy2C6POAuiViluc= +github.com/ebitengine/purego v0.9.0 h1:mh0zpKBIXDceC63hpvPuGLiJ8ZAa3DfrFTudmfi8A4k= +github.com/ebitengine/purego v0.9.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o= github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE= github.com/elliotchance/orderedmap/v3 v3.1.0 h1:j4DJ5ObEmMBt/lcwIecKcoRxIQUEnw0L804lXYDt/pg= @@ -63,6 +65,9 @@ github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMj github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= github.com/go-git/go-git/v5 v5.16.2 h1:fT6ZIOjE5iEnkzKyxTHK1W4HGAsPhqEqiSAssSO77hM= github.com/go-git/go-git/v5 v5.16.2/go.mod h1:4Ge4alE/5gPs30F2H1esi2gPd69R0C39lolkucHBOp8= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= +github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI= github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= @@ -125,6 +130,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU= +github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/puzpuzpuz/xsync/v3 v3.5.1 h1:GJYJZwO6IdxN/IKbneznS6yPkVC+c3zyY/j19c++5Fg= github.com/puzpuzpuz/xsync/v3 v3.5.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -141,9 +148,9 @@ github.com/sebdah/goldie/v2 v2.7.1 h1:PkBHymaYdtvEkZV7TmyqKxdmn5/Vcj+8TpATWZjnG5 github.com/sebdah/goldie/v2 v2.7.1/go.mod h1:oZ9fp0+se1eapSRjfYbsV/0Hqhbuu3bJVvKI/NNtssI= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/shirou/gopsutil/v4 v4.25.10 h1:at8lk/5T1OgtuCp+AwrDofFRjnvosn0nkN2OLQ6g8tA= +github.com/shirou/gopsutil/v4 v4.25.10/go.mod h1:+kSwyC8DRUD9XXEHCAFjK+0nuArFJM0lva+StQAcskM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8= github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY= github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= @@ -156,13 +163,14 @@ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc= github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ= github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0= github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0= @@ -171,6 +179,8 @@ go.bug.st/cleanup v1.0.0 h1:XVj1HZxkBXeq3gMT7ijWUpHyIC1j8XAoNSyQ06CskgA= go.bug.st/cleanup v1.0.0/go.mod h1:EqVmTg2IBk4znLbPD28xne3abjsJftMdqqJEjhn70bk= go.bug.st/f v0.4.0 h1:Vstqb950nMA+PhAlRxUw8QL1ntHy/gXHNyyzjkQLJ10= go.bug.st/f v0.4.0/go.mod h1:bMo23205ll7UW63KwO1ut5RdlJ9JK8RyEEr88CmOF5Y= +go.bug.st/relaxed-semver v0.15.0 h1:w37+SYQPxF53RQO7QZZuPIMaPouOifdaP0B1ktst2nA= +go.bug.st/relaxed-semver v0.15.0/go.mod h1:bwHiCtYuD2m716tBk2OnOBjelsbXw9el5EIuyxT/ksU= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= @@ -181,17 +191,20 @@ golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= -golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= +golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ= golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA= @@ -207,7 +220,6 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= mvdan.cc/sh/v3 v3.12.0 h1:ejKUR7ONP5bb+UGHGEG/k9V5+pRVIyD+LsZz7o8KHrI= diff --git a/list.go b/list.go index 3902cf0..ed30d57 100644 --- a/list.go +++ b/list.go @@ -16,6 +16,8 @@ package main import ( + "context" + "github.com/jedib0t/go-pretty/v6/table" "github.com/spf13/cobra" @@ -31,16 +33,16 @@ func newListCmd() *cobra.Command { Short: "List the available Linux images", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - runListCommand() + runListCommand(cmd.Context()) }, } return cmd } -func runListCommand() { +func runListCommand(ctx context.Context) { client := updater.NewClient() - manifest, err := client.GetInfoManifest() + manifest, err := client.GetInfoManifest(ctx) if err != nil { feedback.Fatal(i18n.Tr("error retrieving the manifest: %v", err), feedback.ErrBadArgument) } diff --git a/main.go b/main.go index fb9ffe8..846f047 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ import ( "log/slog" "os" + "github.com/fatih/color" "github.com/spf13/cobra" "go.bug.st/cleanup" @@ -55,11 +56,28 @@ func main() { newFlashCmd(), newInstallDriversCmd(), newListCmd(), + newDownloadCmd(), &cobra.Command{ Use: "version", Short: "Print the version number of Arduino Flasher CLI", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Arduino Flasher CLI v" + Version) + feedback.PrintResult(versionResult{ + Name: "Arduino Flasher CLI", + Version: Version, + }) + + latest, err := checkForUpdates() + if err != nil { + feedback.Warning(color.YellowString("\n\nFailed to check for updates: "+err.Error()) + "\n") + } + if latest != "" { + msg := fmt.Sprintf("\n\n%s %s → %s\n%s", + color.YellowString(i18n.Tr("A new release of Arduino Flasher CLI is available:")), + color.CyanString(Version), + color.CyanString(latest), + color.YellowString("https://www.arduino.cc/en/software/#flasher-tool")) + feedback.Warning(msg) + } }, }) @@ -69,3 +87,17 @@ func main() { slog.Error(err.Error()) } } + +type versionResult struct { + Name string `json:"name"` + Version string `json:"version"` +} + +func (r versionResult) String() string { + resultMessage := fmt.Sprintf("Arduino Flasher CLI version %s", r.Version) + return resultMessage +} + +func (r versionResult) Data() interface{} { + return r +} diff --git a/updater/download_image.go b/updater/download_image.go index d5c1890..36f92f4 100644 --- a/updater/download_image.go +++ b/updater/download_image.go @@ -46,8 +46,8 @@ type Release struct { // DownloadConfirmCB is a function that is called when a Debian image is ready to be downloaded. type DownloadConfirmCB func(target string) (bool, error) -func DownloadAndExtract(client *Client, targetVersion string, upgradeConfirmCb DownloadConfirmCB, forceYes bool) (*paths.Path, string, error) { - tmpZip, version, err := DownloadImage(client, targetVersion, upgradeConfirmCb, forceYes) +func DownloadAndExtract(ctx context.Context, client *Client, targetVersion string, upgradeConfirmCb DownloadConfirmCB, forceYes bool, temp *paths.Path) (*paths.Path, string, error) { + tmpZip, version, err := DownloadImage(ctx, client, targetVersion, upgradeConfirmCb, forceYes, temp) if err != nil { return nil, "", fmt.Errorf("error downloading the image: %v", err) } @@ -57,7 +57,7 @@ func DownloadAndExtract(client *Client, targetVersion string, upgradeConfirmCb D return nil, "", nil } - err = ExtractImage(tmpZip, tmpZip.Parent()) + err = ExtractImage(ctx, tmpZip, tmpZip.Parent()) if err != nil { return nil, "", fmt.Errorf("error extracting the image: %v", err) } @@ -69,11 +69,11 @@ func DownloadAndExtract(client *Client, targetVersion string, upgradeConfirmCb D return imagePath, version, nil } -func DownloadImage(client *Client, targetVersion string, upgradeConfirmCb DownloadConfirmCB, forceYes bool) (*paths.Path, string, error) { +func DownloadImage(ctx context.Context, client *Client, targetVersion string, upgradeConfirmCb DownloadConfirmCB, forceYes bool, downloadPath *paths.Path) (*paths.Path, string, error) { var err error feedback.Print(i18n.Tr("Checking for Debian image releases")) - manifest, err := client.GetInfoManifest() + manifest, err := client.GetInfoManifest(ctx) if err != nil { return nil, "", err } @@ -105,19 +105,13 @@ func DownloadImage(client *Client, targetVersion string, upgradeConfirmCb Downlo } } - download, size, err := client.FetchZip(rel.Url) + download, size, err := client.FetchZip(ctx, rel.Url) if err != nil { return nil, "", fmt.Errorf("could not fetch Debian image: %w", err) } defer download.Close() - // Download the zip - temp, err := GetTempDir("download-") - if err != nil { - return nil, "", fmt.Errorf("could not create temporary download directory: %w", err) - } - - tmpZip := temp.Join("update.tar.zst") + tmpZip := downloadPath.Join("arduino-unoq-debian-image-" + rel.Version + ".tar.zst") tmpZipFile, err := tmpZip.Create() if err != nil { return nil, "", err @@ -146,7 +140,7 @@ func DownloadImage(client *Client, targetVersion string, upgradeConfirmCb Downlo return tmpZip, rel.Version, nil } -func ExtractImage(archive, temp *paths.Path) error { +func ExtractImage(ctx context.Context, archive, temp *paths.Path) error { // Unzip the Debian image feedback.Print(i18n.Tr("Unzipping Debian image")) tmpZipFile, err := archive.Open() @@ -155,7 +149,7 @@ func ExtractImage(archive, temp *paths.Path) error { } defer tmpZipFile.Close() - if err := extract.Archive(context.Background(), tmpZipFile, temp.String(), func(s string) string { + if err := extract.Archive(ctx, tmpZipFile, temp.String(), func(s string) string { feedback.Print(s) return s }); err != nil { @@ -164,20 +158,26 @@ func ExtractImage(archive, temp *paths.Path) error { return nil } -// GetTempDir returns a temporary directory inside the user's cache directory. +// SetTempDir returns a temporary directory inside the user's cache directory (default). +// The tempDir parameter is used to change the download/extraction directory. // The caller is responsible for removing the directory when no longer needed. -func GetTempDir(prefix string) (*paths.Path, error) { - userCacheDir, err := os.UserCacheDir() - if err != nil { - return nil, fmt.Errorf("could not get user's cache directory: %w", err) - } +func SetTempDir(prefix string, tempDir string) (*paths.Path, error) { + cacheDir := paths.New(tempDir) - cacheDir := paths.New(userCacheDir, "arduino-flasher-cli") - _ = cacheDir.MkdirAll() + if cacheDir == nil { + userCacheDir, err := os.UserCacheDir() + if err != nil { + return nil, fmt.Errorf("could not get user's cache directory: %w", err) + } + + cacheDir = paths.New(userCacheDir, "arduino-flasher-cli") + _ = cacheDir.MkdirAll() + } temp, err := paths.MkTempDir(cacheDir.String(), prefix) if err != nil { return nil, fmt.Errorf("could not create .cache directory: %w", err) } + return temp, nil } diff --git a/updater/flasher.go b/updater/flasher.go index 9daae0e..d0104ce 100644 --- a/updater/flasher.go +++ b/updater/flasher.go @@ -22,17 +22,37 @@ import ( "strings" "github.com/arduino/go-paths-helper" + "github.com/shirou/gopsutil/v4/disk" "github.com/arduino/arduino-flasher-cli/feedback" "github.com/arduino/arduino-flasher-cli/i18n" "github.com/arduino/arduino-flasher-cli/updater/artifacts" ) -func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes bool) error { +const GiB = uint64(1024 * 1024 * 1024) +const DownloadDiskSpace = uint64(12) +const ExtractDiskSpace = uint64(10) + +func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes bool, tempDir string) error { if !imagePath.Exist() { client := NewClient() - tempImagePath, v, err := DownloadAndExtract(client, version, func(target string) (bool, error) { + temp, err := SetTempDir("download-", tempDir) + if err != nil { + return fmt.Errorf("error creating a temporary directory to extract the archive: %v", err) + } + defer func() { _ = temp.RemoveAll() }() + + // Check if there is enough free disk space before downloading and extracting an image + d, err := disk.Usage(temp.String()) + if err != nil { + return err + } + if d.Free/GiB < DownloadDiskSpace { + return fmt.Errorf("download and extraction requires up to %d GiB of free space", DownloadDiskSpace) + } + + tempImagePath, v, err := DownloadAndExtract(ctx, client, version, func(target string) (bool, error) { feedback.Printf("Found Debian image version: %s", target) feedback.Printf("Do you want to download it? (yes/no)") @@ -43,7 +63,7 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes } yes := strings.ToLower(yesInput) == "yes" || strings.ToLower(yesInput) == "y" return yes, nil - }, forceYes) + }, forceYes, temp) if err != nil { return fmt.Errorf("could not download and extract the image: %v", err) @@ -59,13 +79,22 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes version = v imagePath = tempImagePath } else if !imagePath.IsDir() { - temp, err := GetTempDir("extract-") + temp, err := SetTempDir("extract-", tempDir) if err != nil { return fmt.Errorf("error creating a temporary directory to extract the archive: %v", err) } defer func() { _ = temp.RemoveAll() }() - err = ExtractImage(imagePath, temp) + // Check if there is enough free disk space before extracting an image + d, err := disk.Usage(temp.String()) + if err != nil { + return err + } + if d.Free/GiB < ExtractDiskSpace { + return fmt.Errorf("extraction requires up to %d GiB of free space", ExtractDiskSpace) + } + + err = ExtractImage(ctx, imagePath, temp) if err != nil { return fmt.Errorf("error extracting the archive: %v", err) } diff --git a/updater/http_client.go b/updater/http_client.go index 240dc98..58b0a3e 100644 --- a/updater/http_client.go +++ b/updater/http_client.go @@ -16,6 +16,7 @@ package updater import ( + "context" "crypto/sha256" "encoding/hex" "encoding/json" @@ -79,9 +80,9 @@ func (c *Client) addHeaders(req *http.Request) { } // GetInfoManifest fetches and decodes the Debian images info.json. -func (c *Client) GetInfoManifest() (Manifest, error) { +func (c *Client) GetInfoManifest(ctx context.Context) (Manifest, error) { manifestURL := baseURL.JoinPath(pathRelease, "info.json").String() - req, err := http.NewRequest("GET", manifestURL, nil) + req, err := http.NewRequestWithContext(ctx, "GET", manifestURL, nil) if err != nil { return Manifest{}, fmt.Errorf("failed to create request: %w", err) } @@ -109,8 +110,8 @@ func (c *Client) GetInfoManifest() (Manifest, error) { } // FetchZip fetches the Debian image archive. -func (c *Client) FetchZip(zipURL string) (io.ReadCloser, int64, error) { - req, err := http.NewRequest("GET", zipURL, nil) +func (c *Client) FetchZip(ctx context.Context, zipURL string) (io.ReadCloser, int64, error) { + req, err := http.NewRequestWithContext(ctx, "GET", zipURL, nil) if err != nil { return nil, 0, fmt.Errorf("failed to create request: %w", err) }