diff --git a/steamtricks/bin/steamtricks b/steamtricks/bin/steamtricks new file mode 100644 index 0000000..99ca189 --- /dev/null +++ b/steamtricks/bin/steamtricks @@ -0,0 +1,139 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Getopt::Long; +use Config::Tiny; +use File::Basename; +use Data::Dumper; +use File::Copy; + +sub print_help; +sub main; +sub parse_config; +sub setup_config; +sub write_config; +sub create_install; +sub change_install; + +use constant { + VERSION = "v0.1.0" +} + +my $steamtricks_prefix = $ENV{'STEAMTRICKS_PREFIX'}; +my $change_install = ''; +my $create_install = ''; +my $new_config = ''; +my $game = ''; +my $game_version = ''; +my $new_steam_prefix = '~/.var/app/com.valvesoftware.Steam/data/Steam/steamapps/common'; +my $help = ''; +my $version = ''; +my $config_location = "${steamtricks_prefix}/steamtricks.conf" + +GetOptions ('steam-prefix=s' => \$steam_prefix, + 'create-install' => \$create_install, + 'change-install' => \$change_install, + 'game=s' => \$game, + 'game-version=s' => \$game_version, + 'setup-config' => \$new_config, + 'steam-prefix=s' => \$new_steam_prefix, + 'help' => \$help, + 'version' => \$print_version); + +main; + +sub main { + + if ($help) { + print_help; + return 0; + } else if ($version) { + print basename($0), VERSION; + return 0; + } else if ($new_config) { + setup_config($new_steam_prefix) + return 0; + } else { + my $steam_prefix, @managed_games = parse_config; + + if ($change_install && $game_version && ! $create_install) { + change_install($steam_prefix, @managed_games); + return 0; + } else if ($create_install && $game_version && ! $change_install ) { + create_install($steam_prefix, @managed_games); + return 0; + } + } +} + +sub parse_config { + + if (-s "$config_location" ) { + my $Config = Config::Tiny->read( "$config_location" ); + } else { + warn "config file ${config_location} not found. Creating new config with flatpak defaults\n"; + my $Config = setup_config; + } + + my $steam_prefix = Dumper($Config->{steam_prefix}); + my @managed_games = Dumper($Config->{install_manager}->{managed_games}) + return $steam_prefix, @managed_games; +} + +sub setup_config { + + print "Creating config with STEAM_PREFIX=${new_steam_prefix}\n" + if (-s "${config_location}") { + warn "$config_location already exists, do you wish to overwrite this file? [y/N]"; + my $ans = ; + chomp $ans; + + switch($ans) { + case /[yY].?/ { my $Config = write_config } + else { die "Config not created. Exiting" } + } + + } else { + my $Config = write_config; + } + return $Config; +} + +sub write_config { + my $Config = Config::Tiny->new({ + _ => { STEAM_PREFIX => $new_steam_prefix } + install_manager => { MANAGED_GAMES[] => ""} + }); + $Config->write( ${config_location} ) or die "Config file $config_location could not be written: $!\n"; + return $Config; +} + +sub create_install { + my $steam_prefix, @managed_games = @_; + + if (-d "${steam_prefix}/${game}") { + move("${steam_prefix}/${game}", "${steam_prefix}/${game}_${game_version}"); + symlink("${steam_prefix}/${game}_${game_version}", "${steam_prefix}/${game}"); + } else if ( -l "${steam_prefix}/${game}") { + if ( grep( /^$game$/, @managed_games) ){ + warn "This game is already managed, are you looking for --change-install ?"; + exit 1; + } else { + + } + + + } else { + die "Game not found at ${steam_prefix}/${game} please check your steam prefix and your game name"; + } +} + +sub change_install { + +} + +sub print_help { + print basename($0), "\n"; +} \ No newline at end of file diff --git a/steamtricks/bin/steamtricks.pl b/steamtricks/bin/steamtricks.pl deleted file mode 100644 index 33b8534..0000000 --- a/steamtricks/bin/steamtricks.pl +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; - -use Getopt::Long; -use Config::Tiny; -use File::Basename; - -sub setup_config; -sub print_help; -sub main; -sub parse_config; - -use constant { - VERSION = "v0.1.0" -} - -my $steamtricks_prefix = $ENV{'STEAMTRICKS_PREFIX'}; -my $change_install = ''; -my $create_install = ''; -my $new_config = ''; -my $game = ''; -my $game_version = ''; -my $new_steam_prefix = '~/.var/app/com.valvesoftware.Steam/data/Steam/steamapps/common'; -my $help = ''; -my $version = ''; -my $config_location = "${steamtricks_prefix}/steamtricks.conf" - -GetOptions ('steam-prefix=s' => \$steam_prefix, - 'create-install' => \$create_install, - 'change-install' => \$change_install, - 'game=s' => \$game, - 'setup-config' => \$new_config, - 'steam-prefix=s' => \$new_steam_prefix, - 'game-version=s' => \$game_version, - 'help' => \$help, - 'version' => \$print_version); - -main; - -sub main { - - if ($help) { - print_help; - return 0; - } else if ($version) { - print basename($0), VERSION; - } else if ($new_config) { - setup_config($new_steam_prefix) - } else if ($change_install && $game_version) { - - } else if ($create_install && $game_version) { - - } - -} - -sub parse_config { - - if (-s "$config_location" ) { - my $config = Config::Tiny->read( "$config_location" ); - } else { - warn "config file ${config_location} not found. Creating new config with flatpak defaults\n"; - setup_config; - } -} - -sub setup_config { - - print "Creating config with STEAM_PREFIX=${new_steam_prefix}\n" - if (-s "${config_location}") { - warn "$config_location already exists, do you wish to overwrite this file? [y/N]"; - my $ans = ; - chomp $ans; - - switch($ans) { - case /[yY].?/ { my $config = Config::Tiny->new({ _ => { STEAM_PREFIX => "$new_steam_prefix" } }) } - else { die "Config not created. Exiting" } - } - - } else { - my $config = Config::Tiny->new({ _ => { STEAM_PREFIX => "$new_steam_prefix" }});; - } - - $config->write( ${config_location} ) or die "Config file $config_location could not be written: $!\n"; - -} - -sub print_help { - print basename($0), "\n"; -} \ No newline at end of file diff --git a/steamtricks/steamtricks.conf.example b/steamtricks/steamtricks.conf.example index 7a5a290..cfd037a 100644 --- a/steamtricks/steamtricks.conf.example +++ b/steamtricks/steamtricks.conf.example @@ -1,11 +1,11 @@ # For the time being, this config file is very picky. You cannot leave trailing # slashes on any paths in this folder -STEAM_PREFIX=~/.var/app/com.valvesoftware.Steam/data/Steam/steamapps/common - +steam_prefix=~/.var/app/com.valvesoftware.Steam/data/Steam/steamapps/common # You may add any number of managed games you'd like, just note that the value # is case sensitive and should match the original folder name in steamapps/common -# you must also have a separate MANAGED_GAME[] entry for each game -# the brackets are necessary -MANAGED_GAME[]=ProjectZomboid -MANAGED_GAME[]=ELDEN RING -MANAGED_GAME[]=Baldurs Gate 3 \ No newline at end of file +# you must also have a separate managed_games[] entry for each game +# the brackets are necessary. Quotes are unnecessary +[install_manager] +managed_games[]=ProjectZomboid +managed_games[]=ELDEN RING +managed_games[]=Baldurs Gate 3 \ No newline at end of file diff --git a/webinstall.sh b/webinstall.sh index f0ec754..c47c404 100644 --- a/webinstall.sh +++ b/webinstall.sh @@ -1,15 +1,20 @@ #!/usr/bin/env bash -install_steamtricks () { - curl | tar -xvC ~/.steamtricks/ +export DOWNLOADURL="" +install_steamtricks () { + export SHELLNAME="$1" + export SHELLPROFILE="$HOME/.${SHELLNAME}rc" + mkdir -p ~/.steamtricks && curl "$DOWNLOADURL" | tar -xvC ~/.steamtricks/ || echo "Could not install steamtricks" + echo "export STEAMTRICKS_PREFIX=\"$HOME/.steamtricks\"">>$SHELLPROFILE + echo 'export PATH="$PATH:$HOME/.winetricks/bin"'>>$SHELLPROFILE } SHELLNAME=$(echo $SHELL | awk -F '/' '{print $NF}') case "$SHELLNAME" in sh) echo "Shell not supported"; exit 1 ;; - bash | zsh | yash) install_steamtricks + bash | zsh | yash) install_steamtricks "$SHELLNAME" ;; *) echo "You will need to install this by manually adding it to either your /etc/profile for system-wide installation or to your shell's profile" ;;