Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F112550423
scitas-motd-update
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, May 11, 07:59
Size
2 KB
Mime Type
text/x-shellscript
Expires
Tue, May 13, 07:59 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
26103102
Attached To
rSCMOTDSCRIPTS scitas-motd-scripts
scitas-motd-update
View Options
#!/bin/bash
# Location of the configuration file
SMOTD_CONFIG
=
"../etc/scitas-motd/scitas-motd.conf"
# Read configuration values
if
[
-r
${
SMOTD_CONFIG
}
]
then
.
${
SMOTD_CONFIG
}
fi
# Check that all the required values are set
REQUIRED_OPTIONS
=
"SMOTD_GITREPO"
MISSING_OPTION
=
false
for
option in
${
REQUIRED_OPTIONS
}
do
if
[
! -v
${
option
}
]
then
echo
"[ERROR] Missing configuration value: '${option}'"
> /dev/stderr
MISSING_OPTION
=
true
fi
done
if
${
MISSING_OPTION
}
then
echo
"[ERROR] Missing configuration options, update ${SMOTD_CONFIG}"
> /dev/stderr
exit
1
fi
# Check if git is available
SMOTD_GIT
=
${
SMOTD_GIT
:-
git
}
${
SMOTD_GIT
}
--version 1&>2 /dev/null
if
[
!
$?
]
then
echo
"[ERROR] git (${SMOTD_GIT}) not available!"
> /dev/stderr
exit
1
fi
#
# Checkout the repository and/or update it
#
SMOTD_GITDIR
=
${
SMOTD_GITDIR
:-
/var/lib/scitas-motd
}
if
[
-v
${
SMOTD_GITBRANCH
}
]
then
GIT_BRANCH_OPT
=
"--branch ${SMOTD_GITBRANCH}"
else
GIT_BRANCH_OPT
=
""
fi
if
[
-d
${
SMOTD_GITDIR
}
&&
! -d
${
SMOTD_GITDIR
}
/.git
]
||
[
! -a
${
SMOTD_GITDIR
}
]
then
# Assuming it's either an empty directory, or it does not exist
${
SMOTD_GIT
}
clone
${
GIT_BRANCH_OPT
}
${
SMOTD_GITREPO
}
${
SMOTD_GITDIR
}
RC
=
$?
if
!
${
RC
}
then
echo
"[ERROR] Error while cloning repository. Maybe ${SMOTD_GITDIR} is not empty?"
> /dev/stderr
exit
1
fi
elif
[
-d
${
SMOTD_GITDIR
}
&&
-d
${
SMOTD_GITDIR
}
/.git
]
then
# Assuming it already exists and is a git repo
GIT_OPTIONS
=
"--git-dir=${SMOTD_GITDIR}/.git --work-tree=${SMOTD_GITDIR}"
# For safety let's reset the origin URL
# TODO: check return codes
${
SMOTD_GIT
}
${
GIT_OPTIONS
}
remote origin
set
-url
${
SMOTD_GITREPO
}
${
SMOTD_GIT
}
${
GIT_OPTIONS
}
fetch origin
# TODO: test corner cases (different states of the repo)
GIT_REF
=
${
SMOTD_GIT
}
${
GIT_OPTIONS
}
show-ref --hash refs/remotes/origin/
${
SMOTD_GITBRANCH
:-
HEAD
}
${
SMOTD_GIT
}
${
GIT_OPTIONS
}
reset --quiet --hard
${
GIT_REF
}
else
# It must already exist and not be a directory
echo
"[ERROR] ${SMOTD_GITDIR} exists and is not a directory!"
> /dev/sdterr
exit
1
fi
exit
0
Event Timeline
Log In to Comment