Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Rename update.sh to updater #246

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
70f2bdb
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
f965e69
Rename update.sh to updater
sai-kiran-y Jun 11, 2023
c0f79ce
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
f3bd9fc
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
da0692e
Update README.md
sai-kiran-y Jun 11, 2023
93ebd20
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
7c90a9c
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
c7ccd9c
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
15f3f0b
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
687c958
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
fd4784a
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
efdecd9
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
ffbd024
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
3af6b12
fix: Rename update.sh to updater
sai-kiran-y Jun 11, 2023
7a3ee44
Rename startup.sh to check_root_part.sh
sai-kiran-y Jun 13, 2023
24a260f
Update one_time_setup.sh
sai-kiran-y Jun 13, 2023
edc2fe7
fix: Update and rename startup.service to check-root-partition.service
sai-kiran-y Jun 13, 2023
d217600
fix: Update one_time_setup.sh
sai-kiran-y Jun 13, 2023
46b9135
fix: Rename startup.sh to check_root_part.sh
sai-kiran-y Jun 13, 2023
d8190a6
Update one_time_setup.sh
sai-kiran-y Jun 13, 2023
e6ad60e
Update one_time_setup.sh
sai-kiran-y Jun 13, 2023
765e003
Update one_time_setup.sh
sai-kiran-y Jun 13, 2023
1a07a75
Update one_time_setup.sh
sai-kiran-y Jun 13, 2023
4bd338f
Update one_time_setup.sh
sai-kiran-y Jun 13, 2023
7bbcd89
fix: Change persistence path to download partition
sai-kiran-y Jun 21, 2023
8bd217a
fix: Edit Download links for testing
sai-kiran-y Jun 21, 2023
5750255
Update make_firmware_update.sh
sai-kiran-y Jun 21, 2023
93fc42e
Update make_firmware_update.sh
sai-kiran-y Jun 21, 2023
a0fc832
Merge branch 'bytebeamio:main' into main
sai-kiran-y Jul 19, 2023
f368b2f
fix: Add config update logic
sai-kiran-y Jul 22, 2023
d65b453
fix: Add config update logic
sai-kiran-y Jul 22, 2023
5472038
fix: update_config action added
sai-kiran-y Jul 22, 2023
48587b1
fix: Add reboot action logic
sai-kiran-y Jul 24, 2023
d594fff
Merge pull request #1 from sai-kiran-y/test-rpi
sai-kiran-y Aug 7, 2023
72a690d
Merge branch 'main' of https://github.com/sai-kiran-y/uplink into main
sai-kiran-y Aug 7, 2023
f75e2e1
fix: remove serial dependency
sai-kiran-y Aug 7, 2023
7d842dc
fix: remove rumqttc dependency
sai-kiran-y Aug 7, 2023
e9fc1ba
fix: remove tunshell dependency
sai-kiran-y Aug 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[patch.crates-io]
serial = { git = "https://github.com/bytebeamio/serial-rs", branch = "android_fix" }

[workspace]
members = [
Expand Down
2 changes: 1 addition & 1 deletion examples/rpi/updates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Uploading the update to Bytebeam Cloud
From the Bytebeam cloud, updates can be easily installed in few simple steps.
The update file is typically a tar archive(update.tar.gz) with a script(called update.sh) and
The update file is typically a tar archive(update.tar.gz) with a script(called updater) and
other files.
These are the types of updates that are currently supported.
* [**app_update**](app_update/) - Installs the application binary to the specified location
Expand Down
14 changes: 7 additions & 7 deletions examples/rpi/updates/app_update/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# App Update

App update basically replaces the existing binary on the system with the
binary uploaded on the Bytebeam cloud. In this example, it is assumed that
the app is part of systemd. The app basically prints the string "Hello from Bytebeam" every 3 seconds.
binary uploaded on the Bytebeam cloud. In this example, the app is expected to be part of systemd.
The app basically prints the string "Hello from Bytebeam" every 3 seconds.
[app_update.sh](app_update.sh) has the logic of replacing the old app, with the new one.
By default the app is assumed to be in the folder /usr/local/bin. This is configurable in update.sh script.

## update.sh
[update.sh](update.sh) is the wrapper script for app_update script. Using update.sh
script we can configure several parameters such as
## updater
[updater](updater) is the wrapper script for app_update script. Using updater,
we can configure several parameters such as
* Port number
* App name
* App path - Path where the app is expected to be installed
* install_ab - Whether the app needs to be installed on both the partitions

## Create app update
make_firmware_update.sh script creates the [app_update](app_update.tar.gz) tar file
which has the new application, update.sh and app_update.sh scripts. The app_update.tar.gz
which has the new application, updater and app_update.sh scripts. The app_update.tar.gz
file is to be uploaded to the "Firmware Update" section of Bytebeam cloud. Once the OTA
update is triggered, the tar is downloaded to the device and update.sh is run, which
update is triggered, the tar is downloaded to the device and updater is run, which
inturn calls app_update.sh with appropriate parameters.

## Status of the update
Expand Down
2 changes: 1 addition & 1 deletion examples/rpi/updates/app_update/make_firmware_update.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

tar -cf app_update.tar.gz app app_update.sh update.sh
tar -cf app_update.tar.gz app app_update.sh updater
14 changes: 7 additions & 7 deletions examples/rpi/updates/app_update_rollback/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# App update with rollback feature

This update basically replaces the existing binary on the system with the
binary uploaded on the Bytebeam cloud. In this example, it is assumed that
the app is part of systemd. The app basically prints the string "Hello from Bytebeam"
binary uploaded on the Bytebeam cloud. In this example,the app is expected
to be part of systemd. The app basically prints the string "Hello from Bytebeam"
every 3 seconds. [app_update_rollback.sh](app_update_rollback.sh) has the logic of
replacing the old app, with the new one. By default the app is assumed to be in the
folder /usr/local/bin. This is configurable in update.sh script. If the new app doesn't
folder /usr/local/bin. This is configurable in updater script. If the new app doesn't
work as expected, it is replaced with the older working version of the app.

## update.sh
[update.sh](update.sh) is the wrapper script for app_update_rollback script. Using update.sh
## updater
[updater](updater) is the wrapper script for app_update_rollback script. Using updater
script we can configure several parameters such as
* Port number
* App name
Expand All @@ -18,9 +18,9 @@ script we can configure several parameters such as

## Create app update
make_firmware_update.sh script creates the [app_update_rollback](app_update_rollback.tar.gz) tar file
which has the new application, update.sh and app_update_rollback.sh scripts. The app_update_rollback.tar.gz
which has the new application, updater and app_update_rollback.sh scripts. The app_update_rollback.tar.gz
file is to be uploaded to the "Firmware Update" section of Bytebeam cloud. Once the OTA
update is triggered, the tar is downloaded to the device and update.sh is run, which
update is triggered, the tar is downloaded to the device and updater is run, which
inturn calls app_update_rollback.sh with appropriate parameters.

## Status of the update
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

tar -cf app_update_rollback.tar.gz app app_update_rollback.sh update.sh
tar -cf app_update_rollback.tar.gz app app_update_rollback.sh updater
10 changes: 5 additions & 5 deletions examples/rpi/updates/deb_update/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ then deb_update is the right way do it. In this example, we try to install the a
package on the Raspberry Pi. [deb_update.sh](deb_update.sh) script has the logic of
installing a deb package.

## update.sh
[update.sh](update.sh) is the wrapper script for the deb_update.sh script. It calls
## updater
[updater](updater) is the wrapper script for the deb_update.sh script. It calls
the deb_update.sh script with parameters such as file path, port number and so on.
The update script and uplink communicate through this port specified.
The updater script and uplink communicate through this specified port.

## Create update file
All these files including the update.sh, deb_update.sh, deb package needs to be compressed
All these files including the updater, deb_update.sh, deb package needs to be compressed
in tar.gz format. Running make_firmware_update.sh script creates the deb_update.tar.gz file.
This can be uploaded as a new firmware on Bytebeam cloud.

## Status of the update
Once the OTA update is triggered on the cloud, the deb_update.tar.gz file is downloaded on
the device and it's contents are extracted and update.sh is run. This calls the deb_update
the device and it's contents are extracted and updater is run. This calls the deb_update
script with appropriate parameters. Once the deb package is installed, the status "Completed"
is sent to the cloud. In the Bytebeam cloud, this particular update will be marked as Completed.
2 changes: 1 addition & 1 deletion examples/rpi/updates/deb_update/make_firmware_update.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

tar -cf deb_update.tar.gz ./*.deb deb_update.sh update.sh
tar -cf deb_update.tar.gz ./*.deb deb_update.sh updater
6 changes: 3 additions & 3 deletions examples/rpi/updates/rootfs_update/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
This is used in situations, where one needs to update the entire system, including the
rootfs, kernel and firmware files. A typical way of doing this would be to take the
raspian image that you want the system to be updated to and create the tar of the image,
update.sh and rootfs_update.sh script.
updater and rootfs_update.sh script.

## Create the rootfs update tar file
The script make_firmware_update.sh creates the tar file rootfs_update.tar.gz from the
new image, update.sh and rootfs_update.sh scripts
new image, updater and rootfs_update.sh scripts

## Uploading to the Bytebeam cloud
Upload the file rootfs_update.tar.gz in the "Update Firmware" section of the Bytebeam
cloud. Once the OTA update is triggered, the file rootfs_update.tar.gz is downloaded to
the device and its contents are extracted. Then update.sh script is run, which inturn
the device and its contents are extracted. Then updater script is run, which inturn
calls rootfs_update.sh with appropriate parameters. Note that update.sh is like a wrapper
script to rootfs_update.sh

Expand Down
2 changes: 1 addition & 1 deletion examples/rpi/updates/rootfs_update/make_firmware_update.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

tar -cf rootfs_update.tar.gz ./*.tar.gz update.sh rootfs_update.sh
tar -cf rootfs_update.tar.gz ./*.tar.gz updater rootfs_update.sh
12 changes: 6 additions & 6 deletions examples/rpi/updates/rootfs_update/rootfs_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ then
fi
ln -s /mnt/next_root/etc/systemd/system/uplink.service /mnt/next_root/etc/systemd/system/multi-user.target.wants/uplink.service

# Add startup script to systemd
# startup script checks if:
# Add check_root_part script to systemd
# This script checks if:
# system booted to correct partition
# uplink is running as expected
cp /mnt/download/systemd/startup.service /mnt/next_root/etc/systemd/system/
if [ -f /mnt/next_root/etc/systemd/system/multi-user.target.wants/startup.service ]
cp /mnt/download/systemd/check-root-partition.service /mnt/next_root/etc/systemd/system/
if [ -f /mnt/next_root/etc/systemd/system/multi-user.target.wants/check-root-partition.service ]
then
unlink /mnt/next_root/etc/systemd/system/multi-user.target.wants/startup.service
unlink /mnt/next_root/etc/systemd/system/multi-user.target.wants/check-root-partition.service
fi
ln -s /mnt/next_root/etc/systemd/system/startup.service /mnt/next_root/etc/systemd/system/multi-user.target.wants/startup.service
ln -s /mnt/next_root/etc/systemd/system/check-root-partition.service /mnt/next_root/etc/systemd/system/multi-user.target.wants/check-root-partition.service
echo "{ \"stream\": \"action_status\", \"sequence\": 0, \"timestamp\": $(date +%s%3N), \"action_id\": \"$1\", \"state\": \"Completed\", \"progress\": 75, \"errors\": [] }" >&"${COPROC[1]}"

# Copy uplink binary and config.toml to /usr/local/share/bytebeam folder of next rootfs
Expand Down
File renamed without changes.
35 changes: 32 additions & 3 deletions scripts/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def recv_action(s):
# Constructs a payload and sends it over TCP to uplink
def send_data(s, payload):
send = json.dumps(payload) + "\n"
print(bytes(send, encoding="utf-8"))
s.sendall(bytes(send, encoding="utf-8"))

# Constructs a JSON `action_status` as a response to received action on completion
Expand All @@ -43,6 +44,19 @@ def action_failed(id, reason):
"errors": [reason]
}

def update_config(action):
payload = json.loads(action['payload'])
print(payload)
app = payload["name"]
print(app)
ver = payload["version"]
print(ver)
if(ver == "latest"):
cmd = "sudo apt update && sudo apt install " + app
print(cmd)
resp = action_complete(action["action_id"])
print(resp)
send_data(s, resp)

def update_firmware(action_id, payload_json):
payload = json.loads(payload_json)
Expand Down Expand Up @@ -112,6 +126,15 @@ def update_firmware(action_id, payload_json):
return action_failed(action_id, "Could not find the script, reboot.sh")
return action_complete(action_id)

# Reboots the device
def reboot(action):
payload = json.loads(action['payload'])
print(payload)
resp = action_complete(action["action_id"])
print(resp)
send_data(s, resp)
os.system('sudo reboot')

def recv_actions():
while True:
action = recv_action(s)
Expand All @@ -120,14 +143,20 @@ def recv_actions():
action_name = action["name"]
action_id = action["action_id"]
action_payload = action["payload"]

resp = action_failed(action_id, "Action {name} does not exist".format(name=action_name))

#resp = action_failed(action_id, "Action {name} does not exist".format(name=action_name))
try:
if action_name == "update_firmware":
print("update_firmware action received")
resp = update_firmware(action_id, action_payload)
elif action_name == "send_file":
resp = action_complete(action_id)
elif action_name == "update_config":
print("update_config action received")
print(json.loads(action['payload']))
update_config(action)
elif action_name == "reboot":
print("reboot action received")
reboot(action)
except Exception as e:
print(e)
resp = action_failed(action_id, "Failed with exception: {msg}".format(msg=str(e)))
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions scripts/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
persistence_path = "/tmp/uplink"
persistence_path = "/mnt/download/tmp/uplink"
action_redirections={update_firmware="install_firmware"}
[tcpapps.1]
port=5555
Expand All @@ -13,7 +13,7 @@ enabled=true
port=3333

[ota_installer]
path="/tmp/uplink/installer"
path="/mnt/download/tmp/uplink/installer"
actions=[{name="install_firmware", timeout=610}]
uplink_port=5555

Expand Down
32 changes: 17 additions & 15 deletions scripts/one_time_setup.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
# Getting one_time_setup.sh
# curl --proto '=https' --tlsv1.2 -sSf one_time_setup.sh https://raw.githubusercontent.com/bytebeamio/uplink/main/examples/rpi/one_time_setup.sh | bash
# curl --proto '=https' --tlsv1.2 -sSf one_time_setup.sh https://raw.githubusercontent.com/sai-kiran-y/uplink/test-rpi/examples/rpi/one_time_setup.sh | bash

# get update_fstab.sh
curl --proto '=https' --tlsv1.2 -sSf -o update_fstab.sh https://raw.githubusercontent.com/bytebeamio/uplink/main/scripts/update_fstab.sh
curl --proto '=https' --tlsv1.2 -sSf -o update_fstab.sh https://raw.githubusercontent.com/sai-kiran-y/uplink/test-rpi/scripts/update_fstab.sh
chmod +x ./update_fstab.sh
./update_fstab.sh
mount -a
cp update_fstab.sh /mnt/download/

# get update_fstab_next_root
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/update_fstab_next_root.sh https://raw.githubusercontent.com/bytebeamio/uplink/main/scripts/update_fstab_next_root.sh
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/update_fstab_next_root.sh https://raw.githubusercontent.com/sai-kiran-y/uplink/test-rpi/scripts/update_fstab_next_root.sh

# get uplink binary
curl --proto '=https' --tlsv1.2 -sSfL -o /usr/local/share/bytebeam/uplink https://github.com/bytebeamio/uplink/releases/download/v2.4.0/uplink-aarch64-unknown-linux-gnu
curl --proto '=https' --tlsv1.2 -sSfL -o /usr/local/share/bytebeam/uplink https://github.com/bytebeamio/uplink/releases/download/v2.5.0/uplink-aarch64-unknown-linux-gnu

# get systemd script
mkdir -pv /mnt/download/systemd
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/systemd/systemd.sh https://raw.githubusercontent.com/bytebeamio/uplink/main/scripts/systemd/systemd.sh
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/systemd/systemd.sh https://raw.githubusercontent.com/sai-kiran-y/uplink/test-rpi/scripts/systemd/systemd.sh

# get uplink.service
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/systemd/uplink.service https://raw.githubusercontent.com/bytebeamio/uplink/main/scripts/systemd/uplink.service
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/systemd/uplink.service https://raw.githubusercontent.com/sai-kiran-y/uplink/test-rpi/scripts/systemd/uplink.service

# get startup.service
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/systemd/startup.service https://raw.githubusercontent.com/bytebeamio/uplink/main/scripts/systemd/startup.service
# get check-root-partition.service
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/systemd/check-root-partition.service https://raw.githubusercontent.com/sai-kiran-y/uplink/test-rpi/scripts/systemd/check-root-partition.service

# get config.toml
curl --proto '=https' --tlsv1.2 -sSf -o /usr/local/share/bytebeam/config.toml https://raw.githubusercontent.com/bytebeamio/uplink/main/scripts/config.toml
curl --proto '=https' --tlsv1.2 -sSf -o /usr/local/share/bytebeam/config.toml https://raw.githubusercontent.com/sai-kiran-y/uplink/test-rpi/scripts/config.toml

# get reboot.sh
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/reboot.sh https://raw.githubusercontent.com/bytebeamio/uplink/main/scripts/reboot.sh
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/reboot.sh https://raw.githubusercontent.com/sai-kiran-y/uplink/test-rpi/scripts/reboot.sh

# get run_uplink.sh script
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/run_uplink.sh https://raw.githubusercontent.com/bytebeamio/uplink/main/scripts/run_uplink.sh
# curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/run_uplink.sh https://raw.githubusercontent.com/sai-kiran-y/uplink/test-rpi/scripts/run_uplink.sh

# get startup.sh
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/startup.sh https://raw.githubusercontent.com/bytebeamio/uplink/main/scripts/startup.sh
# get check_root_part.sh
curl --proto '=https' --tlsv1.2 -sSf -o /mnt/download/check_root_part.sh https://raw.githubusercontent.com/sai-kiran-y/uplink/test-rpi/scripts/check_root_part.sh

# Install netcat and vim
sudo apt install vim -y
sudo apt install netcat -y

# Make uplink executable
chmod +x /usr/local/share/bytebeam/uplink
chmod +x /mnt/download/startup.sh
chmod +x /mnt/download/check_root_part.sh

cp /mnt/download/systemd/uplink.service /etc/systemd/system/
cp /mnt/download/systemd/startup.service /etc/systemd/system/
cp /mnt/download/systemd/check-root-partition.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable check-root-partition.service
systemctl start check-root-partition.service

touch /boot/two
touch /mnt/download/two
Expand Down
12 changes: 12 additions & 0 deletions scripts/systemd/check-root-partition.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Bytebeam Root Partition Check Service
After=network.target auditd.service uplink.service

[Service]
ExecStart=/mnt/download/check_root_part.sh
KillMode=process
Restart=on-failure
Type=simple

[Install]
WantedBy=multi-user.target
12 changes: 0 additions & 12 deletions scripts/systemd/startup.service

This file was deleted.

6 changes: 3 additions & 3 deletions uplink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ tokio-util = { version = "0.7", features = ["codec", "time"] }
tokio-stream = "0.1"
tokio-compat-02 = "0.2.0"
flume = "0.10"
rumqttc = { git = "https://github.com/bytebeamio/rumqtt" }
#rumqttc = { git = "https://github.com/bytebeamio/rumqtt" }
bytes = "1"
serde = { version = "1", features = ["derive"] }
thiserror = "1"
anyhow = "1"
serde_json = "1.0"
rand = "0.8"
tunshell-client = { git = "https://github.com/bytebeamio/tunshell.git", branch = "android_patch" }
#tunshell-client = { git = "https://github.com/bytebeamio/tunshell.git", branch = "android_patch" }
reqwest = { version = "0.11", default-features = false, features = ["stream", "rustls-tls"] }
futures-util = "0.3"
async-trait = "0.1"
Expand All @@ -45,4 +45,4 @@ surge-ping = "0.8"
vergen = { version = "7", features = ["git", "build", "time"] }

[dev-dependencies]
tempdir = "0.3"
tempdir = "0.3"