-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_setup_oss.sh
executable file
·176 lines (158 loc) · 5.38 KB
/
run_setup_oss.sh
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
#= run_setup_oss.sh
if [ ! -d "$HOME/opensyssetup/" ]; then
echo "# error: this run_setup_oss.sh scripts can only be used if directory '$HOME/opensyssetup/' exists .. "
exit 1;
fi
MYUID=$( id -u )
# 100x for user, 0 for root
echo "# UID is ${MYUID} "
# usage: if [ "${MYUID}" == 0 ]; then echo "# detect root user" ; fi
#LOGNAME <== is bash built-in
# e.g.: "jdg"
IS_DEBIAN_DERIVATIVE="$(which dpkg 2>/dev/null)"
# for Debian derivatives: "/usr/bin/dpkg"
# usage: if [ "${IS_DEBIAN_DERIVATIVE}" ]; then echo "# detected Debian derivative" ; fi
# - - -
# determine platform:
case "$(uname -s)" in
Darwin) PLAT='MacOS' ;;
Linux) PLAT='Linux' ;;
CYGWIN*|MINGW32*|MSYS*|MINGW*) PLAT='Windows' ;;
*) PLAT='Unknown' ;;
esac
echo "# detected platform '${PLAT}' "
# usage: if [ "${PLAT}" == "Linux" ]; then echo "# detected Linux" ; fi
# - - -
echo "# running $HOME/opensyssetup/bin/write_distro_file.sh .."
. $HOME/opensyssetup/bin/write_distro_file.sh
# - - -
echo "# copy default \$HOME/.vimrc .."
SOURCE="$HOME/opensyssetup/debian/root/dot.vimrc"
TARGET="$HOME/.vimrc"
[ -f $TARGET ] && cp -a $TARGET $TARGET.back
cp -v $SOURCE $TARGET
# - - -
if [ "${IS_DEBIAN_DERIVATIVE}" ]; then
echo "# manually install these packages: "
echo "# > sudo apt install -y git curl htop lsof vim apt-transport-https ca-certificates curl gnupg lsb-release "
echo
fi
if [ "${PLAT}" == "Linux" ]; then
if [ "${MYUID}" == 0 ]; then
SFILE="cp-jdg-Xauthority.sh"
cd $HOME
rm $SFILE
ln -s ./opensyssetup/bin/$SFILE .
echo "# created symlink ./opensyssetup/bin/$SFILE $SFILE .."
fi
fi
DIR="$HOME/syssetup"
if [ -L ${DIR} ]; then
rm ${DIR}
echo "# removed symlink ${DIR} .."
fi
#FILE="$HOME/.bashrc"
#BASHRC="$HOME/.bashrc"
#
#if [ -f "${BASHRC}" ]; then
# if [ "${PLAT}" == "Linux" ]; then
# sed -i 's/^.*colorprompt.sh.*$//' ${BASHRC}
# sed -i 's/^.*syssetup.*$/# &/' ${BASHRC}
# sed -i '/^(#\s*|\s*)$/d' ${BASHRC}
# echo -e "\nsource \$HOME/opensyssetup/colorprompt.sh \n" >> $BASHRC
# # ln -sf /usr/local/opensyssetup/linux/etc/colorprompt.sh /etc/colorprompt.sh
# # echo -e "\n#\n. /etc/colorprompt.sh\n" >> ~/.bashrc
# # echo -e "\n#\n. /etc/colorprompt.sh\n" >> /etc/skel/.bashrc
# # echo -e "\n#\n. /etc/colorprompt.sh\n" >> /home/jdg/.bashrc
# echo "# add source-command in ${BASHRC} "
# fi
#fi
BASHRC="$HOME/.bashrc"
touch $BASHRC
if [ "${PLAT}" == "Linux" ]; then
# remove this line: . $HOME/syssetup/colorprompt.sh
sed -i 's/^.*colorprompt\.sh.*$/# &/' ${BASHRC}
#sed -i 's/^.*syssetup.*$/# &/' ${BASHRC}
#sed -i "" '/^(#\s*|\s*)$/d' ${BASHRC}
#
echo -e "\nsource \$HOME/opensyssetup/colorprompt.sh \n" >> $BASHRC
#
#echo -e "\n\$HOME/opensyssetup/bin/write_distro_file.sh \n" >> $BASHRC
#echo -e "source \$HOME/opensyssetup/colorprompt.sh \n" >> $BASHRC
#
echo "# added source-command in ${BASHRC} .."
fi
# https://stackoverflow.com/questions/19670061/bash-if-false-returns-true-instead-of-false-why
#f true ; then # ----- NOT: if [ -f "${BASHRC}" ]; then
#
if [ "${PLAT}" == "MacOS" ]; then
#
sed -i "" 's/^.*colorprompt.sh.*$//' ${BASHRC}
#sed -i "" 's/^.*syssetup.*$/# &/' ${BASHRC}
#sed -i "" '/^(#\s*|\s*)$/d' ${BASHRC}
echo -e "\nsource \$HOME/opensyssetup/colorprompt.sh \n" >> $BASHRC
echo "# add source-command in ${BASHRC} "
#
DIR="$HOME/bin"
if [ -L ${DIR} ]; then
rm ${DIR}
ln -s opensyssetup/mac/bin/ ${DIR}
echo "# symlink opensyssetup/mac/bin/ to ${DIR} "
fi
#ln -sf /usr/local/opensyssetup/mac/bin/colorprompt.sh /etc/colorprompt.sh
#echo "\n#\n. /etc/colorprompt.sh\n" >> /etc/profile
#
#PROFILE="$HOME/.profile"
BASH_PROFILE="$HOME/.bash_profile"
#
touch ${BASH_PROFILE}
sed -i "" 's/^.*bashrc.*$/# &/' ${BASH_PROFILE}
echo -e "# .bash_profile \nif [ -r ~/.bashrc ]; then source ~/.bashrc ; fi \n# \n" >> ${BASH_PROFILE}
echo "# added source-command in .bash_profile .."
#
fi
# on Mac do:
#
# > cat <<HERE > $HOME/.bash_profile
# # .bash_profile
# # https://securitronlinux.com/debian-testing/how-to-get-mac-os-to-read-the-bashrc-file-on-every-login/
# if [ -s ~/.bashrc ]; then source ~/.bashrc; fi
# #-EOF
# HERE
#
# or:
# echo -e "# .bash_profile \nif [ -r ~/.bashrc ]; then source ~/.bashrc fi \n# \n"
ODIR="/usr/local/syssetup"
NDIR="/usr/local/_syssetup"
if [ -d "${ODIR}" ]; then
if [ "${MYUID}" == 0 ]; then
mv ${ODIR} ${NDIR}
echo "# renamed ${ODIR} to ${NDIR} "
fi
fi
# - - -
if [ "${LOGNAME}" == "jdg" ]; then
#
#git config --global user.name "John de Graaff"
#git config --global user.email [email protected]
#git config --global alias.ss "status -s" # short status
#git config --global alias.logg "log --oneline --decorate --graph --all --pretty=format:'%C(auto)%h %aD %d %s'"
#git config --global alias.logn "log --oneline --decorate --graph --all --pretty=format:'%h - %ae - %ad : %s' --numstat"
# or:
~/opensyssetup/bin/git-config-jdg.sh
#
# will set in this file: ~/.gitconfig
# [user]
# name = John de Graaff
# email = [email protected]
# [alias]
# ss = status -s
# logg = log --oneline --decorate --graph --all --pretty=format:'%C(auto)%h %aD %d %s'
# logn = log --oneline --decorate --graph --all --pretty=format:'%h - %ae - %ad : %s' --numstat
#
echo "# set git config for user jdg "
#
fi
# - - -
#-EOF