Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
liu-puppet-modules
aes
Commits
62951cc6
Commit
62951cc6
authored
1 year ago
by
Filip Strömbäck
Browse files
Options
Downloads
Patches
Plain Diff
Removed the update_repo.sh file, not needed anymore.
parent
7da41173
No related branches found
No related tags found
2 merge requests
!50
Fix: Puppet Defining "data_provider": "hiera" in metadata.json is deprecated....
,
!40
Merge from devel. Commits related to RHEL9 upgrade and pdk cleanup.
Pipeline
#102013
passed
1 year ago
Stage: puppet
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
files/update_repo.sh
+0
-113
0 additions, 113 deletions
files/update_repo.sh
manifests/init.pp
+13
-13
13 additions, 13 deletions
manifests/init.pp
with
13 additions
and
126 deletions
files/update_repo.sh
deleted
100755 → 0
+
0
−
113
View file @
7da41173
#!/bin/bash
# Keep a Git repository updated. Optionally execute a command whenever it has been updated in order
# to trigger further processing of some kind (e.g. restarting services).
# The command is called as follows:
# update_repo.sh <destination path> <source repo> <source branch>
# If REPO_ON_UPDATE is set, then that file will be executed whenever the repo is created and/or
# updated to a new revision. This can be used to trigger further processing of some sort, such as
# compiling the contained source and/or restarting system services as appropriate.
# This script is designed to be executed as a privillegied user so that the update command could do
# privillegied operations. Thus, the git commands will be isolated to a user as described by
# REPO_USER and REPO_GROUP, if they are is set. It is, of course, also possible to just run this
# script as a regular user without setting REPO_USER.
# "function" that keeps the repo updated. Returns 0 if nothing was done, 100 if the repo was updated,
# and something else on some kind of error. This function will be executed as the user indicated in
# the environment variables.
# I'm sorry for this thing... Turns out that sudo does not allow passing bash functions as environment
# variables, so I simply pass the entire "function" to Bash as a string.
update_repo_fn
=
$(
cat
<<
'
EOF
'
if [[ ! -d "
$repo_path
" ]]
then
# Does not exist. We need to checkout the repository.
git clone --single-branch --branch "
$repo_branch
" "
$repo_source
" "
$repo_path
" || exit 1
exit 100
else
# It does exist. Make sure it is updated.
cd "
$repo_path
"
old_sha=
$(
git rev-parse HEAD
)
git fetch -f "
$repo_source
" "
$repo_branch
":remotes/origin/"
$repo_branch
" || exit 1
new_sha=
$(
git rev-parse remotes/origin/
"
$repo_branch
"
)
if [[ "
$old_sha
" == "
$new_sha
" ]]
then
# They are the same, we don't need to do anything.
exit 0
else
# They differ. Check out the new revision.
git checkout -f "
$new_sha
" || exit 1
git branch -f "
$repo_branch
" "
$new_sha
" || exit 1
# This is not strictly necessary, but it makes it look like we have the correct branch
# checked out. Good if someone inspects the repo at a later time.
git checkout -f "
$repo_branch
" || exit 1
exit 100
fi
fi
EOF
)
# Check for enough parameters.
if
[[
"$#"
< 3
]]
then
echo
"Not enough parameters."
echo
"Usage: update_repo.sh <path> <source> <branch>"
exit
2
fi
# Check if the REPO_ON_UPDATE script exists. If it doesn't (probably
# because Puppet has not created it yet), then we don't want to run
# yet. If we run without the script being present, then the script
# will not be executed until the repository is updated, thus breaking
# our promises.
if
[[
!
-z
"
$REPO_ON_UPDATE
"
]]
then
if
[[
!
-f
"
$REPO_ON_UPDATE
"
]]
then
echo
"The script
$REPO_ON_UPDATE
does not exist."
exit
4
fi
fi
# Setup variables for calling "update_repo"...
repo_path
=
"
$1
"
repo_source
=
"
$2
"
repo_branch
=
"
$3
"
export
repo_path repo_source repo_branch
if
[[
-z
"
$REPO_USER
"
]]
then
# Just run it in a subshell
bash
-c
"
$update_repo_fn
"
else
# Perhaps group was not supplied.
if
[[
-z
"
$REPO_GROUP
"
]]
then
REPO_GROUP
=
"
$REPO_USER
"
fi
sudo
--preserve-env
=
repo_path,repo_source,repo_branch,update_repo
--set-home
--user
=
"
$REPO_USER
"
--group
=
"
$REPO_GROUP
"
--
bash
-c
"
$update_repo_fn
"
fi
# Note: We cannot put any commands between the if-statement and here. We need the result code from
# invoking bash, which is the last command in both the if- and else- branches.
result
=
"
$?
"
if
[[
$result
==
0
]]
then
# All is well, nothing needed to be done.
exit
0
elif
[[
$result
==
100
]]
then
# All is well, but we need to tell the environment that we updated the repo.
if
[[
!
-z
"
$REPO_ON_UPDATE
"
]]
then
# Run it if it is there.
eval
"
$REPO_ON_UPDATE
"
fi
exit
0
else
# Something went awry, forward the exit code.
exit
$result
fi
This diff is collapsed.
Click to expand it.
manifests/init.pp
+
13
−
13
View file @
62951cc6
...
...
@@ -45,19 +45,19 @@ class aes {
}
# File for updating repositories.
file
{
'/opt/utils'
:
ensure
=>
directory
,
mode
=>
'0755'
,
owner
=>
root
,
group
=>
root
,
}
file
{
'/opt/utils/update_repo.sh'
:
ensure
=>
file
,
mode
=>
'0755'
,
owner
=>
root
,
group
=>
root
,
content
=>
file
(
"
${module_name}
/update_repo.sh"
),
}
#
file { '/opt/utils':
#
ensure => directory,
#
mode => '0755',
#
owner => root,
#
group => root,
#
}
#
file { '/opt/utils/update_repo.sh':
#
ensure => file,
#
mode => '0755',
#
owner => root,
#
group => root,
#
content => file("${module_name}/update_repo.sh"),
#
}
# File to easily see when Puppet was last executed.
# Ideally, we would like to know if it is devel or production as well.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment