forked from redox-os/ion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ion
executable file
·89 lines (78 loc) · 2.83 KB
/
setup.ion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env ion
# Get the root directory of the cargo project.
let PROJECT_DIR = $parent(@split($(cargo locate-project), '"')[3])
# If the destination for the binary was not give, set it.
if not exists ${env::DESTDIR}
let DESTDIR = "/usr/bin/"
end
# If the share directory was not given, set it.
if not exists ${env::SHAREDIR}
let SHAREDIR = "/usr/share/ion/";
end
# Ensure that we begin execution with this as the working directory.
cd $PROJECT_DIR
fn print_option definition description
echo " ${c::bold}- ${c::0x0CF}$definition: ${c::reset}$description"
end
# Print all available options
fn show_options
echo -e "${c::0x0F6}Available options for this script are:${c::reset}"
print_option "build ion" " Build the Ion shell"
print_option "build docs" " Build the Ion mdBook"
print_option "install ion" " Install the Ion Shell"
print_option "install docs" " Install the Ion mdBook"
print_option "install plugins" "Install official Ion plugins"
print_option "uninstall ion" " Removes Ion from System"
end
# In case a bad argument was supplied, this will be used.
fn bad_arg argument
echo -e "${c::0xF60,bold}Error: ${c::0xF06}`$argument`${c::0xF60} is \
not a valid command.${c::reset}"
show_options
exit
end
# Arguments are required!
if test 1 -eq $len(@args)
echo -e "${c::0xF60,bold}Error: must proved command.${c::reset}"
show_options
exit
end
# Rust/Cargo is required!
if not exists -b "cargo"
echo "${c::0xF60,bold}Error: Rust/Cargo is not installed."
echo "${c::0x09F}Hint: `curl https://sh.rustup.rs -sSf | sh`"
exit
end
# Nightly Rust is currently required
if not exists $(rustc --version | grep nightly)
echo "${c::0xF60,bold}Error: Project currently requires a nightly version Rust."
echo "${c::0x09F}Hint: `rustup default nightly`"
exit
end
# The first and second argument will determine what the user wants.
match "@args[1..3]"
case "build ion"
cargo build --release
case "build docs"
if not exists -b "mdbook"
echo "${c::0x09F}Installing mdbook from Crates.io${c::reset}"
cargo install mdbook --force
end
cd manual && mdbook build
case "install ion"
sudo install target/release/ion ${DESTDIR}/ion
case "install docs"
echo "${c::0xF30,bold}Installing documentation with root${c::reset}"
sudo mkdir -p ${SHAREDIR}/docs/
sudo cp manual/book/* ${SHAREDIR}/docs/ -R
case "install plugins"
git clone https://github.com/mmstick/ion-plugins
cd ion-plugins && ion install.ion
case "uninstall ion"
echo "${c::0xF30,bold}Removing ${c::0x09F}${DESTDIR}${c::0xF30}/ion \
and ${c::0xF30}${SHAREDIR}${c::reset}"
sudo rm ${DESTDIR}/ion
sudo rm ${SHAREDIR} -R
case _
bad_arg "@args[1..3]"
end