-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpip_script.sh
More file actions
63 lines (52 loc) · 1.36 KB
/
pip_script.sh
File metadata and controls
63 lines (52 loc) · 1.36 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
#! /bin/bash
function verbose_log {
local MEN=$1
local LEVEL_MEN=$2
if (($LEVEL_MEN == 1))
then
echo "ERROR:$MEN" >> $WORK_LOG
else
echo "INFO:$MEN" >> $WORK_LOG
fi
}
readonly INFO=0
readonly ERROR=1
readonly CONFIG_FILE="/etc/Pip_Updater/pip_updater.conf"
readonly WORK_LOG="/tmp/pip_updater.log"
echo "--------------------------$(date +%y-%m-%d)---------------------------" >> $WORK_LOG
if [ ! -s $CONFIG_FILE ]
then
verbose_log "CONFIG_FILE is not settled!" $ERROR
verbose_log "Leaving the program" $INFO
exit
elif (($(id -u) != 0 ))
then
verbose_log "Script ins't running as superuser!" $ERROR
verbose_log "Leaving the program" $INFO
exit
fi
declare -a UPDATE_LIST
counter=0
for PROGRAM_PIP in $(cat $CONFIG_FILE | grep -v "#.*")
do
if pip -q show $PROGRAM_PIP
then
UPDATE_LIST[$counter]=$PROGRAM_PIP
counter=$(($counter + 1))
verbose_log "$PROGRAM_PIP is marked to be updated" $INFO
else
verbose_log "$PROGRAM_PIP does not exist! Ignoring..." $ERROR
fi
done
verbose_log "Starting update process" $INFO
for UPDATE_PROGRAM in ${UPDATE_LIST[*]}
do
verbose_log "The $UPDATE_PROGRAM will be updated now" $INFO
if pip -q install $UPDATE_PROGRAM --upgrade
then
verbose_log "$UPDATE_PROGRAM was sucessfully updated" $INFO
else
verbose_log "$UPDATE_PROGRAM was not updated, something went wrong" $ERROR
fi
done
verbose_log "End of the workload" $INFO