679 lines
24 KiB
Bash
Executable file
679 lines
24 KiB
Bash
Executable file
#!/bin/bash
|
|
function setConstant() {
|
|
export "SOSGIT_VERSION=dev28"
|
|
}
|
|
function getDefaultConfiguration() {
|
|
# SOSGIT_CONFIGVERSION=6
|
|
# # sos-git configuration\n
|
|
# # this is the default configuration, you\n
|
|
# # may make changes in sos-git.conf.d\n
|
|
# # since they may get overriten in a future\n
|
|
# # update.\n
|
|
# \n
|
|
# # Commands\n
|
|
# ## Shell\n
|
|
# ## DEFAULT: /bin/sh\n
|
|
# ## You may want to set this to /bin/bash\n
|
|
# #SOSGIT_SHELL=/bin/sh\n
|
|
# \n
|
|
# ## Shell arguments\n
|
|
# ## DEFAULT:\n
|
|
# ## Here you can define your custom shell\n
|
|
# ## arguments, like another rcfile.\n
|
|
# #SOSGIT_SHELLARGS=\n
|
|
# #\n
|
|
# ## Make\n
|
|
# ## DEFAULT: /bin/make\n
|
|
# #SOSGIT_MAKE=/bin/make\n
|
|
# #\n
|
|
# ## Editor\n
|
|
# ## DEFAULT: /bin/nano\n
|
|
# ## You may want to set this to /bin/vi\n
|
|
# ## or /bin/vim or any other editor.\n
|
|
# #SOSGIT_EDITOR=/bin/nano\n
|
|
# #\n
|
|
# ## cURL\n
|
|
# ## DEFAULT: /bin/curl\n
|
|
# #SOSGIT_CURL=/bin/curl\n
|
|
# #\n
|
|
# ## git\n
|
|
# ## DEFAULT: /bin/git\n
|
|
# #SOSGIT_GIT=/bin/git\n
|
|
# #\n
|
|
# ## ls\n
|
|
# ## DEFAULT: /bin/ls\n
|
|
# ## The ls command must be from GNU\n
|
|
# ## coreutils, otherwise it may not\n
|
|
# ## work correctly with sos-git.\n
|
|
# #SOSGIT_LS=/bin/ls\n
|
|
# #\n
|
|
# ## rm\n
|
|
# ## DEFAULT: /bin/rm\n
|
|
# ## The rm command must be from GNU\n
|
|
# ## coreutils, otherwise it may not\n
|
|
# ## work correctly with sos-git.\n
|
|
# #SOSGIT_RM=/bin/rm\n
|
|
# #\n
|
|
# ## mkdir\n
|
|
# ## DEFAULT: /bin/mkdir\n
|
|
# ## The mkdir command must be from\n
|
|
# ## GNU coreutils, otherwise it may\n
|
|
# ## not work correctly with sos-git.\n
|
|
# #SOSGIT_MKDIR=/bin/mkdir\n
|
|
# #\n
|
|
# ## mv\n
|
|
# ## DEFAULT: /bin/mv\n
|
|
# ## The mv command must be from GNU\n
|
|
# ## coreutils, otherwise it may not\n
|
|
# ## work correctly with sos-git.\n
|
|
# #SOSGIT_MV=/bin/mv\n
|
|
# #\n
|
|
# ## chmod\n
|
|
# ## DEFAULT: /bin/chmod\n
|
|
# ## The chmod command must be from\n
|
|
# ## GNU coreutils, otherwise it may\n
|
|
# ## not work correctly with sos-git.\n
|
|
# #SOSGIT_CHMOD=/bin/chmod\n
|
|
# \n
|
|
# # Title\n
|
|
# ## Suppress\n
|
|
# ## DEFAULT: false\n
|
|
# ## This hides the branding at\n
|
|
# ## startup completely.\n
|
|
# #SOSGIT_TITLE_SUPPRESS=false\n
|
|
# #\n
|
|
# ## Text\n
|
|
# ## DEFAULT: false\n
|
|
# ## This prints the branding\n
|
|
# ## at startup in normal text.\n
|
|
# #SOSGIT_TITLE_TEXT=false\n
|
|
# \n
|
|
# # Temp\n
|
|
# # DEFAULT: /dev/shm\n
|
|
# # The temporary directory.\n
|
|
# # NO TRAILING SLASH AT THE END!\n
|
|
# #SOSGIT_TMP=/dev/shm\n
|
|
# \n
|
|
# # Repository save directory\n
|
|
# # DEFAULT: \$HOME/.sostools/git/repos\n
|
|
# # The directory where your downloaded\n
|
|
# # repositories are stored.\n
|
|
# # NO TRAILING SLASH AT THE END!\n
|
|
# # NO ~, USE \$HOME INSTEAD!\n
|
|
# #SOSGIT_REPOS=\$HOME/.sostools/git/repos\n
|
|
# \n
|
|
# # Internet\n
|
|
# ## Update URL\n
|
|
# ## DEFAULT: https://staropensource.ddns.net\n
|
|
# ## /git/staropensource/sostools\n
|
|
# ## /raw/branch/develop/sos-git.sh
|
|
# ## The update URL, from where sos-git gets\n
|
|
# ## updates. The save location will be\n
|
|
# ## determined from the command line arguments.\n
|
|
# #SOSGIT_UPDATEURL=https://staropensource.ddns.net/git/staropensource/sostools/raw/branch/develop/sos-git.sh\n
|
|
# #\n
|
|
# ## Request string\n
|
|
# ## DEFAULT: https://staropensource.ddns.net\n
|
|
# ## /git/%s/%s\n
|
|
# ## String is used for making requests and\n
|
|
# ## downloading repositories. First %s is user,\n
|
|
# ## second %s is the repository.
|
|
# ## NO TRAILING SLASH AT THE END!\n
|
|
# #SOSGIT_REQUESTSTRING=https://staropensource.ddns.net/git/%s/%s\n
|
|
# #\n
|
|
# ## Remote request string\n
|
|
# ## DEFAULT: https://%s:%s@staropensource.ddns.net/%s/%s
|
|
# ## String is used for remoteauth, that updates\n
|
|
# ## the remote string in git. First %s is username,\n
|
|
# ## second %s is password, third %s is user and\n
|
|
# ## fourth %s is the repository.\n
|
|
# ## NO TRAILING SLASH AT THE END!\n
|
|
# #SOSGIT_REQUESTSTRING_REMOTE=https://%s:%s@staropensource.ddns.net/%s/%s\n
|
|
# \n
|
|
# # No root warning\n
|
|
# ## DEFAULT: false\n
|
|
# ## Disables the root warning\n
|
|
# #SOSGIT_NOROOTWARNING=false\n
|
|
export "SOSGIT_EXITSTRING=SOSGIT_CONFIGVERSION=6# sos-git configuration\n# this is the default configuration, you\n# may make changes in sos-git.conf.d\n# since they may get overriten in a future\n# update.\n\n# Commands\n## Shell\n## DEFAULT: /bin/sh\n## You may want to set this to /bin/bash\n#SOSGIT_SHELL=/bin/sh\n\n## Shell arguments\n## DEFAULT:\n## Here you can define your custom shell\n## arguments, like another rcfile.\n#SOSGIT_SHELLARGS=\n#\n## Make\n## DEFAULT: /bin/make\n#SOSGIT_MAKE=/bin/make\n#\n## Editor\n## DEFAULT: /bin/nano\n## You may want to set this to /bin/vi\n## or /bin/vim or any other editor.\n#SOSGIT_EDITOR=/bin/nano\n#\n## cURL\n## DEFAULT: /bin/curl\n#SOSGIT_CURL=/bin/curl\n#\n## git\n## DEFAULT: /bin/git\n#SOSGIT_GIT=/bin/git\n#\n## ls\n## DEFAULT: /bin/ls\n## The ls command must be from GNU\n## coreutils, otherwise it may not\n## work correctly with sos-git.\n#SOSGIT_LS=/bin/ls\n#\n## rm\n## DEFAULT: /bin/rm\n## The rm command must be from GNU\n## coreutils, otherwise it may not\n## work correctly with sos-git.\n#SOSGIT_RM=/bin/rm\n#\n## mkdir\n## DEFAULT: /bin/mkdir\n## The mkdir command must be from\n## GNU coreutils, otherwise it may\n## not work correctly with sos-git.\n#SOSGIT_MKDIR=/bin/mkdir\n#\n## mv\n## DEFAULT: /bin/mv\n## The mv command must be from GNU\n## coreutils, otherwise it may not\n## work correctly with sos-git.\n#SOSGIT_MV=/bin/mv\n#\n## chmod\n## DEFAULT: /bin/chmod\n## The chmod command must be from\n## GNU coreutils, otherwise it may\n## not work correctly with sos-git.\n#SOSGIT_CHMOD=/bin/chmod\n\n# Title\n## Suppress\n## DEFAULT: false\n## This hides the branding at\n## startup completely.\n#SOSGIT_TITLE_SUPPRESS=false\n#\n## Text\n## DEFAULT: false\n## This prints the branding\n## at startup in normal text.\n#SOSGIT_TITLE_TEXT=false\n\n# Temp\n# DEFAULT: /dev/shm\n# The temporary directory.\n# NO TRAILING SLASH AT THE END!\n#SOSGIT_TMP=/dev/shm\n\n# Repository save directory\n# DEFAULT: \$HOME/.sostools/git/repos\n# The directory where your downloaded\n# repositories are stored.\n# NO TRAILING SLASH AT THE END!\n# NO ~, USE \$HOME INSTEAD!\n#SOSGIT_REPOS=\$HOME/.sostools/git/repos\n\n# Internet\n## Update URL\n## DEFAULT: https://staropensource.ddns.net\n## /git/staropensource/sostools\n## /raw/branch/develop/sos-git.sh## The update URL, from where sos-git gets\n## updates. The save location will be\n## determined from the command line arguments.\n#SOSGIT_UPDATEURL=https://staropensource.ddns.net/git/staropensource/sostools/raw/branch/develop/sos-git.sh\n#\n## Request string\n## DEFAULT: https://staropensource.ddns.net\n## /git/%s/%s\n## String is used for making requests and\n## downloading repositories. First %s is user,\n## second %s is the repository.## NO TRAILING SLASH AT THE END!\n#SOSGIT_REQUESTSTRING=https://staropensource.ddns.net/git/%s/%s\n#\n## Remote request string\n## DEFAULT: https://%s:%s@staropensource.ddns.net/%s/%s## String is used for remoteauth, that updates\n## the remote string in git. First %s is username,\n## second %s is password, third %s is user and\n## fourth %s is the repository.\n## NO TRAILING SLASH AT THE END!\n#SOSGIT_REQUESTSTRING_REMOTE=https://%s:%s@staropensource.ddns.net/%s/%s\n\n# No root warning\n## DEFAULT: false\n## Disables the root warning\n#SOSGIT_NOROOTWARNING=false\n"
|
|
return "0"
|
|
}
|
|
function loadDefaultConfiguration() {
|
|
export "SOSGIT_CONFIGVERSION=6"
|
|
export "SOSGIT_SETUP_USER=false"
|
|
export "SOSGIT_SETUP_SYSTEM=false"
|
|
export "SOSGIT_SHELL=/bin/sh"
|
|
export "SOSGIT_MAKE=/bin/make"
|
|
export "SOSGIT_EDITOR=/bin/nano"
|
|
export "SOSGIT_CURL=/bin/curl"
|
|
export "SOSGIT_GIT=/bin/git"
|
|
export "SOSGIT_LS=/bin/ls"
|
|
export "SOSGIT_RM=/bin/rm"
|
|
export "SOSGIT_MKDIR=/bin/mkdir"
|
|
export "SOSGIT_CHMOD=/bin/chmod"
|
|
export "SOSGIT_TITLE_SUPPRESS=false"
|
|
export "SOSGIT_TITLE_TEXT=false"
|
|
export "SOSGIT_TMP=/dev/shm"
|
|
export "SOSGIT_REPOS=$HOME/.sostools/git/repos"
|
|
export "SOSGIT_UPDATEURL=https://staropensource.ddns.net/git/staropensource/sostools/raw/branch/develop/sos-git.sh"
|
|
export "SOSGIT_REQUESTSTRING=https://staropensource.ddns.net/git/%s/%s"
|
|
export "SOSGIT_REQUESTSTRING_REMOTE=https://%s:%s@staropensource.ddns.net/git/%s/%s"
|
|
export "SOSGIT_NOROOTWARNING=false"
|
|
}
|
|
function loadSystemConfigurationMigrationError() {
|
|
echo "Your system configuration file is too old, but can't be reset."
|
|
echo ""
|
|
echo "If you want to ignore loading the system configuration,"
|
|
echo "create a empty file at $HOME/.sostools/git/nosysconf"
|
|
exit "249"
|
|
}
|
|
function loadSystemConfiguration() {
|
|
if [ -f "$HOME/.sostools/git/nosysconf" ] || [ -d "$HOME/.sostools/git/nosysconf" ]; then
|
|
return
|
|
else
|
|
if [ -f "/etc/sostools/git/sos-git.conf" ]; then
|
|
export "SOSGIT_EXITSTRING=$SOSGIT_CONFIGVERSION"
|
|
source "/etc/sostools/git/sos-git.conf"
|
|
if [ ! "$SOSGIT_CONFIGVERSION" == "$SOSGIT_EXITSTRING" ]; then
|
|
if [ "$(whoami)" == "root" ]; then
|
|
$SOSGIT_RM -rf "/etc/sostools/git/sos-git.conf" &> /dev/null
|
|
if [ ! "$?" == "0" ]; then loadSystemConfigurationMigrationError; fi
|
|
if [ -f "/etc/sostools/git/sos-git.conf" ] || [ -d "/etc/sostools/git/sos-git.conf" ]; then loadSystemConfigurationMigrationError; fi
|
|
getDefaultConfiguration
|
|
echo -e "$SOSGIT_EXITSTRING" &> /etc/sostools/git/sos-git.conf
|
|
echo "Your system configuration file is too old and has been reset."
|
|
exit "250"
|
|
else
|
|
loadSystemConfigurationMigrationError
|
|
fi
|
|
fi
|
|
else
|
|
if [ "$(whoami)" == "root" ]; then
|
|
getDefaultConfiguration
|
|
echo -e "$SOSGIT_EXITSTRING" &> /etc/sostools/git/sos-git.conf
|
|
fi
|
|
fi
|
|
if [ -d "/etc/sostools/git/sos-git.conf.d/" ]; then
|
|
for file in $($SOSGIT_LS --color=never -w 1 "/etc/sostools/git/sos-git.conf.d/");do
|
|
source "/etc/sostools/git/sos-git.conf.d/${file}"
|
|
done
|
|
fi
|
|
fi
|
|
}
|
|
function loadUserConfiguration() {
|
|
if [ -f "$HOME/.sostools/git/sos-git.conf" ]; then
|
|
export "SOSGIT_EXITSTRING=$SOSGIT_CONFIGVERSION"
|
|
source "$HOME/.sostools/git/sos-git.conf"
|
|
if [ ! "$SOSGIT_CONFIGVERSION" == "$SOSGIT_EXITSTRING" ]; then
|
|
$SOSGIT_RM "$HOME/.sostools/git/sos-git.conf" &> /dev/null
|
|
getDefaultConfiguration
|
|
echo "$SOSSSH_EXITSTRING" &> "$HOME/.sostools/git/sos-git.conf"
|
|
echo "Your user configuration file is too old and has been reset."
|
|
exit "251"
|
|
fi
|
|
fi
|
|
if [ -d "$HOME/.sostools/git/sos-git.conf.d/" ]; then
|
|
for file in $($SOSGIT_LS --color=never -w 1 "$HOME/.sostools/git/sos-git.conf.d/");do
|
|
source "$HOME/.sostools/git/sos-git.conf.d/${file}"
|
|
done
|
|
fi
|
|
}
|
|
function doUserSetup() {
|
|
if [ "$1" == "force" ] || [ "$1" == "force+noinfo" ] || [ ! "$SOSGIT_SETUP_USER" == "true" ]; then
|
|
if [ "$1" == "force+noinfo" ] || [ "$1" == "noinfo" ]; then
|
|
echo -n ""
|
|
else
|
|
echo "Writing user configuration"
|
|
fi
|
|
$SOSGIT_MKDIR "$HOME/.sostools/git/sos-git.conf.d" -p
|
|
getDefaultConfiguration
|
|
echo -e "$SOSGIT_EXITSTRING" &> $HOME/.sostools/git/sos-git.conf
|
|
echo -e "# DO NOT DELETE OR MODIFY THIS FILE\nSOSGIT_SETUP_USER=true" &> $HOME/.sostools/git/sos-git.conf.d/setup.conf
|
|
$SOSGIT_CHMOD "+x" "$HOME/.sostools/git/sos-git.conf" "$HOME/.sostools/git/sos.git.conf.d/*" &> /dev/null
|
|
if [ "$1" == "force+noinfo" ] || [ "$1" == "noinfo" ]; then
|
|
echo -n ""
|
|
else
|
|
echo "Applying new user configuration"
|
|
fi
|
|
loadUserConfiguration
|
|
fi
|
|
}
|
|
function doSystemSetup() {
|
|
if [ "$1" == "force" ] || [ "$1" == "force+noinfo" ] || [ ! "$SOSGIT_SETUP_SYSTEM" == "true" ] && [ "$(whoami)" == "root" ]; then
|
|
if [ "$1" == "force+noinfo" ] || [ "$1" == "noinfo" ]; then
|
|
echo -n ""
|
|
else
|
|
echo "Writing system configuration"
|
|
fi
|
|
$SOSGIT_MKDIR "/etc/sostools/git/sos-git.conf.d" -p
|
|
getDefaultConfiguration
|
|
echo -e "$SOSGIT_EXITSTRING" &> /etc/sostools/git/sos-git.conf
|
|
$SOSGIT_CHMOD "+x" "/etc/sostools/git/sos-git.conf" "/etc/sostools/git/sos.git.conf.d/*" &> /dev/null
|
|
echo -e "# DO NOT DELETE OR MODIFY THIS FILE\nSOSGIT_SETUP_SYSTEM=true" &> /etc/sostools/git/sos-git.conf.d/setup.conf
|
|
if [ "$1" == "force+noinfo" ] || [ "$1" == "noinfo" ]; then
|
|
echo -n ""
|
|
else
|
|
echo "Applying new system configuration"
|
|
fi
|
|
loadSystemConfiguration
|
|
fi
|
|
}
|
|
function doRepositorySetup() {
|
|
if [ -d "$SOSGIT_REPOS" ]; then
|
|
return "0"
|
|
elif [ -f "$SOSGIT_REPOS" ]; then
|
|
echo "Moving \"$SOSGIT_REPOS\" to \"$SOSGIT_REPOS.bak\""
|
|
$SOSGIT_MV "$SOSGIT_REPOS" "$SOSGIT_REPOS.bak"
|
|
echo "Creating repository save directory"
|
|
$SOSGIT_MKDIR -p "$SOSGIT_REPOS"
|
|
else
|
|
echo "Creating repository save directory"
|
|
$SOSGIT_MKDIR -p "$SOSGIT_REPOS"
|
|
fi
|
|
}
|
|
function checkRootUser() {
|
|
if [ "$(whoami)" == "root" ] && [ ! "$SOSGIT_NOROOTWARNING" == "true" ]; then
|
|
echo "Warning! You are running sos-git as the root user."
|
|
echo " Please switch to a normal account, unless"
|
|
echo " the repository asks for these permissions."
|
|
echo ""
|
|
echo " To disable this warning, create a file"
|
|
echo " at \"$HOME/.sostools/git/norootwarn\" or"
|
|
echo " \"/etc/sostools/git/norootwarn\"."
|
|
fi
|
|
}
|
|
function checkFastSettings() {
|
|
if [ -f "$HOME/.sostools/git/norootwarn" ] || [ -d "$HOME/.sostools/git/norootwarn" ]; then
|
|
rm -rf "$HOME/.sostools/git/norootwarn"
|
|
echo -e "# This file has been generated by sos-git\n# because of the use of fast settings.\nSOSGIT_NOROOTWARNING=true" &> "$HOME/.sostools/git/sos-git.conf.d/norootwarning.conf"
|
|
fi
|
|
if [ "$(whoami)" == "root" ]; then
|
|
if [ -f "/etc/sostools/git/norootwarn" ] || [ -d "/etc/sostools/git/norootwarn" ]; then
|
|
rm -rf "/etc/sostools/git/norootwarn"
|
|
echo -e "# This file has been generated by sos-git\n# because of the use of fast settings.\nSOSGIT_NOROOTWARNING=true" &> "/etc/sostools/git/sos-git.conf.d/norootwarning.conf"
|
|
fi
|
|
fi
|
|
}
|
|
function chmodConfiguration() {
|
|
$SOSGIT_CHMOD +x "$HOME/.sostools/git/sos-git.conf" &> /dev/null
|
|
for file in $($SOSGIT_LS --color=never -w 1 "$HOME/.sostools/git/sos-git.conf.d"); do
|
|
$SOSGIT_CHMOD +x "$HOME/.sostools/git/sos-git.conf.d/$file" &> /dev/null
|
|
done
|
|
if [ -d "/etc/sostools/git/" ] && [ "$(whoami)" == "root" ]; then
|
|
$SOSGIT_CHMOD +x "/etc/sostools/git/sos-git.conf" &> /dev/null
|
|
for file in $($SOSGIT_LS --color=never -w 1 "/etc/sostools/git/sos-git.conf.d"); do
|
|
$SOSGIT_CHMOD +x "/etc/sostools/git/sos-git.conf.d/$file" &> /dev/null
|
|
done
|
|
fi
|
|
}
|
|
loadDefaultConfiguration
|
|
checkFastSettings
|
|
chmodConfiguration
|
|
loadSystemConfiguration
|
|
loadUserConfiguration
|
|
doSystemSetup
|
|
doUserSetup
|
|
doRepositorySetup
|
|
setConstant
|
|
function translateRepo() {
|
|
export "SOSGIT_EXITSTRING=${SOSGIT_REPOS}/$1"
|
|
}
|
|
function existRepo() {
|
|
translateRepo "$1"
|
|
if [ -d "$SOSGIT_EXITSTRING" ]; then
|
|
return "0"
|
|
else
|
|
return "1"
|
|
fi
|
|
}
|
|
function noRepoFound() {
|
|
echo "ERROR: Repository \"$1\" does not exist."
|
|
exit 9
|
|
}
|
|
function formatRequestString() {
|
|
# dont noodle me that I shouldve used -v var. I tried, it didnt work. yes i did typos to fuck you off.
|
|
printf "$SOSGIT_REQUESTSTRING" "$1" "$2" &> ${SOSGIT_TMP}/formatrequeststring
|
|
export "SOSGIT_EXITSTRING=$(cat ${SOSGIT_TMP}/formatrequeststring)"
|
|
$SOSGIT_RM -rf "${SOSGIT_TMP}/formatrequeststring"
|
|
return
|
|
}
|
|
function formatRemoteRequestString() {
|
|
# same here as in formatRequestString()
|
|
printf "$SOSGIT_REQUESTSTRING_REMOTE" "$1" "$2" "$3" "$4" &> ${SOSGIT_TMP}/formatremoterequeststring
|
|
export "SOSGIT_EXITSTRING=$(cat ${SOSGIT_TMP}/formatremoterequeststring)"
|
|
$SOSGIT_RM -rf "${SOSGIT_TMP}/formatremoterequeststring"
|
|
return
|
|
}
|
|
function existRepoOnline() {
|
|
formatRequestString "$1" "$2"
|
|
$SOSGIT_CURL "-sSLqq" "${SOSGIT_EXITSTRING}/.git/HEAD" &> /dev/null
|
|
if [ "$?" == "0" ]; then
|
|
return "0"
|
|
else
|
|
return "1"
|
|
fi
|
|
}
|
|
function hasMakefile() {
|
|
translateRepo "$1"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
if [ -f "Makefile" ]; then
|
|
return "0"
|
|
else
|
|
return "1"
|
|
fi
|
|
}
|
|
function noMakefileFound() {
|
|
echo "ERROR: Repository \"$1\" is not compatible with make."
|
|
exit 7
|
|
}
|
|
function argumentMissing() {
|
|
echo "ERROR: Missing arguments."
|
|
exit 6
|
|
}
|
|
function existBranch() {
|
|
translateRepo "$1"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
git branch | grep "$2" &> /dev/null
|
|
if [ "$?" == "0" ]; then
|
|
return "0"
|
|
else
|
|
return "1"
|
|
fi
|
|
}
|
|
function noBranchFound() {
|
|
echo "ERROR: Branch \"$2\" in repository \"$1\" does not exist."
|
|
}
|
|
function collectFiles() {
|
|
echo "$(pwd)" &> $SOSGIT_TMP/sosgit_collectfiles_pwd
|
|
cd "$1"
|
|
export "SOSGIT_EXITSTRING="
|
|
for file in $($SOSGIT_LS --color=never -w 1 "$1"); do
|
|
if [ "$SOSGIT_EXITSTRING" == "" ]; then
|
|
export "SOSGIT_EXITSTRING=$($SOSGIT_LS --color=never -w 1 $(pwd)/$file)"
|
|
else
|
|
export "SOSGIT_EXITSTRING= $($SOSGIT_LS --color=never -w 1 $(pwd)/$file)"
|
|
fi
|
|
done
|
|
cd "$(cat ${SOSGIT_TMP}/sosgit_collectfiles_pwd)"
|
|
rm -rf "${SOSGIT_TMP}/sosgit_collectfiles_pwd"
|
|
return
|
|
}
|
|
if [ ! "$SOSGIT_TITLE_SUPPRESS" == "true" ]; then
|
|
if [ ! "$SOSGIT_TITLE_TEXT" == "true" ]; then
|
|
# _ _
|
|
# ___ ___ ___ __ _(_) |_
|
|
#/ __|/ _ \/ __|_____ / _` | | __|
|
|
#\__ \ (_) \__ \_____| (_| | | |_
|
|
#|___/\___/|___/ \__, |_|\__|
|
|
# |___/
|
|
echo " _ _"
|
|
echo " ___ ___ ___ __ _(_) |_"
|
|
echo "/ __|/ _ \\/ __|_____ / _\` | | __|"
|
|
echo "\\__ \\ (_) \\__ \\_____| (_| | | |_"
|
|
echo "|___/\\___/|___/ \\__, |_|\\__|"
|
|
echo " |___/"
|
|
echo ""
|
|
else
|
|
echo -e "sos-git\n"
|
|
fi
|
|
fi
|
|
checkRootUser
|
|
if [ "$1" == "" ]; then
|
|
echo "Use \"sos-git help\" for all commands."
|
|
echo "If you want more information, use \"sos-git helpextend\"."
|
|
exit 1
|
|
elif [ "$1" == "help" ]; then
|
|
echo "<required> [optional]"
|
|
echo "sos-git branch <repository>"
|
|
echo " build <repository>"
|
|
echo " shell <repository>"
|
|
echo " clean <repository>"
|
|
echo " editconf <system>"
|
|
echo " getrepo <repository>"
|
|
echo " help"
|
|
echo " helpextend"
|
|
echo " history <repository>"
|
|
echo " install <repository>"
|
|
echo " list"
|
|
echo " pull <repository>"
|
|
echo " push <repository>"
|
|
echo " remoteauth <repository> [user]"
|
|
echo " remrepo <repository>"
|
|
echo " selfupdate"
|
|
echo " upstream <repository> <branch>"
|
|
echo " version"
|
|
exit 0
|
|
elif [ "$1" == "helpextend" ]; then
|
|
echo "<required> [optional]"
|
|
echo "command | args | description"
|
|
echo "branch | <repository> | list all branches"
|
|
echo "build | <repository> | build repository"
|
|
echo "shell | <repository> | spawn shell in repository"
|
|
echo "clean | <repository> | clean built executables"
|
|
echo "editconf | <system> | edit the configuration"
|
|
echo "getrepo | <user> <repository> | clone a repository"
|
|
echo "help | | lists all commands"
|
|
echo "helpextend | | lists all commands with extended information"
|
|
echo "history | <repository> | shows commit history"
|
|
echo "install | <repository> | install built executables"
|
|
echo "list | | lists all cloned repositories"
|
|
echo "pull | <repository> | pull new updates"
|
|
echo "push | <repository> | push new changes"
|
|
echo "remoteauth | <user> <repository> [user] | update remote to include login information"
|
|
echo "remrepo | <repository> | remove a cloned repository"
|
|
echo "selfupdate | | update sos-git"
|
|
echo "upstream | <repository> <branch> | push new changes and set branch upstream"
|
|
echo "version | | returns version string"
|
|
elif [ "$1" == "build" ]; then
|
|
if [ "$2" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$2"; then
|
|
if hasMakefile "$2"; then
|
|
translateRepo "$2"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
echo "Building repository \"$2\""
|
|
$SOSGIT_MAKE -j$(nproc) build
|
|
exit "$?"
|
|
else
|
|
noMakefileFound "$2"
|
|
fi
|
|
else
|
|
noRepoFound "$2"
|
|
fi
|
|
elif [ "$1" == "shell" ]; then
|
|
if [ "$2" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$2"; then
|
|
translateRepo "$2"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
$SOSGIT_SHELL $SOSGIT_SHELLARGS
|
|
exit "$?"
|
|
else
|
|
noRepoFound "$2"
|
|
fi
|
|
elif [ "$1" == "clean" ]; then
|
|
if [ "$2" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$2"; then
|
|
if hasMakefile "$2"; then
|
|
translateRepo "$2"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
echo "Cleaning repository \"$2\""
|
|
$SOSGIT_MAKE -j$(nproc) clean
|
|
exit "$?"
|
|
else
|
|
noMakefileFound "$2"
|
|
fi
|
|
else
|
|
noRepoFound "$2"
|
|
fi
|
|
elif [ "$1" == "editconf" ]; then
|
|
if [ "$2" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if [ "$2" == "true" ]; then
|
|
if [ "$(whoami)" == "root" ]; then
|
|
collectFiles "/etc/sostools/git/sos-git.conf.d/"
|
|
echo "Opening system configuration files in $SOSGIT_EDITOR"
|
|
$SOSGIT_EDITOR "/etc/sostools/git/sos-git.conf" $SOSGIT_EXITSTRING
|
|
else
|
|
echo "ERROR: You aren't root."
|
|
exit "2"
|
|
fi
|
|
elif [ "$2" == "false" ]; then
|
|
collectFiles "$HOME/.sostools/git/sos-git.conf.d/"
|
|
echo "Opening user configuration files in $SOSGIT_EDITOR"
|
|
$SOSGIT_EDITOR "$HOME/.sostools/git/sos-git.conf" $SOSGIT_EXITSTRING
|
|
else
|
|
echo "ERROR: Invalid boolean."
|
|
fi
|
|
elif [ "$1" == "getrepo" ]; then
|
|
if [ "$2" == "" ] || [ "$3" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepoOnline "$2" "$3"; then
|
|
translateRepo ""
|
|
cd "$SOSGIT_EXITSTRING"
|
|
formatRequestString "$2" "$3"
|
|
echo "Cloning repository"
|
|
$SOSGIT_GIT clone "$SOSGIT_EXITSTRING" "$3"
|
|
cd "$3"
|
|
echo "Cloning submodules"
|
|
$SOSGIT_GIT submodule update --init --force --recursive
|
|
else
|
|
noRepoFound "$3"
|
|
fi
|
|
elif [ "$1" == "install" ]; then
|
|
if [ "$2" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$2"; then
|
|
if hasMakefile "$2"; then
|
|
translateRepo "$2"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
echo "Installing repository \"$2\""
|
|
$SOSGIT_MAKE -j$(nproc) install
|
|
exit "$?"
|
|
else
|
|
noMakefileFound "$2"
|
|
fi
|
|
else
|
|
noRepoFound "$2"
|
|
fi
|
|
elif [ "$1" == "pull" ]; then
|
|
if [ "$2" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$2"; then
|
|
translateRepo "$2"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
echo "Pulling new changes"
|
|
$SOSGIT_GIT pull
|
|
exit "$?"
|
|
else
|
|
noRepoFound "$2"
|
|
fi
|
|
elif [ "$1" == "push" ]; then
|
|
if [ "$2" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$2"; then
|
|
translateRepo "$2"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
echo "Pushing new changes"
|
|
$SOSGIT_GIT push
|
|
exit "$?"
|
|
else
|
|
noRepoFound "$2"
|
|
fi
|
|
elif [ "$1" == "remoteauth" ]; then
|
|
if [ "$2" == "" ] || [ "$3" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$3"; then
|
|
translateRepo "$3"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
echo "You are now required to enter your StarOpenGit credentials. If you are using 2FA, use a Application Token as a password."
|
|
if [ "$4" == "" ]; then
|
|
echo -n "Enter username: "
|
|
read -r "SOSGIT_USERNAME"
|
|
else
|
|
export "SOSGIT_USERNAME=$4"
|
|
fi
|
|
echo -n "Enter password: "
|
|
read -r -s "SOSGIT_PASSWD"
|
|
echo "********"
|
|
git remote remove origin
|
|
formatRemoteRequestString "$SOSGIT_USERNAME" "$SOSGIT_PASSWD" "$2" "$3"
|
|
git remote add origin "$SOSGIT_EXITSTRING"
|
|
echo -e "\nClearing variables containing password"
|
|
export "SOSGIT_PASSWD="
|
|
export "SOSGIT_EXITSTRING="
|
|
echo "Updated remote for repository \"$3\""
|
|
else
|
|
noRepoFound "$3"
|
|
fi
|
|
elif [ "$1" == "selfupdate" ]; then
|
|
echo -e "echo Updating sos-git to \"$0\";$SOSGIT_CURL -sSLqq \"$SOSGIT_UPDATEURL\" &> $0;kill -9 $$" &> $SOSGIT_TMP/sos-git-updater.sh
|
|
chmod +x $SOSGIT_TMP/sos-git-updater.sh
|
|
$SOSGIT_TMP/sos-git-updater.sh
|
|
elif [ "$1" == "list" ]; then
|
|
translateRepo ""
|
|
$SOSGIT_LS -A -h "$SOSGIT_EXITSTRING"
|
|
elif [ "$1" == "remrepo" ]; then
|
|
if [ "$2" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$2"; then
|
|
translateRepo "$2"
|
|
echo "Removing repository \"$2\""
|
|
$SOSGIT_RM -rf "$SOSGIT_EXITSTRING"
|
|
else
|
|
noRepoFound "$2"
|
|
fi
|
|
elif [ "$1" == "upstream" ]; then
|
|
if [ "$2" == "" ] || [ "$3" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$2"; then
|
|
translateRepo "$2"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
if existBranch "$2" "$3"; then
|
|
echo "Pushing new changes and making branch \"$3\" upstream."
|
|
git push "--set-upstream" "origin" "$3"
|
|
else
|
|
noBranchFound "$2" "$3"
|
|
fi
|
|
else
|
|
noRepoFound "$2"
|
|
fi
|
|
elif [ "$1" == "branch" ]; then
|
|
if [ "$2" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$2"; then
|
|
translateRepo "$2"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
git branch
|
|
else
|
|
noRepoFound "$2"
|
|
fi
|
|
elif [ "$1" == "history" ]; then
|
|
if [ "$2" == "" ]; then
|
|
argumentMissing
|
|
fi
|
|
if existRepo "$2"; then
|
|
translateRepo "$2"
|
|
cd "$SOSGIT_EXITSTRING"
|
|
git log
|
|
else
|
|
noRepoFound "$2"
|
|
fi
|
|
elif [ "$1" == "version" ]; then
|
|
echo "sos-git $SOSGIT_VERSION"
|
|
echo "config $SOSGIT_CONFIGVERSION"
|
|
else
|
|
argumentMissing
|
|
fi
|