Skip to content

Instantly share code, notes, and snippets.

@asmattic
Created October 19, 2020 02:47
Show Gist options
  • Save asmattic/516d964ffdcc1196aba556dcd39385a8 to your computer and use it in GitHub Desktop.
Save asmattic/516d964ffdcc1196aba556dcd39385a8 to your computer and use it in GitHub Desktop.
Raspberry Pi Boot Script: Run config, pull or clone git repo, copy repo folder containing the pi specific project, run any config on that working folder, run next script
#!/bin/bash
# For now, I know user home
user_home=${HOME}
echo "Go to ${user_home} dir"
echo ""
cd $user_home
# Any startup scripts you want to run before updating the git repo
# sets the ssh keys to reference for git
export GIT_SSH="${user_home}/git-ssh.sh"
export GIT_SSH_KEY="${user_home}/.ssh/id_rsa"
# Folder in repo that contains the project to be run on the pi
working_project_dir_name="some-project-dir-name"
# Remove the project dir from the previous run
echo "Remove the current ${user_home}/${working_project_dir_name} dir"
sudo rm -rf "${user_home}/${working_project_dir_name}"
# TODO: Check if the git project folder already exists
# If it does, update it
git_repo_name="some-repo-name"
git_username="asmattic"
git_dir="${user_home}/${repo_name}"
git_repo_ssh_link="[email protected]:${git_username}/${git_repo_name}.git"
if [ -d "$git_dir" ]
then
echo "${git_dir} exists"
# echo "Here are the branches"
cd $git_dir \
# && git branch -a
# echo "Type the one you want and hit [ENTER]"
# read git_branch_to_pull
git_branch_to_pull="master"
echo "You chose ${git_branch_to_pull}, about to pull"
git checkout ${git_branch_to_pull} \
&& git pull origin ${git_branch_to_pull}
else
echo "Get the whole GitHub repo"
echo "${git_repo_ssh_link}"
echo ""
git clone $git_repo_ssh_link
fi
echo "Copy just the ${working_project_dir_name} dir to ${user_home}"
cp -r ${user_home}/${git_repo_name}/${working_project_dir_name} ${user_home}/ \
&& cd "${user_home}/${working_project_dir_name}"
# Add something to the working project dir
# echo "Get some input to add to the working project dir"
# read some_input
# cat <<EndOfText >> "${project_dir_name}/some-file.txt"
# ${some_input}
# EndOfText
# echo "Placing ${some_input}"
# echo -e "\n${some_input}" | sudo tee -a ${user_home}/${project_dir_name}/some-file.txt
# Run next script
# Run sudo ./next_script.sh
echo "About to run next_script.sh"
cd ${user_home}/${} \
&& sudo ./next_script.sh
echo -e "\nDone"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment