-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare.sh
executable file
·199 lines (175 loc) · 5.8 KB
/
prepare.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
UPDATE_SYS=1
CHECK_UBUNTU=1
UPDATE_ALIASES=0
UBUNTU=0
INSTALL_PPA=0
SKIP_PPA=0
REBOOT=1
PPA_INSTALLED=0
DEBUG=0
PKG_LIST=("vim" "htop" "git-lfs" "powertop" "acpica-tools" "efitools")
pushd $SCRIPT_DIR
if [ -d .git ]; then
./install.sh git
git reset --hard HEAD
git restore .
git fetch --all
git pull --rebase
git submodule update --init --recursive --checkout
fi
if [ ! -f ~/.local/bin/apt-proxy ]; then
mkdir -p ~/.local/bin
cp apt-proxy ~/.local/bin/
fi
if [ ! -d ~/.bash_completion.d ]; then
mkdir -p ~/.bash_completion.d
fi
if [ ! -f ~/.bash_completion.d/apt-proxy ]; then
cp /usr/share/bash-completion/completions/apt ~/.bash_completion.d/apt-proxy
if [ $(grep -c apt-proxy ~/.bash_completion.d/apt-proxy) -eq 0 ]; then
sed -i 's/complete -F _apt apt/complete -F _apt apt-proxy/' ~/.bash_completion.d/apt-proxy
fi
fi
if [ $(grep -c "~/\.bash_completion\.d" ~/.bashrc) -eq 0 ]; then
echo -e "if [ -d ~/.bash_completion.d ]; then\n for f in ~/.bash_completion.d/*; do\n . \"\$f\"\n done\nfi" >> ~/.bashrc
fi
if [ -f ~/.zshrc ]; then
if [ $(grep -c "~/\.bash_completion\.d" ~/.zshrc) -eq 0 ]; then
echo -e "if [ -d ~/.bash_completion.d ]; then\n for f in ~/.bash_completion.d/*; do\n . \"\$f\"\n done\nfi" >> ~/.zshrc
fi
fi
PATH="$HOME/.local/bin:$PATH"
while getopts "npsud" option; do
case $option in
n) # skip reboot
REBOOT=0;;
p) # skip ppa
SKIP_PPA=1;;
s) # Skip updating the system
CHECK_UBUNTU=0
UPDATE_SYS=0;;
u) # update the aliases file
UPDATE_ALIASES=1;;
d) # don't remove temp diff file
DEBUG=1;;
\?) # Invalid option
echo "Error: Invalid option"
exit 1;;
esac
done
# Check and set timezone to Denver if not already set
if command -v timedatectl >/dev/null 2>&1; then
CURRENT_TZ=$(timedatectl show -p Timezone --value)
if [ "$CURRENT_TZ" != "America/Denver" ]; then
echo "Timezone is not set to America/Denver. Setting timezone to America/Denver."
sudo timedatectl set-timezone America/Denver
else
echo "Timezone is already set to America/Denver."
fi
else
echo "timedatectl command not found. Cannot check or set timezone."
fi
if [ $CHECK_UBUNTU -eq 1 ]; then
if grep -q "Ubuntu" /etc/os-release; then
UBUNTU=1
fi
fi
if grep -R --include '*.list' '^deb.*ppa.launchpad.net/system76-dev/stable' /etc/apt/; then
PPA_INSTALLED=1
fi
if [ $UBUNTU -eq 1 ] && [ $PPA_INSTALLED -eq 0 ]; then
UPDATE_SYS=0
REBOOT=0
INSTALL_PPA=1
fi
if [ $SKIP_PPA -gt 0 ]; then
INSTALL_PPA=0
fi
if [ $UBUNTU -eq 0 ] && [ $PPA_INSTALLED -eq 1 ] && [ $SKIP_PPA -eq 0 ]; then
PKG_LIST+=("system76-firmware")
PKG_LIST+=("system76-firmware-daemon")
fi
if [ $UPDATE_SYS -eq 1 ]; then
until apt-proxy update
do
sleep 1
done
apt-proxy full-upgrade -y --allow-downgrades
apt-proxy autoremove -y
fi
# Determine the location of the current script to get the path of the new aliases file
NEW_ALIASES_PATH="${SCRIPT_DIR}/bash_aliases"
if [ -e $NEW_ALIASES_PATH ]; then
sed -i "s|\./install\.sh|${SCRIPT_DIR}/install.sh|g" ${SCRIPT_DIR}/bash_aliases
sed -i "s|\./terminal\.sh|${SCRIPT_DIR}/terminal.sh|g" ${SCRIPT_DIR}/bash_aliases
sed -i "s|\./check-needrestart\.sh|${SCRIPT_DIR}/check-needrestart.sh|g" ${SCRIPT_DIR}/bash_aliases
# Check if ~/.bash_aliases exists
if [[ ! -f $HOME/.bash_aliases ]]; then
cp $NEW_ALIASES_PATH $HOME/.bash_aliases
elif [ $UPDATE_ALIASES -eq 1 ]; then
# Create a temporary diff file
DIFF_FILE=$(mktemp)
# Create a diff
diff -u $HOME/.bash_aliases $NEW_ALIASES_PATH > $DIFF_FILE
# Check if there are any changes
if [[ ! -s $DIFF_FILE ]]; then
echo "No changes found."
rm -f $DIFF_FILE
else
# Apply the patch
patch $HOME/.bash_aliases < $DIFF_FILE
# Check the exit status of the patch command to determine success
if [[ $? -eq 0 ]]; then
echo "Aliases updated successfully."
else
echo "Error occurred while updating aliases. Check the diff and patch manually."
fi
if [ $DEBUG -eq 0 ]; then
rm -f $DIFF_FILE
fi
fi
fi
fi
if [ -e ${SCRIPT_DIR}/terminal.sh ]; then
sed -i "s|\./install\.sh|${SCRIPT_DIR}/install.sh|g" ${SCRIPT_DIR}/terminal.sh
fi
pushd $HOME/.local/bin
if [ -e ${SCRIPT_DIR}/mainline.sh ]; then
sed -i "s|\./install\.sh|${SCRIPT_DIR}/install.sh|g" ${SCRIPT_DIR}/mainline.sh
if [ -e setup-mainline ]; then
rm -rvf setup-mainline
fi
ln -s ${SCRIPT_DIR}/mainline.sh setup-mainline
fi
if [ -e ${SCRIPT_DIR}/suspend.sh ]; then
sed -i "s|\./install\.sh|${SCRIPT_DIR}/install.sh|g" ${SCRIPT_DIR}/suspend.sh
sed -i "s|\./count|${SCRIPT_DIR}/count|g" ${SCRIPT_DIR}/suspend.sh
sed -i "s|\./resume-hook\.sh|${SCRIPT_DIR}/resume-hook.sh|g" ${SCRIPT_DIR}/suspend.sh
if [ -e sustest ]; then
rm -rvf sustest
fi
ln -s ${SCRIPT_DIR}/suspend.sh sustest
fi
if [ -e ${SCRIPT_DIR}/system76-ppa.sh ]; then
sed -i "s|\./check-needrestart\.sh|${SCRIPT_DIR}/check-needrestart.sh|g" ${SCRIPT_DIR}/system76-ppa.sh
if [ -e system76-ppa ]; then
rm -rvf system76-ppa
fi
ln -s ${SCRIPT_DIR}/system76-ppa.sh system76-ppa
fi
if [ $INSTALL_PPA -eq 1 ]; then
system76-ppa
fi
$SCRIPT_DIR/install.sh "${PKG_LIST[@]}"
if [ -e $SCRIPT_DIR/check-needrestart.sh ]; then
if [ $REBOOT -eq 1 ]; then
$SCRIPT_DIR/check-needrestart.sh
if [ $? -eq 0 ]; then
systemctl reboot -i
fi
fi
fi
popd
popd