/
powerup
220 lines (192 loc) · 8.6 KB
/
powerup
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/bash
# -----------------------------------------------------------------------------------
# Script Name: powerup
# Description: CSI Linux powerup is the updater script within the CSI Linux Platform
# to maintain updates for the OS, CSI Linux Tools, and Third Party Tools.
# Author: Jeremy Martin
# Website: https://csilinux.com
# Copyright: (C) 2024 CSI Linux - csilinux.com
# License: Closed Source
#
# This script is part of CSI Linux (https://csilinux.com). Unauthorized copying,
# modification, distribution, or use of this script, without express approval from
# CSI Linux, is strictly prohibited. This script is proprietary and confidential.
# -----------------------------------------------------------------------------------
clear
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
output_file="/tmp/powerup-$timestamp.txt"
prompt_for_sudo() {
while true; do
key=$(zenity --password --title "Power up your system with an upgrade." --text "Enter your CSI password." --width=400)
if [ $? -ne 0 ]; then
zenity --info --text="Operation cancelled. Exiting script." --width=400
exit 1
fi
if echo "$key" | sudo -S -v -k &> /dev/null; then
sudo -k # Reset the sudo timestamp after verification
break # Exit loop if the password is correct
else
zenity --error --title="Authentication Failure" --text="Incorrect password or lack of sudo privileges. Please try again." --width=400
fi
done
}
install_missing_programs() {
local programs=(curl bpytop xterm aria2 yad zenity)
local missing_programs=()
local output_file="/tmp/outputfile.txt" # Define the output file path correctly
echo "Creating file at: $output_file"
touch "$output_file"
for program in "${programs[@]}"; do
if ! dpkg -s "$program" &> /dev/null; then
echo "$program is not installed. Will attempt to install." | tee -a "$output_file"
missing_programs+=("$program")
else
echo "$program is already installed." | tee -a "$output_file"
fi
done
if [ ${#missing_programs[@]} -ne 0 ]; then
echo "Updating package lists..." | tee -a "$output_file"
echo $key | sudo -S apt update | tee -a "$output_file"
for program in "${missing_programs[@]}"; do
echo "Attempting to install $program..." | tee -a "$output_file"
if echo $key | sudo -S apt install -y "$program" 2>&1 | tee -a "$output_file"; then
echo "$program installed successfully." | tee -a "$output_file"
else
echo "Failed to install $program. It may not be available in the repository or another error occurred." | tee -a "$output_file"
fi
done
else
echo "Starter programs are already installed." | tee -a "$output_file"
fi
}
install_csi_tools() {
local flag_file="/tmp/csi_tools_installed.flag" # Secure location for flag file
# Check if the flag file exists, indicating the function was already run
if [[ -f "$flag_file" ]]; then
echo "CSI Tools have already been installed. Exiting."
return 0 # Exit the function successfully
fi
local backup_dir="/tmp/restore"
local backup_file_name="csitools"
local archive_path="$backup_dir/$backup_file_name.7z"
echo "$key" | sudo -S DEBIAN_FRONTEND=noninteractive apt install aria2 -y
echo "Preparing for CSI Tools download..."
echo "$key" | sudo -S rm -rf "$backup_dir" # Remove the entire backup directory
echo "$key" | sudo -S mkdir -p "$backup_dir"
echo "$key" | sudo -S chmod 777 "$backup_dir" # Set full permissions temporarily for download
echo "Downloading CSI Tools..."
if aria2c -x3 -k1M https://csilinux.com/downloads/csitools.7z -d "$backup_dir" -o "$backup_file_name.7z"; then
echo "Download successful."
echo "# Installing CSI Tools..."
if restore_backup_to_root "$backup_dir" "$backup_file_name"; then
echo "CSI Tools restored successfully."
echo "Setting permissions and configurations for CSI Tools..."
echo "$key" | sudo -S chown csi:csi -R /opt/csitools
echo "$key" | sudo -S chmod +x /opt/csitools/* -R
echo "$key" | sudo -S chmod +x ~/Desktop/*.desktop
echo "Converting DOS format to UNIX format in CSI Tools directories..."
find /opt/csitools /opt/csitools/helpers -type f -exec sudo dos2unix {} + &>/dev/null
echo "CSI Tools installation and configuration completed successfully."
echo "$key" | sudo -S touch "$flag_file"
else
echo "Failed to restore CSI Tools from the backup."
return 1 # Restoration failed
fi
else
echo "Failed to download CSI Tools."
return 1 # Download failed
fi
return 0 # Successfully completed the function
}
restore_backup_to_root() {
echo $key | sudo -S sleep 1
sudo -k
local backup_dir=$1
local backup_file_name=$2
local archive_path="$backup_dir/$backup_file_name.7z"
echo "Restoring CSI Tools backup..."
# Extract the .7z file safely and ensure files are overwritten without prompting
if ! echo $key | sudo -S 7z x -aoa -o"$backup_dir" "$archive_path"; then
echo "Failed to extract $archive_path. Please check the file and try again."
return 1 # Exit the function with an error status
fi
local tar_file="$backup_dir/$backup_file_name.tar"
if [ -f "$tar_file" ]; then
echo "Restoring backup from tar file..."
# Extract the tar file and ensure files are overwritten without prompting
if ! echo $key | sudo -S tar --overwrite -xpf "$tar_file" -C /; then
echo "Failed to restore from $tar_file. Please check the archive and try again."
return 1 # Exit the function with an error status
fi
echo "Backup restored successfully."
echo $key | sudo -S rm "$tar_file"
else
echo "Backup .tar file not found. Please check the archive path and try again."
return 1 # Exit the function with an error status
fi
return 0 # Successfully completed the function
}
prompt_for_sudo
install_missing_programs
install_csi_tools
declare -a base_names=(
"csi-linux-base"
"csi-linux-themes"
"os-update"
"encryption"
"osint"
"incident-response"
"computer-forensics"
"malware-analysis"
"sigint"
"virtualization"
"security"
)
# Prepare the list for YAD
list_data="FALSE all " # Add "all" option
for name in "${base_names[@]}"; do
list_data+="FALSE $name " # Append each base name, space-delimited
done
welcome_msg="Welcome to the CSI Linux Powerup tool. Choose what sections you either want to install or update below."
logo_url="https://csilinux.com/wp-content/uploads/2023/08/CSILinux-Menu.png"
logo_path="/tmp/CSILinux-Menu.png"
curl -o "$logo_path" "$logo_url"
selected_options=$(yad --list --title='CSI Linux Powerup' --text="$welcome_msg" --window-icon="$logo_path" --width=400 --height=425 --checklist \
--column='Select':CHK --column='Name' $list_data --image="preferences-system" --button=gtk-ok:0 --button=gtk-close:1 --separator="|")
if [ $? -ne 0 ]; then
echo "Dialog was canceled or closed. Exiting script."
exit 1
fi
# Splitting the selected options string correctly to handle newline issues
readarray -t selections <<< "$(echo "$selected_options" | sed 's/|/\n/g')"
# Initialize the array to hold the selected options
arg_list=()
# Flag to indicate if "all" has been selected
all_selected=false
# Iterate through selections to build the arg_list based on selected values
for selection in "${selections[@]}"; do
if [[ "$selection" == "all" ]]; then
all_selected=true
break # No need to continue if "all" is selected
elif [[ " ${base_names[*]} " =~ " ${selection} " ]]; then
# Add the selection to arg_list if it's a valid base name
arg_list+=("$selection")
fi
done
# If "all" is selected, populate arg_list with all base_names except "all"
if [ "$all_selected" = true ]; then
echo "All options have been selected, excluding 'all'."
arg_list=("${base_names[@]}") # Populate arg_list with all base_names
else
echo "Specific selections have been made."
fi
echo "You have selected the following options:"
for option in "${arg_list[@]}"; do
echo "- $option"
done
cd /tmp
SCRIPT_URL="https://raw.githubusercontent.com/CSILinux/CSILinux-Powerup/main/csitoolsupdate.sh"
rm -f ./csitoolsupdate.sh
curl -o csitoolsupdate.sh "$SCRIPT_URL" && chmod +x csitoolsupdate.sh
echo "Running update now..." | tee "$output_file"
./csitoolsupdate.sh $key "${arg_list[@]}" | tee -a "$output_file"