Skip to content

Commit

Permalink
Edit: bug fix -> provisioning on first boot
Browse files Browse the repository at this point in the history
Edit: remove claim certificate after provisioning
  • Loading branch information
kevax24 committed Feb 24, 2024
1 parent d5f4cc6 commit 58f26f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
23 changes: 6 additions & 17 deletions os-image/provision.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
#!/bin/bash

### BEGIN INIT INFO
# Provides: provision.sh
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start provisioning on first boot
# Description: Install Docker Engine, GGC and provision device on AWS
### END INIT INFO

# Set up device with fleet provisioning is based on AWS documentation: https://docs.aws.amazon.com/greengrass/v2/developerguide/fleet-provisioning.html#fleet-provisioning-prerequisites

# Giving the device time to boot (second)
sleep 60
sleep 30

# Move to user directory where provisioning files are stored
cd /home/pi

# Save stdout/stderr to a log file
exec >provision_log.txt 2>&1

# Get serial number of device
SERIAL_NUMBER=$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2)

Expand All @@ -38,8 +25,6 @@ FLEET_TEMPLATE_NAME=$var5
# ---------------------------- Install Docker Engine ----------------------------
# Installation of Docker Engine is based on Docker documentation: https://docs.docker.com/engine/install/debian/
echo "************ Installing Docker... ************"
# update-alternatives --set iptables /usr/sbin/iptables-legacy
# update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
# Add Docker's official GPG key
sudo apt-get update
sudo apt-get -y install ca-certificates curl gnupg
Expand Down Expand Up @@ -110,11 +95,15 @@ echo "Done"

# ---------------------------- Delete all unused files after provisioning ----------------------------
# Delete all provisioning files
sleep 60
rm ./config_parameters.txt
rm ./claim.private.pem.key
rm /greengrass/v2/claim.private.pem.key
rm ./claim.pem.crt
rm /greengrass/v2/claim.pem.crt
rm ./config.yaml
rm -rf ./GreengrassInstaller

# Delete self to provision once
# Delete provision script to provision once
sudo sed -i 's|sudo bash -c '\''/usr/bin/bash /home/pi/provision.sh > /home/pi/provision.log 2>&1'\'' &||' "/etc/rc.local"
rm "${0}"
2 changes: 1 addition & 1 deletion os-image/raspios-lite.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
{
"type": "file",
"source": "./provision.sh",
"destination": "/etc/init.d/provision.sh"
"destination": "/home/pi/provision.sh"
},
{
"type": "shell",
Expand Down
8 changes: 5 additions & 3 deletions os-image/set_os.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ wget -O /etc/init.d/resize2fs_once https://raw.githubusercontent.com/RPi-Distro/
chmod +x /etc/init.d/resize2fs_once
systemctl enable resize2fs_once

# Make the init script executable and update them to run at startup
chmod +x /etc/init.d/provision.sh
update-rc.d provision.sh defaults
# Run provision script on first boot
sed -i -e '$i \sudo bash -c '\''/usr/bin/bash /home/pi/provision.sh > /home/pi/provision.log 2>&1'\'' &\n' "/etc/rc.local"

# Make the provision script executable
chmod +x /home/pi/provision.sh

0 comments on commit 58f26f6

Please sign in to comment.