Changeset View
Changeset View
Standalone View
Standalone View
plasmoid/contents/code/msm.sh
- This file was added.
1 | #!/bin/bash | ||||
---|---|---|---|---|---|
2 | | ||||
3 | # Copyright 2016 Mycroft AI, Inc. | ||||
4 | # | ||||
5 | # This file is part of Mycroft Core. | ||||
6 | # | ||||
7 | # Mycroft Core is free software: you can redistribute it and/or modify | ||||
8 | # it under the terms of the GNU General Public License as published by | ||||
9 | # the Free Software Foundation, either version 3 of the License, or | ||||
10 | # (at your option) any later version. | ||||
11 | # | ||||
12 | # Mycroft Core is distributed in the hope that it will be useful, | ||||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | # GNU General Public License for more details. | ||||
16 | # | ||||
17 | # You should have received a copy of the GNU General Public License | ||||
18 | # along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | | ||||
20 | | ||||
21 | # @author Augusto Monteiro | ||||
22 | # | ||||
23 | # This script assists in the installation and management of | ||||
24 | # skills loaded from Github. | ||||
25 | | ||||
26 | mycroft_skill_folder="/opt/mycroft/skills" | ||||
27 | mycroft_virtualenv=~/.virtualenvs/mycroft/bin/activate | ||||
28 | | ||||
29 | echo "####### Mycroft Skill Manager #######" | ||||
30 | | ||||
31 | function help() { | ||||
32 | echo "msm: Mycroft Skill Manager" | ||||
33 | echo -e " Copyright (c) 2017 Mycroft AI, Inc. All rights reserved.\n" | ||||
34 | echo "usage: msm install <repository> or <name>" | ||||
35 | echo " Installs the given Skill into the /opt/mycroft/skills directory" | ||||
36 | echo " where <repository> is the address of the skill in Github." | ||||
37 | echo -e "example: msm install https://github.com/ethanaward/demo_skill.git\n" | ||||
38 | } | ||||
39 | | ||||
40 | function install() { | ||||
41 | cd $mycroft_skill_folder | ||||
42 | if [ -z "$2" ]; then | ||||
43 | echo "You must pass the git url or skill name" | ||||
44 | exit 1 | ||||
45 | fi | ||||
46 | if [[ "$2" == "git@"* || "$2" == "https://"* || "$2" == "http://"* ]]; then | ||||
47 | repo=$2 | ||||
48 | else | ||||
49 | skill_list="`curl -s "https://raw.githubusercontent.com/MycroftAI/mycroft-skills/master/.gitmodules"`" | ||||
50 | skills=`echo "$skill_list" | grep -n 'submodule' | sed 's/[[:space:]]//g' | sed 's/\[submodule"//g' | sed 's/"\]//g'` | ||||
51 | exact_match=`echo "$skills" | grep -i ".*:$2$"` | ||||
52 | skill=`echo "$skills" | grep -i ".*:.*$2.*"` | ||||
53 | if [ ! -z $exact_match ]; then | ||||
54 | skill=$exact_match | ||||
55 | fi | ||||
56 | git_line=`echo "$skill" | sed 's/\:.*//'` | ||||
57 | | ||||
58 | if [[ $skill == *$'\n'* ]]; then | ||||
59 | echo -e "Your search has multiple choices\n\n$skill" | sed 's/.*://g' | ||||
60 | exit 2 | ||||
61 | else | ||||
62 | if [ -z $git_line ]; then | ||||
63 | echo "Skill not found" | ||||
64 | exit 3 | ||||
65 | fi | ||||
66 | repo_line=$(($git_line + 2)) | ||||
67 | repo=`echo "$skill_list" | sed -n $repo_line'{p;q;}' | sed 's/[[:space:]]//g' | sed 's/url=//g'` | ||||
68 | fi | ||||
69 | fi | ||||
70 | git_name=`echo "$repo" | sed 's/.*\///'` | ||||
71 | name=`echo "$git_name" | sed 's/.git//'` | ||||
72 | echo "Cloning repository" | ||||
73 | git clone $repo >> /dev/null | ||||
74 | cd $name | ||||
75 | if [ -f "requirements.txt" ]; then | ||||
76 | echo "Installing libraries requirements" | ||||
77 | pip install -r requirements.txt | ||||
78 | fi | ||||
79 | echo "Skill installed!" | ||||
80 | } | ||||
81 | | ||||
82 | function update() { | ||||
83 | cd $mycroft_skill_folder | ||||
84 | for d in *; do | ||||
85 | if git -C "$d" rev-parse --git-dir > /dev/null 2>&1; then | ||||
86 | cd $d | ||||
87 | git fetch | ||||
88 | git reset --hard origin/master | ||||
89 | cd .. | ||||
90 | fi | ||||
91 | done | ||||
92 | } | ||||
93 | | ||||
94 | function install_defaults() { | ||||
95 | skills=( "alarm" "audio-record" "configuration" "date-time" "desktop-launcher" "ip" "joke" "hello-world" "media" "npr-news" "naptime" "pairing" "personal" "reminder" "installer" "speak" "spelling" "stop" "stock" "volume" "weather" "wiki" "wolfram-alpha" ) | ||||
96 | for i in "${skills[@]}" | ||||
97 | do | ||||
98 | if [ ! -d "$mycroft_skill_folder/skill-$i" ]; then | ||||
99 | install "" "https://github.com/MycroftAI/skill-$i.git" | ||||
100 | fi | ||||
101 | done | ||||
102 | update | ||||
103 | echo "Installed!" | ||||
104 | } | ||||
105 | | ||||
106 | function list() { | ||||
107 | curl -s "https://raw.githubusercontent.com/MycroftAI/mycroft-skills/master/.gitmodules" | grep 'submodule "' | sed 's/\[submodule "//g'| sed 's/"\]//g' | ||||
108 | } | ||||
109 | | ||||
110 | if [ "$1" = "install" ]; then | ||||
111 | install $* | ||||
112 | elif [ "$1" = "list" ]; then | ||||
113 | echo -e "Searching...\n" | ||||
114 | list | ||||
115 | elif [ "$1" = "update" ]; then | ||||
116 | update | ||||
117 | elif [ "$1" = "default" ]; then | ||||
118 | install_defaults | ||||
119 | else | ||||
120 | help | ||||
121 | fi | ||||
122 | |