microsoft/TypeAgent

Public

mirrored fromhttps://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
8ba3ebd84dd1bb6343ebae028996313cabd70764

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

ts/tools/scripts/install-shell.sh

165lines · modecode

1#!/bin/bash
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4
5function download_yml() {
6 info "Downloading $1"
7 az storage blob download --account-name $STORAGE --container-name $CONTAINER --name $1 --file $DEST/$1 --overwrite --auth-mode login > $DEST/install-shell.log 2>&1
8 if [[ $? != 0 ]]; then
9 error "Failed to download $1 from $STORAGE/$CONTAINER"
10 error "Ensure you that you are logged into azure cli with 'az login' and have access to the storage account."
11 cat $DEST/install-shell.log
12 return 1
13 fi
14 return 0
15}
16
17function download_package() {
18 info "Downloading $1"
19 az storage blob download --account-name $STORAGE --container-name $CONTAINER --name "$1" --file "$DEST/$1" --overwrite --auth-mode login > $DEST/install-shell.log 2>&1
20 if [[ $? != 0 ]]; then
21 error "Failed to download $1 from $STORAGE/$CONTAINER."
22 cat $DEST/install-shell.log
23 return 1
24 fi
25 return 0
26}
27
28function install_package_linux() {
29 info "Installing $1"
30 sudo apt install -y "$DEST/$1" > $DEST/install-shell.log 2>&1
31 if [[ $? != 0 ]]; then
32 error "Failed to install $1"
33 cat $DEST/install-shell.log
34 return 1
35 fi
36 typeagentshell
37 success "$1 installed successfully."
38 success "TypeAgent Shell will start automatically."
39
40}
41
42function install_package_mac() {
43 info "Installing $1"
44 unzip -o "$DEST/$1" -d "/Applications" > $DEST/install-shell.log 2>&1
45 if [[ $? != 0 ]]; then
46 error "Failed to install $1"
47 cat $DEST/install-shell.log
48 return 1
49 fi
50 open /Applications/TypeAgent\ Shell.app
51 success "$1 installed successfully."
52 success "TypeAgent Shell will start automatically."
53 return 0
54}
55
56function usage() {
57 echo Usage: $0 \<storage\> \[\<container\>\] \[\<channel\>\]
58 echo \ \ \<storage\>\ \ \ - The name of the storage account to use.
59 echo \ \ \<container\> - The name of the container to use. \<storage\> will be used if not specified.
60 echo \ \ \<channel\>\ \ \ - The channel to use. Default to 'lkg' if not specified.
61}
62
63function info() {
64 echo INFO: $*
65}
66
67function success() {
68 echo SUCCESS: $*
69}
70
71function error() (
72 echo ERROR: $*
73)
74
75function cleanup() {
76 info "Cleaning up..."
77 rm -rf $DEST > /dev/null 2>&1
78
79}
80
81if [[ "$1" == "" ]]; then
82 error No storage account specified.
83 usage
84 exit 1
85fi
86
87STORAGE=$1
88if [[ "$2" == "" ]]; then
89 CONTAINER=$1
90else
91 CONTAINER=$2
92fi
93
94if [[ "$3" == "" ]]; then
95 CHANNEL=lkg
96else
97 CHANNEL=$3
98fi
99
100ARCH=$(uname -m)
101if [[ "$ARCH" == "x86_64" ]]; then
102 ARCH=x64
103elif [[ "$ARCH" == "arm64" ]]; then
104 ARCH=arm64
105else
106 error "Unsupported architecture: $ARCH"
107 exit 1
108fi
109
110CHANNEL=$CHANNEL-$ARCH
111
112DEST=/tmp/install-shell
113cleanup
114mkdir -p $DEST > /dev/null 2>&1
115if [[ $? != 0 ]]; then
116 error "Failed to create $DEST directory."
117 exit 1
118fi
119
120if [[ $? != 0 ]]; then
121 error "Failed to delete files in $DEST directory."
122 exit 1
123fi
124
125if [[ "$OSTYPE" == "darwin"* ]]; then
126 # Mac OSX
127 YML=$CHANNEL-mac.yml
128else
129 # Linux
130 YML=$CHANNEL-linux.yml
131fi
132
133info "Getting TypeAgent Shell from $CHANNEL channel in $STORAGE/$CONTAINER."
134download_yml $YML
135if [[ $? != 0 ]]; then
136 cleanup
137 exit 1
138fi
139
140PACKAGE=$(cat $DEST/$YML | grep -i path | cut -d ':' -f 2)
141PACKAGE=${PACKAGE#"${PACKAGE%%[![:space:]]*}"}
142if [[ "$PACKAGE" == "" ]]; then
143 error "Failed to find path in $YML. Ensure that the file is valid."
144 cleanup
145 exit 1
146fi
147
148download_package "$PACKAGE"
149if [[ $? != 0 ]]; then
150 cleanup
151 exit 1
152fi
153
154if [[ "$OSTYPE" == "darwin"* ]]; then
155 # Mac OSX
156 install_package_mac "$PACKAGE"
157else
158 install_package_linux "$PACKAGE"
159fi
160if [[ $? != 0 ]]; then
161 cleanup
162 exit 1
163fi
164
165cleanup
166