I am trying to write a bash
script which
- installs
git
then - creates a
.gitconfig
file andcat
's config text into it.
Because the first task requires installing git, the script needs to be run as root, however, I want to de-elevate the script to a regular user while creating and cat
ing config text into the .gitconfig
file.
heres what I have so far (I have removed extraneous content from script)
#! /bin/bash
apt-get install -y git
if [ ! -f /home/$admin_user/.gitconfig ]
then
echo -e "${yellow}Creating .gitconfig file${normal}"
sudo -s -u $admin_user <<EOF
cat <<- DGC >> /home/$admin_user/.gitconfig
[alias]
lg1 = ..
lg2 = ...
lg3 = ...
[user]
email = server_admin@DO_droplet.com
name = server_admin
#
[push]
default = simple
DGC
EOF
else
echo -e "${yellow} gitconfig already exists - so I will not make any modifications${normal}"
fi
when I run this I get an error
script.sh: line 782: syntax error: unexpected end of file
I think the error is being caused by the HEREDOCs?
I am open to the other suggestion other than using sudo and HEREDOC to de-elevate to $admin_user
- I am just looking for a solution to creating the .gitconfig as $admin_user
and not root