microsoft/TypeAgent

Public

mirrored from https://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
6cac91db301a0490a67baa382672cf6245329287

Branches

Tags

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

Clone

HTTPS

Download ZIP

ts/tools/scripts/install-shell.sh

144lines · 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 erorr "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() {
29 info "Installing $1"
30 unzip -o "$DEST/$1" -d "/Applications" > $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 open /Applications/TypeAgent\ Shell.app
37 success "$1 installed successfully."
38 success "TypeAgent Shell will start automatically."
39 return 0
40}
41
42function usage() {
43 echo Usage: $0 \<storage\> \[\<container\>\] \[\<channel\>\]
44 echo \ \ \<storage\>\ \ \ - The name of the storage account to use.
45 echo \ \ \<container\> - The name of the container to use. \<storage\> will be used if not specified.
46 echo \ \ \<channel\>\ \ \ - The channel to use. Default to 'lkg' if not specified.
47}
48
49function info() {
50 echo INFO: $*
51}
52
53function success() {
54 echo SUCCESS: $*
55}
56
57function error() (
58 echo ERROR: $*
59)
60
61function cleanup() {
62 rm -rf $DEST > /dev/null 2>&1
63}
64
65if [[ "$1" == "" ]]; then
66 error No storage account specified.
67 usage
68 exit 1
69fi
70
71STORAGE=$1
72if [[ "$2" == "" ]]; then
73 CONTAINER=$1
74else
75 CONTAINER=$2
76fi
77
78if [[ "$3" == "" ]]; then
79 CHANNEL=lkg
80else
81 CHANNEL=$3
82fi
83
84ARCH=$(uname -m)
85if [[ "$ARCH" == "x86_64" ]]; then
86 ARCH=x64
87elif [[ "$ARCH" == "arm64" ]]; then
88 ARCH=arm64
89else
90 error "Unsupported architecture: $ARCH"
91 exit 1
92fi
93
94CHANNEL=$CHANNEL-$ARCH
95
96DEST=/tmp/install-shell
97cleanup
98mkdir -p $DEST > /dev/null 2>&1
99if [[ $? != 0 ]]; then
100 error "Failed to create $DEST directory."
101 exit 1
102fi
103
104if [[ $? != 0 ]]; then
105 error "Failed to delete files in $DEST directory."
106 exit 1
107fi
108
109if [[ "$OSTYPE" == "darwin"* ]]; then
110 # Mac OSX
111 YML=$CHANNEL-mac.yml
112else
113 # Linux
114 YML=$CHANNEL-linux.yml
115fi
116
117info "Getting TypeAgent Shell from $CHANNEL channel in $STORAGE/$CONTAINER."
118download_yml $YML
119if [[ $? != 0 ]]; then
120 cleanup
121 exit 1
122fi
123
124PACKAGE=$(cat $DEST/$YML | grep -i path | cut -d ':' -f 2)
125PACKAGE=${PACKAGE#"${PACKAGE%%[![:space:]]*}"}
126if [[ "$PACKAGE" == "" ]]; then
127 error "Failed to find path in $YML. Ensure that the file is valid."
128 cleanup
129 exit 1
130fi
131
132download_package "$PACKAGE"
133if [[ $? != 0 ]]; then
134 cleanup
135 exit 1
136fi
137
138install_package "$PACKAGE"
139if [[ $? != 0 ]]; then
140 cleanup
141 exit 1
142fi
143
144cleanup
145