mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-28 08:01:33 +00:00
Added self-update command
This commit is contained in:
57
install.sh
57
install.sh
@ -225,6 +225,9 @@ wasmer_install() {
|
|||||||
magenta2="${reset}\033[34m"
|
magenta2="${reset}\033[34m"
|
||||||
magenta3="${reset}\033[34;2m"
|
magenta3="${reset}\033[34;2m"
|
||||||
|
|
||||||
|
if which wasmer >/dev/null; then
|
||||||
|
printf "${reset}Updating wasmer$reset\n"
|
||||||
|
else
|
||||||
printf "${reset}Installing Wasmer!$reset\n"
|
printf "${reset}Installing Wasmer!$reset\n"
|
||||||
printf "
|
printf "
|
||||||
${magenta1} ${magenta2} ${magenta3}###${reset}
|
${magenta1} ${magenta2} ${magenta3}###${reset}
|
||||||
@ -245,6 +248,7 @@ wasmer_install() {
|
|||||||
${magenta1}####${reset}
|
${magenta1}####${reset}
|
||||||
|
|
||||||
"
|
"
|
||||||
|
fi
|
||||||
# if [ -d "$HOME/.wasmer" ]; then
|
# if [ -d "$HOME/.wasmer" ]; then
|
||||||
# if which wasmer; then
|
# if which wasmer; then
|
||||||
# local latest_url
|
# local latest_url
|
||||||
@ -290,9 +294,41 @@ wasmer_install() {
|
|||||||
|
|
||||||
|
|
||||||
wasmer_reset() {
|
wasmer_reset() {
|
||||||
unset -f wasmer_install wasmer_reset wasmer_download_json wasmer_link wasmer_detect_profile wasmer_download_file wasmer_download wasmer_verify_or_quit
|
unset -f wasmer_install wasmer_compareversions wasmer_reset wasmer_download_json wasmer_link wasmer_detect_profile wasmer_download_file wasmer_download wasmer_verify_or_quit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Example taken from
|
||||||
|
# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
|
||||||
|
wasmer_compareversions () {
|
||||||
|
if [[ $1 == $2 ]]
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
local IFS=.
|
||||||
|
local i ver1=($1) ver2=($2)
|
||||||
|
# fill empty fields in ver1 with zeros
|
||||||
|
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
|
||||||
|
do
|
||||||
|
ver1[i]=0
|
||||||
|
done
|
||||||
|
for ((i=0; i<${#ver1[@]}; i++))
|
||||||
|
do
|
||||||
|
if [[ -z ${ver2[i]} ]]
|
||||||
|
then
|
||||||
|
# fill empty fields in ver2 with zeros
|
||||||
|
ver2[i]=0
|
||||||
|
fi
|
||||||
|
if ((10#${ver1[i]} > 10#${ver2[i]}))
|
||||||
|
then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if ((10#${ver1[i]} < 10#${ver2[i]}))
|
||||||
|
then
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
wasmer_download() {
|
wasmer_download() {
|
||||||
# identify platform based on uname output
|
# identify platform based on uname output
|
||||||
@ -322,6 +358,25 @@ wasmer_download() {
|
|||||||
printf "\033[1A$cyan> Getting wasmer releases... ✓$reset\n"
|
printf "\033[1A$cyan> Getting wasmer releases... ✓$reset\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if which wasmer >/dev/null; then
|
||||||
|
WASMER_VERSION=$(wasmer --version | sed 's/[a-z[:blank:]]//g')
|
||||||
|
wasmer_compareversions "$WASMER_VERSION" "$WASMER_RELEASE_TAG"
|
||||||
|
case $? in
|
||||||
|
# WASMER_VERSION = WASMER_RELEASE_TAG
|
||||||
|
0)
|
||||||
|
printf "You are already on the latest wasmer: ${WASMER_RELEASE_TAG}\n";
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
# WASMER_VERSION > WASMER_RELEASE_TAG
|
||||||
|
1)
|
||||||
|
printf "You are already on a more recent version than the published one: ${WASMER_RELEASE_TAG}.\nExiting\n";
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
# WASMER_VERSION < WASMER_RELEASE_TAG (we continue)
|
||||||
|
2)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
# fetch the real release data to make sure it exists before we attempt a download
|
# fetch the real release data to make sure it exists before we attempt a download
|
||||||
wasmer_download_json RELEASE_DATA "$RELEASES_URL/tag/$WASMER_RELEASE_TAG"
|
wasmer_download_json RELEASE_DATA "$RELEASES_URL/tag/$WASMER_RELEASE_TAG"
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ mod macros;
|
|||||||
mod recovery;
|
mod recovery;
|
||||||
pub mod apis;
|
pub mod apis;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
mod update;
|
||||||
pub mod sighandler;
|
pub mod sighandler;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod spectests;
|
mod spectests;
|
||||||
@ -41,6 +42,10 @@ enum CLIOptions {
|
|||||||
/// Run a WebAssembly file. Formats accepted: wasm, wast
|
/// Run a WebAssembly file. Formats accepted: wasm, wast
|
||||||
#[structopt(name = "run")]
|
#[structopt(name = "run")]
|
||||||
Run(Run),
|
Run(Run),
|
||||||
|
|
||||||
|
/// Update wasmer to the latest version
|
||||||
|
#[structopt(name = "self-update")]
|
||||||
|
SelfUpdate,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
@ -117,5 +122,6 @@ fn main() {
|
|||||||
let options = CLIOptions::from_args();
|
let options = CLIOptions::from_args();
|
||||||
match options {
|
match options {
|
||||||
CLIOptions::Run(options) => run(options),
|
CLIOptions::Run(options) => run(options),
|
||||||
|
CLIOptions::SelfUpdate => update::self_update(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
src/update.rs
Normal file
17
src/update.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
//! When wasmer self-update is executed, this is what gets executed
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
pub fn self_update() {
|
||||||
|
println!("Fetching latest installer");
|
||||||
|
let cmd = Command::new("curl").arg("https://get.wasmer.io").arg("-sSfL")
|
||||||
|
.stdout(Stdio::piped()).spawn().unwrap();
|
||||||
|
|
||||||
|
let mut the_process = Command::new("sh")
|
||||||
|
.stdin(cmd.stdout.unwrap())
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.spawn()
|
||||||
|
.ok().expect("Failed to execute.");
|
||||||
|
|
||||||
|
the_process.wait();
|
||||||
|
}
|
Reference in New Issue
Block a user