-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgitlauncher.sh
More file actions
executable file
·157 lines (129 loc) · 4.42 KB
/
gitlauncher.sh
File metadata and controls
executable file
·157 lines (129 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
# Bash Menu Script Example
#https://askubuntu.com/questions/1705/how-can-i-create-a-select-menu-in-a-shell-script
# defines #
#use underscores in these options for better readability
o1="git-gui"
o2="git_change_user"
o3="Software_Update"
o4="Quit"
repo="/home/pi/testrig"
br="-----------------------------------------------------"
options=("$o1" "$o2" "$o3" "$o4") # insert option3 here if needed
function header
{
cd $repo
#clear
echo $br
olduser="$(git config --get user.name)"
echo "git user: $olduser"
echo $br
echo "${options[@]}" # repeat options
}
function replacevariableinfile # variable file new
{
# $1 $2 are fct parameters
new="\"$3\"" # escape the strings
#replacelineafter
rpla="$1="
#replacewith
rpw="$rpla$new"
echo $new
echo $rpla
echo $rpw
# THIS ONLY WORKS WITH DOUBLE QUOTES
# SINGLE QUOTES sed ONLY IS GOOD FOR STRINGS
# AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
sed -i "s,$rpla.*,$rpw," $2
}
# "main" #
header
# PS3: configures the "select" command
PS3='Please enter your choice: '
select opt in "${options[@]}"
do
case $opt in
"$o1")
echo "you chose choice $REPLY which is $opt"
LC_ALL=en_US.utf8 git gui
header
;;
"$o2")
echo "you chose choice $REPLY which is $opt"
cd $repo
olduser="$(git config --get user.name)"
oldmail="$(git config --get user.email)"
echo "please type git username:"
read gusername
echo "please type git email:"
read gemail
rem="$(git config --get remote.origin.url)"
#newurl="${rem/$olduser/$gusername}" this didn't work since its not a convention
echo "old url : $rem"
echo "what do you want to replace here?"
read todo
echo "with what?"
read overwrite
newurl="${rem/$todo/$overwrite}"
#echo "(copy/paste using crtl+SHIFT+C/V in terminal)"
#echo "a text window will open after you press enter"
#read something
#gedit
#echo "please paste new url (editing is horrible here): "
#read newurl
echo ""
echo "old user: $olduser"
echo "old mail: $oldmail"
echo "old url : $rem"
echo ""
echo "new user: $gusername"
echo "new email: $gemail"
echo "new url: $newurl"
echo ""
echo "Is this correct? press Enter to continue, or close window to abort"
read something
# set git credentials global and of this repo
git config --global user.name $gusername
git config --global user.email $gemail
git config remote.origin.url $newurl
# set string in sw_update
# didn't work if thirschb was not last user :(
#sed -i "s/$oldurl/$newurl/g" sw_update.sh
#this only as an effect the first time around
#placeholder="tobereplaced"
# THE / AFTER s DID define its seperator
#sed -i 's/$placeholder/$newurl/g' sw_update.sh
# double quotes required to tell bash to interpret variable as variables
#sed -i "s,$placeholder,$newurl,g" sw_update.sh
#this is regular operation
sed -i "s,$oldurl,$newurl,g" sw_update.sh # quotes outside url
replacevariableinfile "gitrepo" "sw_update.sh" $newurl # variable file new
header
;;
"$o3")
echo "you chose choice $REPLY which is $opt"
#copy software update to desktop and run from there, close this one
#since this script may be updated as well
sw="sw_update.sh"
sw1="$repo/$sw"
desktopsw="/home/pi/Desktop/$sw"
echo $sw1
echo $desktopsw
cp $sw1 $desktopsw # tested: force overwrite works without add. command
echo "please run $sw"
echo "after the successful software update, you will be prompted to delete it"
read something
header
;;
#
# "$o5")
# echo "you chose choice $REPLY which is $opt"
# echo "tough luck, this is not implemented"
# header
# ;;
"$o4")
break
;;
*) echo "invalid option $REPLY";;
esac
done