Skip to content

Commit

Permalink
Merge branch 'main' into satheshantanu-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshGandhi-AWS authored Nov 25, 2021
2 parents 9436ab8 + 1212ab2 commit 032aba3
Show file tree
Hide file tree
Showing 42 changed files with 1,975 additions and 236 deletions.
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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"operation": "echo",
"args": ["\"Hello world!\""]
}
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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"operation": "remove-packages.sh",
"args": ["lftp", "dos2unix"],
"path": "default"
}
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
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 old-schema-job-docs-and-handlers/old-schema-job-handlers/reboot.sh
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
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
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
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..."
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
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
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;
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

23 changes: 19 additions & 4 deletions sample-job-docs/download-file.json
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"
}
}
]
}
18 changes: 16 additions & 2 deletions sample-job-docs/echo.json
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!"
]
}
}
}
]
}
23 changes: 19 additions & 4 deletions sample-job-docs/install-packages.json
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"
}
}
]
}
16 changes: 16 additions & 0 deletions sample-job-docs/reboot.json
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"
}
}
]
}
22 changes: 19 additions & 3 deletions sample-job-docs/remove-packages.json
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"
}
}
]
}
16 changes: 11 additions & 5 deletions sample-job-handlers/download-file.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/bin/sh
#!/usr/bin/env sh
set -e

echo "Running download-file.sh"
user=$1
fileUrl=$2
outputFile=$3
echo "Username: $user"
echo "File URL: $fileUrl"
echo "Write documents to file: $outputFile"
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"
if id "$user" 2>/dev/null && command -v "sudo" > /dev/null; then
sudo -u "$user" -n wget --quiet -O "$outputFile" "$fileUrl"
else
echo "WARNING: sudo command not found"
wget --quiet -O --quiet "$2" "$1"
echo "username or sudo command not found"
wget --quiet -O "$outputFile" "$fileUrl"
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."
Expand Down
Loading

0 comments on commit 032aba3

Please sign in to comment.