Changed ~40% of sos-git and added conf version check

This commit is contained in:
JeremyStarTM 2022-08-14 12:20:56 +02:00
parent d703bc631d
commit 3b3b4bb65d

View file

@ -1,82 +1,6 @@
#!/bin/bash #!/bin/bash
function loadDefaultConfiguration() {
export "SOSGIT_CONFIGVERSION=1"
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_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"
}
function loadSystemConfigurationMigrationError() {
echo "Your system configuration files are too old, but can't be reset."
echo "Please update all configuration files to the new version,"
echo "if you still want to use them."
exit "249"
}
function loadSystemConfiguration() {
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 [ -f "/etc/sostools/git/sos-git.conf" ] || [ -d "/etc/sostools/git/sos-git.conf" ]; then
rm -rf "/etc/sostools/git/sos-git.conf"
if [ ! "$?" == "0" ]; then loadSystemConfigurationMigrationError; fi
fi
mv "/etc/sostools/git/sos-git.conf" "/etc/sostools/git/sos-git.conf.bak"
if [ ! "$?" == "0" ]; then loadSystemConfigurationMigrationError; fi
if [ -f "/etc/sostools/git/sos-git.conf.d" ] || [ -d "/etc/sostools/git/sos-git.conf.d" ]; then
rm -rf "/etc/sostools/git/sos-git.conf"
if [ ! "$?" == "0" ]; then loadSystemConfigurationMigrationError; fi
fi
mv "/etc/sostools/git/sos-git.conf.d" "/etc/sostools/git/sos-git.conf.d.bak"
if [ ! "$?" == "0" ]; then loadSystemConfigurationMigrationError; fi
doSystemSetup "force" &> /dev/null
echo "Your system configuration files are too old and have been reset."
echo "A backup is named \"sos-git.conf.bak\" and \"sos-git.conf.d.bak\"."
echo "Please update all configuration files to the new version,"
echo "if you still want to use them."
exit "250"
fi
fi
if [ -d "/etc/sostools/git/sos-git.conf.d/" ]; then
for file in $(/bin/ls -Aw 1 "/etc/sostools/git/sos-git.conf.d/");do
source "/etc/sostools/git/sos-git.conf.d/${file}"
done
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
mv "$HOME/.sostools/git/sos-git.conf" "$HOME/.sostools/git/sos-git.conf.bak"
mv "$HOME/.sostools/git/sos-git.conf.d" "$HOME/.sostools/git/sos-git.conf.d.bak"
doUserSetup "force" &> /dev/null
echo "Your user configuration files are too old and have been reset."
echo "A backup is named \"sos-git.conf.bak\" and \"sos-git.conf.d.bak\"."
echo "Please update all configuration files to the new version,"
echo "if you still want to use them."
exit "251"
fi
fi
if [ -d "$HOME/.sostools/git/sos-git.conf.d/" ]; then
for file in $(/bin/ls -Aw 1 "$HOME/.sostools/git/sos-git.conf.d/");do
source "$HOME/.sostools/git/sos-git.conf.d/${file}"
done
fi
}
function getDefaultConfiguration() { function getDefaultConfiguration() {
# SOSGIT_CONFIGVERSION=1 # SOSGIT_CONFIGVERSION=4
# # sos-git configuration\n # # sos-git configuration\n
# # this is the default configuration, you\n # # this is the default configuration, you\n
# # may make changes in sos-git.conf.d\n # # may make changes in sos-git.conf.d\n
@ -113,6 +37,34 @@ function getDefaultConfiguration() {
# ## coreutils, otherwise it may not\n # ## coreutils, otherwise it may not\n
# ## work correctly with sos-git.\n # ## work correctly with sos-git.\n
# #SOSGIT_LS=/bin/ls\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
# ## 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
# ## 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 # \n
# # Title\n # # Title\n
# ## Suppress\n # ## Suppress\n
@ -167,29 +119,141 @@ function getDefaultConfiguration() {
# ## second %s is password, third %s is user and\n # ## second %s is password, third %s is user and\n
# ## fourth %s is the repository.\n # ## fourth %s is the repository.\n
# ## NO TRAILING SLASH AT THE END!\n # ## NO TRAILING SLASH AT THE END!\n
# #SOSGIT_REQUESTSTRING_REMOTE=https://%s:%s@staropensource.ddns.net/%s/%s # #SOSGIT_REQUESTSTRING_REMOTE=https://%s:%s@staropensource.ddns.net/%s/%s\n
export "SOSGIT_EXITSTRING=SOSGIT_CONFIGVERSION=1\n# 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## 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# 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/master/sos-git.sh\n## 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/master/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.\n## 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=4\n# 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## 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/master/sos-git.sh\n## 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/master/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.\n## 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# No root warning\n## DEFAULT: false\n## Disables the root warning\n#SOSGIT_NOROOTWARNING=false\n"
return "0" return "0"
} }
function loadDefaultConfiguration() {
export "SOSGIT_CONFIGVERSION=4"
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 "Please update all configuration files to the new version,"
# echo "if you still want to use them."
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.bak" "/etc/sostools/git/sos-git.conf.d.bak" &> /dev/null
$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."
#echo "A backup is named \"sos-git.conf.bak\" and \"sos-git.conf.d.bak\"."
#echo "Please update all configuration files to the new version,"
#echo "if you still want to use them."
exit "250"
else
loadSystemConfigurationMigrationError
fi
fi
else
getDefaultConfiguration
echo -e "$SOSGIT_EXITSTRING" &> /etc/sostools/git/sos-git.conf
fi
if [ -d "/etc/sostools/git/sos-git.conf.d/" ]; then
for file in $(/bin/ls -Aw 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
#$SOSGIT_RM "$HOME/.sostools/git/sos-git.conf.bak" "$HOME/.sostools/git/sos-git.conf.d.bak" &> /dev/null
#$SOSGIT_MV "$HOME/.sostools/git/sos-git.conf" "$HOME/.sostools/git/sos-git.conf.bak" &> /dev/null
#$SOSGIT_MV "$HOME/.sostools/git/sos-git.conf.d" "$HOME/.sostools/git/sos-git.conf.d.bak" &> /dev/null
doUserSetup "force+noinfo"
echo "Your user configuration file is too old and has been reset."
#echo "A backup is named \"sos-git.conf.bak\" and \"sos-git.conf.d.bak\"."
#echo "Please update all configuration files to the new version,"
#echo "if you still want to use them."
exit "251"
fi
fi
if [ -d "$HOME/.sostools/git/sos-git.conf.d/" ]; then
for file in $(/bin/ls -Aw 1 "$HOME/.sostools/git/sos-git.conf.d/");do
source "$HOME/.sostools/git/sos-git.conf.d/${file}"
done
fi
}
function doUserSetup() { function doUserSetup() {
if [ "$1" == "force" ] || [ ! "$SOSGIT_SETUP_USER" == "true" ]; then if [ "$1" == "force" ] || [ "$1" == "force+noinfo" ] || [ ! "$SOSGIT_SETUP_USER" == "true" ]; then
echo "Starting user setup" if [ "$1" == "force+noinfo" ] || [ "$1" == "noinfo" ]; then
mkdir "$HOME/.sostools/git/sos-git.conf.d" -p echo -n ""
else
echo "Writing user configuration"
fi
$SOSGIT_MKDIR "$HOME/.sostools/git/sos-git.conf.d" -p
getDefaultConfiguration getDefaultConfiguration
echo -e "$SOSGIT_EXITSTRING" &> $HOME/.sostools/git/sos-git.conf 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 echo -e "# DO NOT DELETE OR MODIFY THIS FILE\nSOSGIT_SETUP_USER=true" &> $HOME/.sostools/git/sos-git.conf.d/setup.conf
echo "Applying new changes" $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 loadUserConfiguration
fi fi
} }
function doSystemSetup() { function doSystemSetup() {
if [ "$1" == "force" ] || [ ! "$SOSGIT_SETUP_SYSTEM" == "true" ] && [ "$(whoami)" == "root" ]; then if [ "$1" == "force" ] || [ "$1" == "force+noinfo" ] || [ ! "$SOSGIT_SETUP_SYSTEM" == "true" ] && [ "$(whoami)" == "root" ]; then
echo "Starting system setup" if [ "$1" == "force+noinfo" ] || [ "$1" == "noinfo" ]; then
mkdir "/etc/sostools/git/sos-git.conf.d" -p echo -n ""
else
echo "Writing system configuration"
fi
$SOSGIT_MKDIR "/etc/sostools/git/sos-git.conf.d" -p
getDefaultConfiguration getDefaultConfiguration
echo -e "$SOSGIT_EXITSTRING" &> /etc/sostools/git/sos-git.conf 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 echo -e "# DO NOT DELETE OR MODIFY THIS FILE\nSOSGIT_SETUP_SYSTEM=true" &> /etc/sostools/git/sos-git.conf.d/setup.conf
echo "Applying new changes" if [ "$1" == "force+noinfo" ] || [ "$1" == "noinfo" ]; then
echo -n ""
else
echo "Applying new system configuration"
fi
loadSystemConfiguration loadSystemConfiguration
fi fi
} }
@ -198,12 +262,12 @@ function doRepositorySetup() {
return "0" return "0"
elif [ -f "$SOSGIT_REPOS" ]; then elif [ -f "$SOSGIT_REPOS" ]; then
echo "Moving \"$SOSGIT_REPOS\" to \"$SOSGIT_REPOS.bak\"" echo "Moving \"$SOSGIT_REPOS\" to \"$SOSGIT_REPOS.bak\""
mv "$SOSGIT_REPOS" "$SOSGIT_REPOS.bak" $SOSGIT_MV "$SOSGIT_REPOS" "$SOSGIT_REPOS.bak"
echo "Creating repository save directory" echo "Creating repository save directory"
mkdir -p "$SOSGIT_REPOS" $SOSGIT_MKDIR -p "$SOSGIT_REPOS"
else else
echo "Creating repository save directory" echo "Creating repository save directory"
mkdir -p "$SOSGIT_REPOS" $SOSGIT_MKDIR -p "$SOSGIT_REPOS"
fi fi
} }
loadDefaultConfiguration loadDefaultConfiguration
@ -231,14 +295,14 @@ function formatRequestString() {
# dont noodle me that I shouldve used -v var. I tried, it didnt work. yes i did typos to fuck you off. # 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 printf "$SOSGIT_REQUESTSTRING" "$1" "$2" &> ${SOSGIT_TMP}/formatrequeststring
export "SOSGIT_EXITSTRING=$(cat ${SOSGIT_TMP}/formatrequeststring)" export "SOSGIT_EXITSTRING=$(cat ${SOSGIT_TMP}/formatrequeststring)"
rm -rf "${SOSGIT_TMP}/formatrequeststring" $SOSGIT_RM -rf "${SOSGIT_TMP}/formatrequeststring"
return return
} }
function formatRemoteRequestString() { function formatRemoteRequestString() {
# same here as in formatRequestString() # same here as in formatRequestString()
printf "$SOSGIT_REQUESTSTRING_REMOTE" "$1" "$2" "$3" "$4" &> ${SOSGIT_TMP}/formatremoterequeststring printf "$SOSGIT_REQUESTSTRING_REMOTE" "$1" "$2" "$3" "$4" &> ${SOSGIT_TMP}/formatremoterequeststring
export "SOSGIT_EXITSTRING=$(cat ${SOSGIT_TMP}/formatremoterequeststring)" export "SOSGIT_EXITSTRING=$(cat ${SOSGIT_TMP}/formatremoterequeststring)"
rm -rf "${SOSGIT_TMP}/formatremoterequeststring" $SOSGIT_RM -rf "${SOSGIT_TMP}/formatremoterequeststring"
return return
} }
function existRepoOnline() { function existRepoOnline() {
@ -280,6 +344,21 @@ function existBranch() {
function noBranchFound() { function noBranchFound() {
echo "ERROR: Branch \"$2\" in repository \"$1\" does not exist." 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 $(ls --color=never -w 1 "$1"); do
if [ "$SOSGIT_EXITSTRING" == "" ]; then
export "SOSGIT_EXITSTRING=$(ls --color=never -w 1 $(pwd)/$file)"
else
export "SOSGIT_EXITSTRING= $(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_SUPPRESS" == "true" ]; then
if [ ! "$SOSGIT_TITLE_TEXT" == "true" ]; then if [ ! "$SOSGIT_TITLE_TEXT" == "true" ]; then
# _ _ # _ _
@ -393,13 +472,15 @@ elif [ "$1" == "editconf" ]; then
if [ "$2" == "true" ]; then if [ "$2" == "true" ]; then
if [ "$(whoami)" == "root" ]; then if [ "$(whoami)" == "root" ]; then
collectFiles "/etc/sostools/git/sos-git.conf.d/" 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 $SOSGIT_EDITOR "/etc/sostools/git/sos-git.conf" $SOSGIT_EXITSTRING
else else
echo "ERROR: You aren't root." echo "ERROR: You aren't root."
exit "2" exit "2"
fi fi
elif [ "$2" == "false" ]; then elif [ "$2" == "false" ]; then
collectFiles "$HOME/.sostools/git/sos-git.conf" 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 $SOSGIT_EDITOR "$HOME/.sostools/git/sos-git.conf" $SOSGIT_EXITSTRING
else else
echo "ERROR: Invalid boolean." echo "ERROR: Invalid boolean."
@ -503,7 +584,7 @@ elif [ "$1" == "remrepo" ]; then
if existRepo "$2"; then if existRepo "$2"; then
translateRepo "$2" translateRepo "$2"
echo "Removing repository \"$2\"" echo "Removing repository \"$2\""
rm -rf "$SOSGIT_EXITSTRING" $SOSGIT_RM -rf "$SOSGIT_EXITSTRING"
else else
noRepoFound "$2" noRepoFound "$2"
fi fi