-
Notifications
You must be signed in to change notification settings - Fork 30
[script] install nodes in ~/.local/share/otns so that OTNS can run from anywhere #773
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #!/bin/bash | ||
| # Copyright (c) 2020-2026, The OTNS 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: | ||
| # 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. | ||
|
|
||
| # Installs OTNS (without any OT node executables) and pyOTNS. | ||
|
|
||
| # shellcheck source=script/common.sh | ||
| . "$(dirname "$0")"/common.sh | ||
|
|
||
| install_otns() | ||
| { | ||
| go mod tidy | ||
| repeat 3 go_install ./cmd/... | ||
| echo "otns installed: $(command -v otns)" | ||
| } | ||
|
|
||
| install_pyotns() | ||
| { | ||
| activate_python_venv | ||
| cd pylibs || die "required directory 'pylibs' not found" | ||
| python3 -m pip install . | ||
| # python3 setup.py install --user --prefix= 2>/dev/null # alternative - fails on macos-14 | ||
| cd - || die "cd failed" | ||
| } | ||
|
|
||
| main() | ||
| { | ||
| install_pyotns | ||
| install_otns | ||
| } | ||
|
|
||
| main |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Copyright (c) 2020-2024, The OTNS Authors. | ||
| // Copyright (c) 2020-2026, The OTNS Authors. | ||
| // All rights reserved. | ||
| // | ||
| // Redistribution and use in source and binary forms, with or without | ||
|
|
@@ -37,6 +37,14 @@ import ( | |
| "golang.org/x/net/ipv6" | ||
| ) | ||
|
|
||
| func filePathInUserHomeDir(relPath string) string { | ||
| home, err := os.UserHomeDir() | ||
| if err == nil { | ||
| return filepath.Join(home, relPath) | ||
| } | ||
| return "/tmp/UserHomeDirNotFound" | ||
| } | ||
|
Comment on lines
+40
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling for func filePathInUserHomeDir(relPath string) string {
home, err := os.UserHomeDir()
if err != nil {
// os.UserHomeDir() can fail in some environments (e.g. when cross-compiling).
// Return a path that is unlikely to exist, so the executable search will
// gracefully fail for this path and continue with other search paths.
return "/tmp/otns-home-dir-not-found"
}
return filepath.Join(home, relPath)
} |
||
|
|
||
| func removeAllFiles(globPath string) error { | ||
| files, err := filepath.Glob(globPath) | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better compliance with the XDG Base Directory Specification and to improve robustness, consider using the
$XDG_DATA_HOMEenvironment variable, which defaults to$HOME/.local/share. This avoids hardcoding the path and respects user configurations. Using a variable also makes the code cleaner by avoiding repetition.