Improved scripts using ShellCheck

This commit is contained in:
2023-06-22 13:04:01 +02:00
parent 5b918e762b
commit 057527f86a
3 changed files with 20 additions and 17 deletions

View File

@@ -37,21 +37,21 @@ if [[ -z $CTID || -z $CONTAINER_NAME || -z $DISTRO || -z $ROOTPASS ]]; then
exit 1
fi
template=$(pveam available | grep $DISTRO | sort -rV | head -n 1 | awk '{print $2}')
template=$(pveam available | grep "$DISTRO" | sort -rV | head -n 1 | awk '{print $2}')
if [[ -z $template ]]; then
echo "$DISTRO template not found."
exit 1
fi
template=$(pveam list local | grep $template | awk '{print $1}')
template=$(pveam list local | grep "$template" | awk '{print $1}')
if [[ -z $template ]]; then
echo "$DISTRO template not found. Downloading..."
pveam download local $template
pveam download local "$template"
fi
pct create $CTID $template --hostname $CONTAINER_NAME --memory 1024 --storage local-lvm --net0 name=eth0,bridge=vmbr0,firewall=1,ip=dhcp --unprivileged --ostype $DISTRO --password="$ROOTPASS"
echo -e "lxc.cgroup.devices.allow: c 10:200 rwm\nlxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file" >> /etc/pve/lxc/$CTID.conf
pct start $CTID
pct status $CTID | grep "status: running" || sleep 10
pct create "$CTID" "$template" --hostname "$CONTAINER_NAME" --memory 1024 --storage local-lvm --net0 name=eth0,bridge=vmbr0,firewall=1,ip=dhcp --unprivileged --ostype "$DISTRO" --password="$ROOTPASS"
echo -e "lxc.cgroup.devices.allow: c 10:200 rwm\nlxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file" >> /etc/pve/lxc/"$CTID".conf
pct start "$CTID"
pct status "$CTID" | grep "status: running" || sleep 10
echo lxc now running

View File

@@ -17,7 +17,7 @@ function console_log() {
function check_update() {
git fetch
if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then
if [ "$(git rev-parse HEAD)" != "$(git rev-parse "@{u}")" ]; then
console_log "Updates available! Please run the updater script." "info"
fi
}
@@ -50,7 +50,7 @@ function vpn_connect() {
}
function vpn_disconnect() {
nmcli connection down $(nmcli connection show --active | grep vpn | awk '{print $1}')
nmcli connection down "$(nmcli connection show --active | grep vpn | awk '{print $1}')"
status=$(nmcli connection show --active | awk '/vpn/ {print $1}')
if [[ -z $status ]]; then
@@ -88,12 +88,13 @@ function start_bot() {
function main() {
check_update
local vpns=$(nmcli connection show | grep vpn | awk '{print $1}')
local host=$(hostname -f)
local vpns
vpns=$(nmcli connection show | grep vpn | awk '{print $1}')
local host
host=$(hostname -f)
config_file="config.txt"
if [ -f "$config_file" ]; then
source "$config_file"
if [ -f "config.txt" ]; then
source "config.txt"
else
console_log "[$host] Config file not found." "error"
exit 1

View File

@@ -1,5 +1,7 @@
#!/bin/bash
git fetch
if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then
if [ "$(git rev-parse HEAD)" != "$(git rev-parse "@{u}")" ]; then
git stash && git pull
exec "$0"
fi
@@ -17,9 +19,9 @@ if [ ! -d "Microsoft-Rewards-bot" ]; then
fi
sudo dnf up -y
cd Microsoft-Rewards-bot
cd Microsoft-Rewards-bot || exit
git fetch
if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then
if [ "$(git rev-parse HEAD)" != "$(git rev-parse "@{u}")" ]; then
git stash && git pull && git checkout master && pip install -r requirements.txt
fi