-
Notifications
You must be signed in to change notification settings - Fork 2
/
MicroHelper
executable file
·83 lines (71 loc) · 2.72 KB
/
MicroHelper
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
#!/usr/bin/env bash
. "${BASH_SOURCE[0]%/*}/function.sh" app script || exit
usage()
{
ScriptUsage "$1" "\
Usage: $(ScriptName) [OPTION]... [close|download|install|IsInstalled|IsRunning|profile|program|restart|start|startup](start)
$(ScriptName) commands."
}
init()
{
defaultCommand="start"
profileName="micro" profileDir="$HOME/.config/micro" profileMask="*"
program="$(FindInPath "micro")"
return 0
}
closeCommand() { ! isRunningCommand && return 0; ProcessClose "$program"; }
isInstalledCommand() { [[ -e "$program" ]]; }
isRunningCommand() { IsProcessRunning "$program"; }
profileUsage() { echot "Usage: $(ScriptName) profile dir|SaveDir|save|restore [<profile name>|default](latest)\n$(ScriptName) configuration."; }
profileArgs() { profileArgs=( "$@" ); (( shift+=$# )); return 0; }
profileCommand() { profile $noPrompt --app "$profileName" --method "$profileDir" --files "$profileMask" "${profileArgs[@]}"; }
programCommand() { echo "$program"; }
restartCommand() { closeCommand && startCommand; }
startArgs() { startArgs=( "$@" ); shift="$#"; }
startCommand() { AppInstallCheck && start $wait "$program" "${startArgs[@]}"; }
startupCommand() { startCommand; }
versionCommand() { AppInstallCheck && AppVersion "$program"; }
downloadCommand()
{
# find the install location
local dir; dir="$(FindInstallFile "shareware/micro")" || return
# download the executables
cd "$dir" || return
local platform platforms=( linux64 linux-arm linux-arm64 osx )
for platform in "${platforms[@]}"; do
header "Downloading micro for $platform..."
export GETMICRO_PLATFORM="$platform"
curl https://getmic.ro | bash || return
mv "micro" "micro_$platform" || return
done
}
installUsage() { echot "Usage: micro install [HOST]\n Install micro locally or on the specified host."; }
installArgStart() { unset -v host; }
installArgs() { (( $# == 0 )) && return; ScriptArgGet "host" -- "$@"; }
installCommand()
{
# get the host platform information
ScriptEval HostGetInfo $host || return
# determine the executable to use
local suffix
if IsPlatformAll arm,64 --host; then suffix="linux-arm64"
elif IsPlatformAll arm,32 --host; then suffix="linux-arm"
elif IsPlatform mac --host; then suffix="osx"
elif IsPlatform linux,win --host && ! IsPlatform mips --host; then suffix="linux64"
else
[[ ! $quiet ]] && EchoErr "micro is not available on '$_machine'"
return 1
fi
# determine the destination directory
local destDir="/usr/local/bin"
IsPlatform openwrt,ubiquiti --host && destDir="/usr/bin"
# find the executable
local file="$(FindInstallFile "shareware/micro/micro_$suffix")" || return
# copy the executable
if [[ $host ]]; then
scp "$file" "$host:$destDir/micro" || return
else
sudo cp "$file" "/usr/local/bin/micro" || return
fi
}
ScriptRun "$@"