forked from dswd/vpncloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Static builds that can install themselves
- Loading branch information
Showing
9 changed files
with
130 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,49 @@ | ||
use crate::error::Error; | ||
use std::{ | ||
env, | ||
fs::{self, File}, | ||
io::Write, | ||
os::unix::fs::PermissionsExt | ||
}; | ||
|
||
const MANPAGE: &[u8] = include_bytes!("../target/vpncloud.1.gz"); | ||
const SERVICE_FILE: &[u8] = include_bytes!("../assets/vpncloud@.service"); | ||
const WS_PROXY_SERVICE_FILE: &[u8] = include_bytes!("../assets/vpncloud-wsproxy.service"); | ||
const EXAMPLE_CONFIG: &[u8] = include_bytes!("../assets/example.net.disabled"); | ||
|
||
pub fn install() -> Result<(), Error> { | ||
env::current_exe() | ||
.and_then(|p| fs::copy(p, "/usr/bin/vpncloud")) | ||
.map_err(|e| Error::FileIo("Failed to copy binary", e))?; | ||
fs::set_permissions("/usr/bin/vpncloud", fs::Permissions::from_mode(755)) | ||
.map_err(|e| Error::FileIo("Failed to set permissions for binary", e))?; | ||
fs::create_dir_all("/etc/vpncloud").map_err(|e| Error::FileIo("Failed to create config folder", e))?; | ||
fs::set_permissions("/etc/vpncloud", fs::Permissions::from_mode(600)) | ||
.map_err(|e| Error::FileIo("Failed to set permissions for config folder", e))?; | ||
File::create("/etc/vpncloud/example.net.disabled") | ||
.and_then(|mut f| f.write_all(EXAMPLE_CONFIG)) | ||
.map_err(|e| Error::FileIo("Failed to create example config", e))?; | ||
File::create("/usr/share/man/man1/vpncloud.1.gz") | ||
.and_then(|mut f| f.write_all(MANPAGE)) | ||
.map_err(|e| Error::FileIo("Failed to create manpage", e))?; | ||
File::create("/lib/systemd/system/vpncloud@.service") | ||
.and_then(|mut f| f.write_all(SERVICE_FILE)) | ||
.map_err(|e| Error::FileIo("Failed to create service file", e))?; | ||
File::create("/lib/systemd/system/vpncloud-wsproxy.service") | ||
.and_then(|mut f| f.write_all(WS_PROXY_SERVICE_FILE)) | ||
.map_err(|e| Error::FileIo("Failed to create wsporxy service file", e))?; | ||
info!("Install successful"); | ||
Ok(()) | ||
} | ||
|
||
pub fn uninstall() -> Result<(), Error> { | ||
fs::remove_file("/etc/vpncloud/example.net.disabled").map_err(|e| Error::FileIo("Failed to remove binary", e))?; | ||
fs::remove_file("/usr/share/man/man1/vpncloud.1.gz").map_err(|e| Error::FileIo("Failed to remove manpage", e))?; | ||
fs::remove_file("/lib/systemd/system/vpncloud@.service") | ||
.map_err(|e| Error::FileIo("Failed to remove service file", e))?; | ||
fs::remove_file("/lib/systemd/system/vpncloud-wsproxy.service") | ||
.map_err(|e| Error::FileIo("Failed to remove wsproxy service file", e))?; | ||
fs::remove_file("/usr/bin/vpncloud").map_err(|e| Error::FileIo("Failed to remove binary", e))?; | ||
info!("Uninstall successful"); | ||
Ok(()) | ||
} |
This file contains 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