You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

91 lines
3.1 KiB

#curl -LO https://www.gitea1.intx.com.au/jn/punkshell/raw/branch/master/getpunk.cmd
#chmod +x getpunk.cmd
git_upstream="https://gitea1.intx.com.au/jn/punkshell.git"
#review - how can we test if another url such as ssh://git@pcm-gitea1.corp.intx.com.au:2222/jn/punkshell is actually the same repo, without cloning and comparing files/history?
if ! command -v git &> /dev/null; then
echo "Git is not available. Please install git and ensure it is available on the path."
exit 1
fi
wdir="$(pwd)"; [ "$(pwd)" = "/" ] && wdir=""
case "$0" in
/*) scriptpath="${0}";;
*) scriptpath="$wdir/${0#./}";;
esac
scriptdir="${scriptpath%/*}"
echo "script: $0"
echo "pwd: $(pwd)"
echo "scriptdir: $scriptdir"
echo "scriptpath: $scriptpath"
scriptdir=$(realpath $scriptdir)
scriptpath=$(realpath $scriptpath)
basename=$(basename "$scriptpath")
scriptroot="${basename%.*}" #e.g "getpunk"
launchdir=$(pwd)
if [[ "$launchdir" != "$scriptdir" ]]; then
echo "The current directory does not seem to be the folder in which the ${scriptroot} script is located."
read -p "Do you want to use the current directory '${launchdir}' as the location for punkshell? (Y|N)"$'\n'" Y - use launchdir ${launchdir}"$'\n'" N - use script folder '${scriptdir}'"$'\n'" (Any other value to abort): " answer
if [[ "${answer^^}" == "Y" ]]; then
punkfolder=$launchdir
elif [[ "${answer^^}" == "N" ]]; then
punkfolder=$scriptdir
else
exit 1
fi
else
punkfolder=$scriptdir
fi
cd $punkfolder
contentcount=$(ls -A | wc -l)
effectively_empty=0
if [ $contentcount == 0 ]; then
effectively_empty=1
elif [[ ("$punkfolder" == "$scriptdir") && ("$contentcount" -lt 10) ]]; then
#treat as empty if we have only a few files matching script root name
count_scriptlike=$(ls ${scriptroot}.* | wc -l)
if [ "$count_scriptlike" -eq $contentcount ]; then
effectively_empty=1
fi
fi
if [ "$effectively_empty" -ne 1 ]; then
if ! [ -d "$punkfolder/.git" ]; then
echo "The folder '${punkfolder}' contains other items, and it does not appear to be a git project"
echo "Please place this script in an empty folder which is to be the punkshell base folder."
exit
else
repo_origin=$(git remote get-url origin)
if [ "$repo_origin" != "$git_upstream" ]; then
echo "The current repository origin '${repo_origin}' is not the expected upstream '${git_upstream}'"
read -p "Continue anyway? (Y|N)" answer
if [[ "${answer^^}" != "Y" ]]; then
exit 1
fi
fi
fi
fi
if ! [ -d "$punkfolder/.git" ]; then
#set defaultbranch to master to suppress loud stderr 'hint' about initial branch name.
git -c init.DefaultBranch=master init
git remote add origin $git_upstream
fi
git fetch origin
if [[ "$punkfolder" == "$scriptdir" ]]; then
if [ -f $scriptroot.cmd ]; then
cp -f $scriptroot.cmd $scriptroot.cmd.lastrun
rm $scriptroot.cmd
fi
fi
git pull $git_upstream master
git checkout $scriptroot.cmd
git branch --set-upstream-to=origin/master master
cd $launchdir #restore original CWD