Skip to content

Commit d7d6363

Browse files
committed
Revert "ref RobertLucian#2 : hotfix - removed sudoes from all .sh"
This reverts commit e347d91.
1 parent e347d91 commit d7d6363

3 files changed

Lines changed: 39 additions & 39 deletions

File tree

functions_library.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
##############################################################
22
##############################################################
3-
#
4-
# A SERIES OF HELPER FUNCTIONS TO HELP OUT IN
3+
#
4+
# A SERIES OF HELPER FUNCTIONS TO HELP OUT IN
55
# HANDLING SCRIPTS THAT ARE GROWING IN COMPLEXITY
66
#
77
##############################################################
@@ -41,17 +41,17 @@ feedback() {
4141
change_branch() {
4242
# first and only parameter is the branch to checkout
4343

44-
# -z tests for zero length.
45-
if [ -z ${1+x} ]; then
46-
echo "Working from main branch.";
47-
else
44+
# -z tests for zero length.
45+
if [ -z ${1+x} ]; then
46+
echo "Working from main branch.";
47+
else
4848
echo "Working from $1 branch";
4949
# sudo git checkout -b $BRANCH
5050
# the -b creates a branch if it doesn't exist
5151
# this leads to a fatal error msg being displayed to the user
5252
# is there any case where we can to create the branch here???
5353
# https://github.com/tldr-pages/tldr/blob/master/pages/common/git-checkout.md
54-
git checkout $1
54+
sudo git checkout $1
5555
fi
5656
}
5757

@@ -61,12 +61,12 @@ change_branch() {
6161
#
6262
#########################################################################
6363
delete_line_from_file() {
64-
# first parameter is the string to be matched
64+
# first parameter is the string to be matched
6565
# the lines that contain that string will get deleted
6666
# second parameter is the filename
6767
if [ -f $2 ]
6868
then
69-
sed -i "/$1/d" $2
69+
sudo sed -i "/$1/d" $2
7070
fi
7171
}
7272

@@ -77,7 +77,7 @@ insert_before_line_in_file() {
7777

7878
if [ -f $3 ]
7979
then
80-
sed -i "/$2/i $1" $3
80+
sudo sed -i "/$2/i $1" $3
8181
fi
8282
}
8383

@@ -87,7 +87,7 @@ add_line_to_end_of_file() {
8787
if [ -f $2 ]
8888
then
8989
echo "$1" >> "$2"
90-
fi
90+
fi
9191
}
9292

9393
replace_first_this_with_that_in_file() {
@@ -97,7 +97,7 @@ replace_first_this_with_that_in_file() {
9797
# third parameter is the filename
9898
if grep -q "$1" $3
9999
then
100-
sed -i "s/$1/$2/" "$3"
100+
sudo sed -i "s/$1/$2/" "$3"
101101
return 0
102102
else
103103
#feedback "Line - $1 not found"
@@ -114,7 +114,7 @@ replace_all_this_with_that_in_file(){
114114
#feedback "replacing $1 with $2 in $3"
115115
if file_exists "$3"
116116
then
117-
sed -i "s/$1/$2/g" "$3"
117+
sudo sed -i "s/$1/$2/g" "$3"
118118
return 0
119119
else
120120
return 1
@@ -187,7 +187,7 @@ delete_file (){
187187
# One parameter only: the file to delete
188188
if file_exists "$1"
189189
then
190-
rm "$1"
190+
sudo rm "$1"
191191
fi
192192
}
193193

@@ -214,7 +214,7 @@ wget_file() {
214214
create_folder(){
215215
if ! folder_exists "$1"
216216
then
217-
mkdir "$1"
217+
sudo mkdir "$1"
218218
fi
219219
}
220220

@@ -233,6 +233,6 @@ folder_exists(){
233233
delete_folder(){
234234
if folder_exists "$1"
235235
then
236-
rm -r "$1"
236+
sudo rm -r "$1"
237237
fi
238238
}

install_avrdude.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ create_avrdude_folder(){
55
AVRDUDE_DIR='/home/pi/Dexter/lib/AVRDUDE'
66
if [ -d "$AVRDUDE_DIR" ]; then
77
echo $AVRDUDE_DIR" Found!"
8-
else
8+
else
99
DIRECTORY='/home/pi/Dexter'
1010
if [ -d "$DIRECTORY" ]; then
1111
# Will enter here if $DIRECTORY exists, even if it contains spaces
@@ -23,7 +23,7 @@ create_avrdude_folder(){
2323
echo "creating "$DIRECTORY
2424
mkdir $DIRECTORY
2525
fi
26-
26+
2727
pushd $DIRECTORY
2828
git clone https://github.com/DexterInd/AVRDUDE.git
2929
popd
@@ -35,36 +35,36 @@ install_avrdude(){
3535
FILENAME=tmpfile.txt
3636
AVRDUDE_VER=5.10
3737
avrdude -v &> $FILENAME
38-
38+
3939
#Only install avrdude 5.1 if it does not exist
40-
if grep -q $AVRDUDE_VER $FILENAME
40+
if grep -q $AVRDUDE_VER $FILENAME
4141
then
4242
echo "avrdude" $AVRDUDE_VER "Found"
4343
else
4444
echo "avrdude" $AVRDUDE_VER "Not Found,Installing avrdude now"
4545
create_avrdude_folder
46-
46+
4747
##########################################
4848
#Installing AVRDUDE
4949
##########################################
5050
pushd /home/pi/Dexter/lib/AVRDUDE/avrdude
51-
51+
5252
# Install the avrdude deb package
5353
# No need to wget since files should be there in the avrdude folder
5454
# wget https://github.com/DexterInd/AVRDUDE/raw/master/avrdude/avrdude_5.10-4_armhf.deb
55-
dpkg -i avrdude_5.10-4_armhf.deb
56-
chmod 4755 /usr/bin/avrdude
57-
58-
# Setup config files
55+
sudo dpkg -i avrdude_5.10-4_armhf.deb
56+
sudo chmod 4755 /usr/bin/avrdude
57+
58+
# Setup config files
5959
# wget http://project-downloads.drogon.net/gertboard/setup.sh
6060
chmod +x setup.sh
61-
./setup.sh
62-
61+
sudo ./setup.sh
62+
6363
# pushd /etc/minicom
6464
# sudo wget http://project-downloads.drogon.net/gertboard/minirc.ama0
6565
# sudo sed -i '/Exec=arduino/c\Exec=sudo arduino' /usr/share/applications/arduino.desktop
6666
echo " "
6767
popd
6868
fi
69-
rm $FILENAME
69+
rm $FILENAME
7070
}

update_wiringpi.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ LIB=lib
88

99
# Check if WiringPi Installed and has the latest version. If it does, skip the step.
1010
# Gets the version of wiringPi installed
11-
version=`gpio -v`
11+
version=`gpio -v`
1212

1313
# Parses the version to get the number
14-
set -- $version
14+
set -- $version
1515

1616
# Gets the third word parsed out of the first line of gpio -v returned.
1717
# Should be 2.36
18-
WIRINGVERSIONDEC=$3
18+
WIRINGVERSIONDEC=$3
1919

2020
# Store to temp file
21-
echo $WIRINGVERSIONDEC >> tmpversion
21+
echo $WIRINGVERSIONDEC >> tmpversion
2222

2323
# Remove decimals
24-
VERSION=$(sed 's/\.//g' tmpversion)
24+
VERSION=$(sed 's/\.//g' tmpversion)
2525

2626
# Remove the temp file
27-
delete_file tmpversion
27+
delete_file tmpversion
2828

2929
feedback "wiringPi VERSION is $VERSION"
3030
if [ $VERSION -eq '236' ]; then
@@ -38,13 +38,13 @@ else
3838

3939
# Change directories to Dexter/lib
4040
cd $PIHOME/$DEXTER/$LIB
41-
42-
delete_folder wiringPi
41+
42+
delete_folder wiringPi
4343
# Install wiringPi
4444
git clone https://github.com/DexterInd/wiringPi/ # Clone directories to Dexter.
4545
cd wiringPi
46-
chmod +x ./build
47-
./build
46+
sudo chmod +x ./build
47+
sudo ./build
4848
feedback "wiringPi Installed"
4949
fi
5050
# End check if WiringPi installed

0 commit comments

Comments
 (0)