-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into satheshantanu-patch-1
- Loading branch information
Showing
42 changed files
with
1,975 additions
and
236 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
old-schema-job-docs-and-handlers/old-schema-job-docs/download-file.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"_comment": "This sample JSON file can be used for downloading specific file from cloud storage. The arguments passed here in `args` are valid file URL and path where we want to store the downloaded file on the device.", | ||
"operation": "download-file.sh", | ||
"args": ["https://github.com/awslabs/aws-iot-device-client/archive/refs/tags/v1.3.tar.gz", "/tmp/Downloaded_File.tar.gz"], | ||
"path": "default" | ||
} |
4 changes: 4 additions & 0 deletions
4
old-schema-job-docs-and-handlers/old-schema-job-docs/echo.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"operation": "echo", | ||
"args": ["\"Hello world!\""] | ||
} |
6 changes: 6 additions & 0 deletions
6
old-schema-job-docs-and-handlers/old-schema-job-docs/install-packages.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"operation": "install-packages.sh", | ||
"args": ["lftp", "dos2unix"], | ||
"path": "default", | ||
"allowStdErr": 2 | ||
} |
5 changes: 5 additions & 0 deletions
5
old-schema-job-docs-and-handlers/old-schema-job-docs/remove-packages.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"operation": "remove-packages.sh", | ||
"args": ["lftp", "dos2unix"], | ||
"path": "default" | ||
} |
17 changes: 17 additions & 0 deletions
17
old-schema-job-docs-and-handlers/old-schema-job-handlers/download-file.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
echo "Running download-file.sh" | ||
if command -v "wget" > /dev/null | ||
then | ||
echo "Using wget for downloading user specified file" | ||
if command -v "sudo" > /dev/null; then | ||
sudo -n wget --quiet -O "$2" "$1" | ||
else | ||
echo "WARNING: sudo command not found" | ||
wget --quiet -O --quiet "$2" "$1" | ||
fi | ||
else | ||
>&2 echo "Wget software package not installed on the device. Use the \"install-packages.sh\" operation to install the wget software package on this device." | ||
exit 1 | ||
fi |
28 changes: 28 additions & 0 deletions
28
old-schema-job-docs-and-handlers/old-schema-job-handlers/install-packages.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
echo "Running install-packages.sh" | ||
if command -v "apt-get" > /dev/null | ||
then | ||
echo "Using apt-get for package install" | ||
# Squash any issues related to debconf frontend | ||
export DEBIAN_FRONTEND=noninteractive | ||
if command -v "sudo" > /dev/null; then | ||
sudo -n apt-get install -y "$@" | ||
else | ||
echo "WARNING: sudo command not found" | ||
apt-get install -y "$@" | ||
fi | ||
elif command -v "yum" > /dev/null | ||
then | ||
echo "Using yum for package install" | ||
if command -v "sudo" > /dev/null; then | ||
sudo -n yum install -y "$@" | ||
else | ||
echo "WARNING: sudo command not found" | ||
yum install -y "$@" | ||
fi | ||
else | ||
>&2 echo "No suitable package manager found" | ||
exit 1 | ||
fi |
30 changes: 30 additions & 0 deletions
30
old-schema-job-docs-and-handlers/old-schema-job-handlers/reboot.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
GLOBAL_LAST_BOOT="" | ||
REBOOT_LOCK_FILE=/var/tmp/dc-reboot.lock | ||
|
||
get_last_boot_time() { | ||
# Calculate exact time of last boot | ||
UPTIME=$(cat /proc/uptime | head -n1 | awk '{print $1;}') | ||
CURRENT=$(date "+%s") | ||
GLOBAL_LAST_BOOT=$(awk -v currentTime=$CURRENT -v uptime=$UPTIME 'BEGIN {printf "%.0f",currentTime-uptime}') | ||
} | ||
|
||
if sudo -n test -f "$REBOOT_LOCK_FILE"; then | ||
echo "Found lock file" | ||
LOCK_FILE_BOOT=$(cat $REBOOT_LOCK_FILE) | ||
rm $REBOOT_LOCK_FILE | ||
get_last_boot_time | ||
if [ "$LOCK_FILE_BOOT" -lt "$GLOBAL_LAST_BOOT" ]; then | ||
echo "Reboot was successful" | ||
exit 0 | ||
else | ||
echo "Reboot failed" | ||
exit 1 | ||
fi | ||
else | ||
echo "Did not find $REBOOT_LOCK_FILE" | ||
date "+%s" > $REBOOT_LOCK_FILE | ||
sudo -n reboot | ||
fi |
20 changes: 20 additions & 0 deletions
20
old-schema-job-docs-and-handlers/old-schema-job-handlers/remove-packages.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
if command -v "apt-get" > /dev/null | ||
then | ||
if command -v "sudo" > /dev/null; then | ||
sudo -n apt-get remove -y --purge "$@" | ||
else | ||
echo "WARNING: sudo command not found" | ||
apt-get remove -y --purge "$@" | ||
fi | ||
elif command -v "yum" > /dev/null; then | ||
if command -v "sudo" > /dev/null; then | ||
sudo -n yum remove -y "$@" | ||
else | ||
echo "WARNING: sudo command not found" | ||
yum remove -y "$@" | ||
fi | ||
else | ||
>&2 echo "No suitable package manager found" | ||
exit 1 | ||
fi |
17 changes: 17 additions & 0 deletions
17
old-schema-job-docs-and-handlers/old-schema-job-handlers/restart-services.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
if command -v "systemctl" > /dev/null; | ||
then | ||
for service in "$@" | ||
do | ||
sudo -n systemctl restart "$service" | ||
done | ||
elif command -v "service" > /dev/null; | ||
then | ||
for service in "$@" | ||
do | ||
sudo -n service restart "$service" | ||
done | ||
else | ||
>&2 echo "No suitable package manager found" | ||
exit 1 | ||
fi |
4 changes: 4 additions & 0 deletions
4
old-schema-job-docs-and-handlers/old-schema-job-handlers/shutdown.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
set -e | ||
sudo -n shutdown -h +1 > /dev/null | ||
echo "System scheduled for shut down in one minute..." |
14 changes: 14 additions & 0 deletions
14
old-schema-job-docs-and-handlers/old-schema-job-handlers/start-services.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
if command -v "systemctl" > /dev/null; | ||
then | ||
for service in "$@" | ||
do | ||
sudo -n systemctl start "$service" | ||
done | ||
elif command -v "service" > /dev/null; | ||
then | ||
for service in "$@" | ||
do | ||
sudo -n service start "$service" | ||
done | ||
fi |
14 changes: 14 additions & 0 deletions
14
old-schema-job-docs-and-handlers/old-schema-job-handlers/stop-services.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
if command -v "systemctl" > /dev/null; | ||
then | ||
for service in "$@" | ||
do | ||
sudo -n systemctl stop "$service" | ||
done | ||
elif command -v "service" > /dev/null; | ||
then | ||
for service in "$@" | ||
do | ||
sudo -n service stop "$service" | ||
done | ||
fi |
12 changes: 12 additions & 0 deletions
12
old-schema-job-docs-and-handlers/old-schema-job-handlers/verify-packages-installed.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
|
||
if command -v "rpm" > /dev/null; then | ||
rpm -q $1 | ||
elif command -v "dpkg" > /dev/null; then | ||
# Using -s flag instead of -l for dpkg based on https://github.com/bitrise-io/bitrise/issues/433 | ||
dpkg -s $1 | ||
else | ||
>&2 echo "No suitable package manager found" | ||
exit 1 | ||
fi; |
26 changes: 26 additions & 0 deletions
26
old-schema-job-docs-and-handlers/old-schema-job-handlers/verify-packages-removed.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
if command -v "rpm" > /dev/null; then | ||
for package in "$@" | ||
do | ||
rpm -q $1 | ||
RETVAL=$? | ||
if [ $RETVAL -eq 0 ]; then | ||
exit 1 | ||
fi | ||
done | ||
elif command -v "dpkg" > /dev/null; then | ||
for package in "$@" | ||
do | ||
# Using -s flag instead of -l for dpkg based on https://github.com/bitrise-io/bitrise/issues/433 | ||
dpkg -s "$package" | ||
RETVAL=$? | ||
if [ $RETVAL -eq 0 ]; then | ||
exit 1 | ||
fi | ||
done | ||
else | ||
>&2 echo "No suitable method found to determine installed packages" | ||
exit 1 | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
{ | ||
"_comment": "This sample JSON file can be used for downloading specific file from cloud storage. The arguments passed here in `args` are valid file URL and path where we want to store the downloaded file on the device.", | ||
"operation": "download-file.sh", | ||
"args": ["https://github.com/awslabs/aws-iot-device-client/archive/refs/tags/v1.3.tar.gz", "/tmp/Downloaded_File.tar.gz"], | ||
"path": "default" | ||
"_comment": "This sample JSON file can be used for downloading specific file from cloud storage. The arguments passed here in `steps`->`action`->`args` are valid file URL and path where we want to store the downloaded file on the device.", | ||
"version": "1.0", | ||
"steps": [ | ||
{ | ||
"action": { | ||
"name": "Download File", | ||
"type": "runHandler", | ||
"input": { | ||
"handler": "download-file.sh", | ||
"args": [ | ||
"https://github.com/awslabs/aws-iot-device-client/archive/refs/tags/v1.3.tar.gz", | ||
"/tmp/Downloaded_File.tar.gz" | ||
], | ||
"path": "default" | ||
}, | ||
"runAsUser": "root" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
{ | ||
"operation": "echo", | ||
"args": ["\"Hello world!\""] | ||
"_comment": "This sample JSON file can be used for running the echo command on the device side.", | ||
"version": "1.0", | ||
"steps": [ | ||
{ | ||
"action": { | ||
"name": "Echo Messages", | ||
"type": "runHandler", | ||
"input": { | ||
"handler": "echo", | ||
"args": [ | ||
"Hello IoT World!" | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
{ | ||
"operation": "install-packages.sh", | ||
"args": ["lftp", "dos2unix"], | ||
"path": "default", | ||
"allowStdErr": 2 | ||
"_comment": "This sample JSON file can be used for installing specific list of packages on device. The arguments passed here in `steps`->`action`->`args` are valid package names.", | ||
"version": "1.0", | ||
"steps": [ | ||
{ | ||
"action": { | ||
"name": "Install Packages", | ||
"type": "runHandler", | ||
"input": { | ||
"handler": "install-packages.sh", | ||
"args": [ | ||
"lftp", | ||
"dos2unix" | ||
], | ||
"path": "default" | ||
}, | ||
"runAsUser": "root" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"_comment": "This sample JSON file can be used for rebooting the device.", | ||
"version": "1.0", | ||
"steps": [ | ||
{ | ||
"action": { | ||
"name": "Reboot Device", | ||
"type": "runHandler", | ||
"input": { | ||
"handler": "reboot.sh" | ||
}, | ||
"runAsUser": "root" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
{ | ||
"operation": "remove-packages.sh", | ||
"args": ["lftp", "dos2unix"], | ||
"path": "default" | ||
"_comment": "This sample JSON file can be used for removing specific list of packages from device. The arguments passed here in `steps`->`action`->`args` are valid package names.", | ||
"version": "1.0", | ||
"steps": [ | ||
{ | ||
"action": { | ||
"name": "Remove Packages", | ||
"type": "runHandler", | ||
"input": { | ||
"handler": "remove-packages.sh", | ||
"args": [ | ||
"lftp", | ||
"dos2unix" | ||
], | ||
"path": "default" | ||
}, | ||
"runAsUser": "root" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.