@@ -108,6 +108,43 @@ setup_ssh() {
108108 return 0
109109}
110110
111+ init_schedule () {
112+ if [[ -z ${TIME_UNIT+x} ]]
113+ then
114+ log_msg " Something went wrong during schedule initialization"
115+ exit 1
116+ else
117+ if [[ $SCHEDULED_BACKUPS -eq 1 ]]
118+ then
119+ case $TIME_UNIT in
120+ h)
121+ INTERVAL=" OnCalendar=*-*-* 01/${BACKUP_INTERVAL} :00:00"
122+ PERSISTENT=" true"
123+ ;;
124+ d)
125+ INTERVAL=" OnCalendar=*-*-01/${BACKUP_INTERVAL} 00:00:00"
126+ PERSISTENT=" true"
127+ ;;
128+ m)
129+ INTERVAL=" OnCalendar=*-01/${BACKUP_INTERVAL} -* 00:00:00"
130+ PERSISTENT=" true"
131+ ;;
132+ * )
133+ log_msg " Misconfiguration in backup interval"
134+ log_msg " Please specify a valid timespan"
135+ log_msg " Available are h(ours), d(ays) and m(onths)"
136+ log_msg " Falling back to daily backup"
137+ INTERVAL=" OnCalendar=*-*-*/${BACKUP_INTERVAL} 00:00:00"
138+ PERSISTENT=" true"
139+ ;;
140+ esac
141+ else
142+ INTERVAL=" OnBootSec=3min"
143+ PERSISTENT=" false"
144+ fi
145+ fi
146+ }
147+
111148install () {
112149 success_msg " Installing"
113150 chmod +x " ${SCRIPTPATH} /" * .sh
@@ -116,7 +153,7 @@ install() {
116153 then
117154 error_msg " Git is not installed"
118155 info_msg " Installing..."
119- " ${SCRIPTPATH} /install-git.sh "
156+ install_git
120157 else
121158 GIT_VERSION=$( git --version | cut -b 13- | sed -e ' s/\.//g' )
122159 if [[ $GIT_VERSION -lt 2280 ]]
@@ -138,6 +175,7 @@ install() {
138175 mkdir -p " $HOME /kgb-log"
139176 git config --global user.email " $GITHUB_MAIL "
140177 git config --global user.name " $GITHUB_USER "
178+ git config --global init.defaultBranch " $GITHUB_BRANCH "
141179 for i in ${! REPO_LIST[@]}
142180 do
143181 if [[ -d " ${CONFIG_FOLDER_LIST[$i]} /.git" ]]
@@ -164,9 +202,32 @@ install() {
164202 echo " $SERVICE_FILE " >> " ${SCRIPTPATH} /kgb.service"
165203 sudo mv " ${SCRIPTPATH} /kgb.service" /etc/systemd/system/kgb.service
166204 sudo chown root:root /etc/systemd/system/kgb.service
205+ sudo chmod 644 /etc/systemd/system/kgb.service
167206 sudo systemctl enable kgb.service
168- sudo systemctl start kgb.service
207+ # sudo systemctl start kgb.service
208+ fi
209+ if [[ -f /etc/systemd/system/kgb.timer ]]
210+ then
211+ info_msg " Schedule was already set up"
212+ info_msg " Disabling the schedule temporarily"
213+ sudo systemctl stop kgb.timer
214+ sudo systemctl disable kgb.timer
215+ info_msg " Updating the schedule"
216+ else
217+ info_msg " Setting up the schedule"
169218 fi
219+ init_schedule
220+ echo " $SERVICE_TIMER " >> " ${SCRIPTPATH} /kgb.timer"
221+ sleep 1
222+ sed -i " s|replace_interval|${INTERVAL} |g" " ${SCRIPTPATH} /kgb.timer"
223+ sed -i " s|replace_persist|${PERSISTENT} |g" " ${SCRIPTPATH} /kgb.timer"
224+ sudo mv " ${SCRIPTPATH} /kgb.timer" /etc/systemd/system/kgb.timer
225+ sudo chown root:root /etc/systemd/system/kgb.timer
226+ sudo chmod 644 /etc/systemd/system/kgb.timer
227+ info_msg " Enabling the schedule"
228+ sudo systemctl daemon-reload
229+ sudo systemctl enable kgb.timer
230+ sudo systemctl start kgb.timer
170231 success_msg " Installation complete"
171232 read -p " $( echo -e " ${CYAN} Press enter to continue ${NC} " ) " CONTINUE
172233}
0 commit comments