|
1 | 1 | #!/bin/sh
|
2 | 2 | #
|
3 |
| -echo "Installing bootstate ..." |
| 3 | + |
| 4 | +TARGET="$1" |
| 5 | +if [ -z "$TARGET" ]; then |
| 6 | + echo "Usage: $0 <TARGET>" |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | +echo "Installing mPower bootstate ... to $TARGET" |
| 11 | + |
| 12 | +WORK_DIR=`mktemp -d -p "$DIR"` |
| 13 | +SSH_PARAMS="-o PubkeyAcceptedKeyTypes=+ssh-rsa -o KexAlgorithms=+diffie-hellman-group1-sha1 -o HostKeyAlgorithms=+ssh-dss -o Ciphers=+aes256-cbc -o StrictHostKeyChecking=accept-new" |
| 14 | +SCP_PARAMS="$SSH_PARAMS" |
4 | 15 |
|
5 | 16 | scriptdir=/var/etc/persistent/bootstate
|
| 17 | +applyscript="$scriptdir/apply-bootstate.sh" |
| 18 | + |
| 19 | +ssh $SSH_PARAMS ubnt@$TARGET "mkdir -p $scriptdir" |
| 20 | +wget -q https://raw.githubusercontent.com/magcode/mpower-tools/master/bootstate/apply-bootstate.sh -O $WORK_DIR/apply-bootstate.sh |
| 21 | +scp $SCP_PARAMS $WORK_DIR/apply-bootstate.sh ubnt@$TARGET:$scriptdir |
| 22 | +ssh $SSH_PARAMS ubnt@$TARGET "chmod 755 $applyscript" |
6 | 23 |
|
7 |
| -mkdir -p $scriptdir |
8 | 24 | config="$scriptdir/bootstate.cfg"
|
9 |
| -applyscript="$scriptdir/apply-bootstate.sh" |
10 |
| -poststartscript="sleep 60; $applyscript" |
11 |
| -poststart=/etc/persistent/rc.poststart |
12 | 25 |
|
13 |
| -wget --no-check-certificate -q https://raw.githubusercontent.com/magcode/mpower-tools/master/bootstate/apply-bootstate.sh -O $applyscript |
14 |
| -chmod 775 $applyscript |
15 | 26 |
|
16 |
| -if [ ! -f $config ]; then |
17 |
| - echo "$config not found, creating it ..." |
18 |
| - export PORTS=`cat /etc/board.inc | grep feature_power | sed -e 's/.*\([0-9]\+\);/\1/'` |
19 |
| - touch $config |
| 27 | + |
| 28 | +if ssh $SSH_PARAMS ubnt@$TARGET "test -f '$config'" 2>/dev/null; then |
| 29 | + echo "$config exists, not touching" |
| 30 | +else |
| 31 | + PORTS=`ssh $SSH_PARAMS ubnt@$TARGET "cat /etc/board.inc | grep feature_power | sed -e 's/.*\([0-9]\+\);/\1/'" 2>/dev/null` |
| 32 | + echo "Found $PORTS ports" |
| 33 | + |
| 34 | + ssh $SSH_PARAMS ubnt@$TARGET "touch $config" |
20 | 35 | for i in $(seq $PORTS)
|
21 | 36 | do
|
22 |
| - echo "vpower.$i.relay=on" >> $config |
| 37 | + ssh $SSH_PARAMS ubnt@$TARGET "echo 'vpower.$i.relay=on' >> $config" |
23 | 38 | done
|
| 39 | + echo "Config file created: $config" |
24 | 40 | fi
|
25 | 41 |
|
26 |
| -if [ ! -f $poststart ]; then |
| 42 | + |
| 43 | + |
| 44 | +poststart=/etc/persistent/rc.poststart |
| 45 | +poststartscript="sleep 60; $applyscript" |
| 46 | + |
| 47 | + |
| 48 | +# create poststart file if not exists |
| 49 | + |
| 50 | +if ssh $SSH_PARAMS ubnt@$TARGET "test -f '$poststart'" 2>/dev/null; then |
| 51 | + echo "$poststart exists already" |
| 52 | +else |
27 | 53 | echo "$poststart not found, creating it ..."
|
28 |
| - touch $poststart |
29 |
| - echo "#!/bin/sh" >> $poststart |
30 |
| - chmod 755 $poststart |
| 54 | + ssh $SSH_PARAMS ubnt@$TARGET "echo '#!/bin/sh' >> $poststart" |
| 55 | + ssh $SSH_PARAMS ubnt@$TARGET "chmod 755 $poststart" |
31 | 56 | fi
|
32 | 57 |
|
33 |
| -if grep -q "$poststartscript" "$poststart"; then |
34 |
| - echo "Found $poststart entry. File will not be changed" |
| 58 | +# add entry to poststart file if not exists |
| 59 | +if ssh $SSH_PARAMS ubnt@$TARGET "grep -q '$poststartscript' '$poststart'" 2>/dev/null; then |
| 60 | + echo "Found startscript entry. File will not be changed" |
35 | 61 | else
|
36 |
| - echo "Adding start command to $poststart" |
37 |
| - echo -e "$poststartscript" >> $poststart |
| 62 | + echo "Adding start command to $poststart" |
| 63 | + ssh $SSH_PARAMS ubnt@$TARGET "echo -e '$poststartscript' >> $poststart" |
38 | 64 | fi
|
39 | 65 |
|
40 |
| -echo "Done!" |
41 |
| -cfgmtd -w -p /etc/ |
| 66 | +ssh $SSH_PARAMS ubnt@$TARGET "cfgmtd -w -p /etc/" |
| 67 | + |
42 | 68 | echo "Adapt your settings in '$config' and call '$applyscript' afterwards."
|
0 commit comments