-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·187 lines (151 loc) · 6.68 KB
/
setup
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# this is a sample script that can be called from reinstallMods
#
# CommonResources provides:
# code to determine if it was called from reinstallMods or manually from a command line
# code to insert the script into scriptsList
# code to control exitting the program or processing by reinstallMods
# or prompting the user
#
# functions to make it easier to install and remove modified files from Venus
#
# The SetupHelper package includes CommonResources
# and a script to reinstall programs after a Venus software update
# SetupHelper should be installed before running this script
#
# Refer to the SetupHelper ReadMe file for details.
#
# key segments are marked with ####
qmlDir=/opt/victronenergy/gui/qml
#### following lines incorporate SetupHelper utilities into this script
# Refer to the SetupHelper ReadMe file for details.
source "/data/SetupHelper/CommonResources"
# GitHub account info - fill in as appropriate
# to include this package in SetupHelper automatic updates
packageGitHubUser="mr-manuel"
packageGitHubBranch="venus-os_ngrok"
#### end of lines to include SetupHelper
#### running manually and OK to proceed - prompt for input
if [ $scriptAction == 'NONE' ] ; then
# display innitial message
echo
echo "The ngrok allows you to access a specified port from external,"
echo "like tcp/22 (SSH), tcp/80 (HTTP), tcp/1881 (Node-RED) and all others."
# prompt for standard actions (install, reinstall, uninstall, etc)
# include MORE_PROMPTS if additional prompts are needed for installation
# scriptAction is set to INSTALL for reinstalls and UNINSTALL for uninstalls
# function exits for quit action
# log display is handled in function and remains there for other actions
#standardActionPrompt 'MORE_PROMPTS'
standardActionPrompt
# If nonstandard action prompts are required, duplicate the standardActionPrompt code here
# and modify it as needed
#### prompt for additional parameters - do all prompting before starting any work
# if [ $scriptAction == 'NONE' ]; then
# echo
# echo "The widget:"
# echo " 1) does something"
# echo " 2) and something else"
# echo
# response=""
# while [ -z $response ] || ! ( [ $response == 'y' ] || [ $response == 'n' ] )
# do
# /bin/echo -n "Do you wish to install the widget? (y/n): "
# read response
# done
#
# #### save parameters in persistent storage for reinstall
# if [ $response == 'y' ]; then
# touch $setupOptionsDir/param1
# else
# rm -f $setupOptionsDir/param1
# fi
#
# # ask user for a value to be added to /Settings
# # typeset -i inverterPeakPower
# read -p "Enter value for Widget X: " param2
# echo $param2 > $setupOptionsDir/param2
# fi
#
# # next step is to install
# scriptAction='INSTALL'
fi
#### install code goes here
if [ $scriptAction == 'INSTALL' ] ; then
#### code to install/activate package goes here
# below is example code to set flags used for exiting
# sample calls to install the package files - original files are backed up for restore during uninstall
# updateActiveFile $venusDirectory/activeFile1
# copyToActiveFile $someDirectory/replacementFile2 $venusDirectory/activeFile2
logMessage "installing $packageName files"
updateActiveFile "$qmlDir/MbEditBoxAuthToken.qml"
updateActiveFile "$qmlDir/PageSettingsServices.qml"
updateActiveFile "$qmlDir/PageSettingsServicesNgrok.qml"
# sample code to create dBus settings
# dbus -y com.victronenergy.settings /Settings AddSettings\
# '%[{"path": "/category/paramA", "type":"int", "default":0},\
# {"path":"/category/paramB", "type":"float", "default":0},\
# {"path":"/category/paramC", "type":"float", "default":0},\
# {"path":"/category/paramD", "type":"float", "default":0}]' > /dev/null
# sample code to set dBus settings
# dbus -y com.victronenergy.settings /Settings/category/paramA SetValue $param2 > /dev/null
# revert to VisualItemModel if before v3.00~14 (v3.00~14 uses VisibleItemModel)
versionStringToNumber "v3.00~14"
if (( $venusVersionNumber < $versionNumber )); then
logMessage "replacing VisibleItemModel with VisualItemModel"
fileList="$qmlDir/MbEditBoxAuthToken.qml"
fileList+=" $qmlDir/PageSettingsServices.qml"
fileList+=" $qmlDir/PageSettingsServicesNgrok.qml"
for file in $fileList ; do
sed -i -e 's/VisibleItemModel/VisualItemModel/' "$file"
done
restartGui=true
fi
logMessage "Downloading ngrok and extracting it"
wget -O /tmp/ngrok-v3-stable-linux-arm.tgz https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-arm.tgz
tar xvzf /tmp/ngrok-v3-stable-linux-arm.tgz -C $scriptDir
chmod +x $scriptDir/ngrok
# check, if config file exists. If not copy it, if it exists in driver folder (e.g. after Venus OS update)
if [[ ! -f "/.config/ngrok/ngrok.yml" ]] && [[ -f "/data/venus-os_ngrok/ngrok.yml" ]]; then
if [[ ! -d "/.config/ngrok/ngrok.yml" ]]; then
mkdir -p /.config/ngrok
fi
cp /data/venus-os_ngrok/ngrok.yml /.config/ngrok/ngrok.yml
fi
# copy config file to driver folder (e.g. after plugin update)
if [[ -f "/.config/ngrok/ngrok.yml" ]] && [[ ! -f "/data/venus-os_ngrok/ngrok.yml" ]]; then
cp /.config/ngrok/ngrok.yml /data/venus-os_ngrok/ngrok.yml
fi
installService $packageName
logMessage "++ $packageName installed"
fi
# #### uninstalling - check scriptAction again
# if an install step failed package needs to be removed
if [ $scriptAction == 'UNINSTALL' ] ; then
#### code to uninstall and deactivate package goes here
# sample calls to restore files to stock
# restoreActiveFile $venusDirectory/activeFile1
# restoreActiveFile $venusDirectory/activeFile2
# restoreActiveFile $venusDirectory/activeFile3
restoreActiveFile "$qmlDir/MbEditBoxAuthToken.qml"
restoreActiveFile "$qmlDir/PageSettingsServices.qml"
restoreActiveFile "$qmlDir/PageSettingsServicesNgrok.qml"
# remove any dBus settings
# dbus -y com.victronenergy.settings /Settings RemoveSettings\
# '%["category/paramA", "category/paramB",\
# "category/paramC", "category/paramD"]' > /dev/null
removeService $packageName
logMessage "++ $packageName uninstalled"
fi
#### add code to restart apps and services here
# gui is handled in endScript so it's not necessary to restart it here
#if $restartAppsNeeded ; then
# echo restarting apps
# # killall foo # sample restart line(s)
# # svc -t "/service/bar"
#fi
if $filesUpdated ; then
restartGui=true
fi
# thats all folks - SCRIPT EXITS INSIDE THE FUNCTION
endScript