Skip to content

Commit 47a8b7d

Browse files
committed
Merge branch 'main' into augustoccesar/improve-linux-support
# Conflicts: # linkup-cli/src/services/caddy.rs
2 parents 586d6d5 + d4c5f29 commit 47a8b7d

File tree

12 files changed

+653
-42
lines changed

12 files changed

+653
-42
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store
2+
13
.idea
24
.vscode
35

Cargo.lock

Lines changed: 88 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linkup-cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ regex = "1.11.0"
2222
reqwest = { version = "0.12.8", default-features = false, features = [
2323
"blocking",
2424
"rustls-tls",
25+
"json",
2526
] }
2627
serde = "1.0.210"
2728
serde_json = "1.0.129"
@@ -33,6 +34,8 @@ base64 = "0.22.1"
3334
env_logger = "0.11.5"
3435
crossterm = "0.28.1"
3536
sysinfo = "0.32.1"
37+
tar = "0.4.43"
38+
flate2 = "1.0.35"
3639

3740
[dev-dependencies]
3841
mockall = "0.13.0"

linkup-cli/install.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
if command -v linkup &>/dev/null; then
2+
echo "Linkup is already installed. To update it, run 'linkup update'."
3+
exit 0
4+
fi
5+
6+
# region: Dependencies
7+
# TODO: Maybe we want this script to be able to install the dependencies as well?
8+
if ! command -v cloudflared &>/dev/null; then
9+
echo "WARN: 'cloudflared' is not installed. Some features will not work as expected. Please install it.\nFor more info check: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/"
10+
fi
11+
12+
if ! command -v caddy &>/dev/null; then
13+
echo "WARN: 'caddy' is not installed. Some features will not work as expected. Please install it.\nFor more info check: https://caddyserver.com/docs/install"
14+
fi
15+
16+
if ! command -v dnsmasq &>/dev/null; then
17+
echo "WARN: 'dnsmasq' is not installed. Some features will not work as expected. Please install it.\nFor more info check: https://thekelleys.org.uk/dnsmasq/doc.html"
18+
fi
19+
# endregion: Dependencies
20+
21+
OS=$(uname -s)
22+
ARCH=$(uname -m)
23+
24+
FETCH_OS=''
25+
FETCH_ARCH=''
26+
if [[ "$OS" == "Darwin"* ]]; then
27+
FETCH_OS='apple-darwin'
28+
29+
if [[ "$ARCH" == "arm64" ]]; then
30+
FETCH_ARCH='aarch64'
31+
elif [[ "$arch" == "x86_64" ]]; then
32+
FETCH_ARCH='x86_64'
33+
fi
34+
elif [[ "$OS" == "Linux"* ]]; then
35+
FETCH_OS='unknown-linux'
36+
37+
if [[ "$ARCH" == "arm64" ]]; then
38+
FETCH_ARCH='aarch64'
39+
elif [[ "$arch" == "x86_64" ]]; then
40+
FETCH_ARCH='x86_64'
41+
fi
42+
fi
43+
44+
if [[ -z "$FETCH_OS" || -z "$FETCH_ARCH" ]]; then
45+
echo "Unsupported OS/Arch combination: $OS/$ARCH"
46+
exit 1
47+
fi
48+
49+
LOOKUP_FILE_DOWNLOAD_URL="https://github.com/mentimeter/linkup/releases/download/.*/linkup-.*-$FETCH_ARCH-$FETCH_OS.tar.gz"
50+
FILE_DOWNLOAD_URL=$(
51+
curl -sL \
52+
-H "Accept: application/vnd.github+json" \
53+
-H "X-GitHub-Api-Version: 2022-11-28" \
54+
https://api.github.com/repos/mentimeter/linkup/releases/latest |
55+
grep -Eio "$LOOKUP_FILE_DOWNLOAD_URL"
56+
)
57+
58+
if [ -z "$FILE_DOWNLOAD_URL" ]; then
59+
echo "Could not find file with pattern '$LOOKUP_FILE_DOWNLOAD_URL' on the latest GitHub release."
60+
exit 1
61+
fi
62+
63+
echo "Downloading: $FILE_DOWNLOAD_URL"
64+
curl -sLO --output-dir "/tmp" $FILE_DOWNLOAD_URL
65+
66+
LOCAL_FILE_PATH="/tmp/$(basename $FILE_DOWNLOAD_URL)"
67+
68+
echo "Decompressing $LOCAL_FILE_PATH"
69+
tar -xzf $LOCAL_FILE_PATH -C /tmp
70+
71+
mkdir -p $HOME/.linkup/bin
72+
mv /tmp/linkup $HOME/.linkup/bin/
73+
echo "Linkup installed on $HOME/.linkup/bin/linkup"
74+
75+
rm "$LOCAL_FILE_PATH"
76+
77+
if [[ ":$PATH:" != *":$HOME/.linkup/bin:"* ]]; then
78+
SHELL_NAME=$(basename "$SHELL")
79+
case "$SHELL_NAME" in
80+
bash)
81+
PROFILE_FILE="$HOME/.bashrc"
82+
;;
83+
zsh)
84+
PROFILE_FILE="$HOME/.zshrc"
85+
;;
86+
fish)
87+
PROFILE_FILE="$HOME/.config/fish/config.fish"
88+
;;
89+
*)
90+
PROFILE_FILE="$HOME/.profile"
91+
;;
92+
esac
93+
94+
echo "Adding Linkup bin to PATH in $PROFILE_FILE"
95+
echo "\n# Linkup bin\nexport PATH=\$PATH:\$HOME/.linkup/bin" >>"$PROFILE_FILE"
96+
echo "Please source your profile file or restart your terminal to apply the changes."
97+
fi

linkup-cli/src/commands/local_dns.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,18 @@ fn uninstall_resolvers(resolve_domains: &[String]) -> Result<()> {
153153
Ok(())
154154
}
155155

156-
pub fn list_resolvers() -> Result<Vec<String>> {
157-
let resolvers = fs::read_dir("/etc/resolver/")?
158-
.map(|f| f.unwrap().file_name().into_string().unwrap())
156+
pub fn list_resolvers() -> std::result::Result<Vec<String>, std::io::Error> {
157+
let resolvers_dir = match fs::read_dir("/etc/resolver/") {
158+
Ok(read_dir) => read_dir,
159+
Err(err) => match err.kind() {
160+
std::io::ErrorKind::NotFound => return Ok(vec![]),
161+
_ => return Err(err),
162+
},
163+
};
164+
165+
let resolvers = resolvers_dir
166+
.filter_map(|entry| entry.ok())
167+
.filter_map(|entry| entry.file_name().into_string().ok())
159168
.collect();
160169

161170
Ok(resolvers)

linkup-cli/src/commands/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub mod server;
99
pub mod start;
1010
pub mod status;
1111
pub mod stop;
12+
pub mod uninstall;
13+
pub mod update;
1214

1315
pub use {completion::completion, completion::Args as CompletionArgs};
1416
pub use {health::health, health::Args as HealthArgs};
@@ -21,3 +23,5 @@ pub use {server::server, server::Args as ServerArgs};
2123
pub use {start::start, start::Args as StartArgs};
2224
pub use {status::status, status::Args as StatusArgs};
2325
pub use {stop::stop, stop::Args as StopArgs};
26+
pub use {uninstall::uninstall, uninstall::Args as UninstallArgs};
27+
pub use {update::update, update::Args as UpdateArgs};

linkup-cli/src/commands/stop.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@ use crate::{services, CliError};
99
pub struct Args {}
1010

1111
pub fn stop(_args: &Args, clear_env: bool) -> Result<(), CliError> {
12-
let state = LocalState::load()?;
12+
match (LocalState::load(), clear_env) {
13+
(Ok(state), true) => {
14+
// Reset env vars back to what they were before
15+
for service in &state.services {
16+
let remove_res = match &service.directory {
17+
Some(d) => remove_service_env(d.clone(), state.linkup.config_path.clone()),
18+
None => Ok(()),
19+
};
1320

14-
if clear_env {
15-
// Reset env vars back to what they were before
16-
for service in &state.services {
17-
let remove_res = match &service.directory {
18-
Some(d) => remove_service_env(d.clone(), state.linkup.config_path.clone()),
19-
None => Ok(()),
20-
};
21-
22-
if let Err(e) = remove_res {
23-
println!("Could not remove env for service {}: {}", service.name, e);
21+
if let Err(e) = remove_res {
22+
println!("Could not remove env for service {}: {}", service.name, e);
23+
}
2424
}
2525
}
26+
(Ok(_), false) => (),
27+
(Err(err), _) => {
28+
log::warn!("Failed to fetch local state: {}", err);
29+
}
2630
}
2731

2832
services::LocalServer::new().stop().unwrap();

0 commit comments

Comments
 (0)